-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from interplanetary to datacapstats api
- Loading branch information
1 parent
21abbd3
commit e0614c6
Showing
7 changed files
with
111 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { type ApiAllowanceResponse } from '@/type' | ||
import { config } from '@/config' | ||
|
||
/** | ||
* Get the allowance for a verfier from the API. | ||
* | ||
* @param {string} address - The address to get the allowance for. | ||
* @returns {Promise<ApiAllowanceResponse>} ApiAllowanceResponse - The response from the API. | ||
*/ | ||
export const getAllowanceForVerifier = async ( | ||
address: string, | ||
): Promise<ApiAllowanceResponse> => { | ||
try { | ||
const requestBody = { | ||
jsonrpc: '2.0', | ||
method: 'Filecoin.StateVerifierStatus', | ||
params: [address, null], | ||
id: 1, | ||
} | ||
const response = await fetch(`${config.glifNodeUrl}`, { | ||
method: 'POST', | ||
body: JSON.stringify(requestBody), | ||
}) | ||
|
||
const data = await response.json() | ||
if (data?.type === 'error') { | ||
return { | ||
data: '', | ||
error: data.error.message, | ||
success: false, | ||
} | ||
} | ||
|
||
return { | ||
data: data.result, | ||
error: '', | ||
success: true, | ||
} | ||
} catch (error: unknown) { | ||
const errMessage = `Error accessing GLIF API Filecoin.StateVerifierStatus: ${ | ||
(error as Error).message | ||
}` | ||
return { | ||
data: '', | ||
error: errMessage, | ||
success: false, | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get the allowance for a client from the API. | ||
* | ||
* @param {string} address - The address to get the allowance for. | ||
* @returns {Promise<ApiAllowanceResponse>} ApiAllowanceResponse - The response from the API. | ||
*/ | ||
export const getAllowanceForClient = async ( | ||
address: string, | ||
): Promise<ApiAllowanceResponse> => { | ||
try { | ||
const requestBody = { | ||
jsonrpc: '2.0', | ||
method: 'Filecoin.StateVerifiedClientStatus', | ||
params: [address, null], | ||
id: 1, | ||
} | ||
const response = await fetch(`${config.glifNodeUrl}`, { | ||
method: 'POST', | ||
body: JSON.stringify(requestBody), | ||
}) | ||
|
||
const data = await response.json() | ||
if (data?.error) { | ||
return { | ||
data: '', | ||
error: data.error.message, | ||
success: false, | ||
} | ||
} | ||
|
||
return { | ||
data: data.result, | ||
error: '', | ||
success: true, | ||
} | ||
} catch (error: unknown) { | ||
const errMessage = `Error accessing GLIF API Filecoin.StateVerifiedClientStatus: ${ | ||
(error as Error).message | ||
}` | ||
return { | ||
data: '', | ||
error: errMessage, | ||
success: false, | ||
} | ||
} | ||
} |