Skip to content

Commit

Permalink
Add request & response types
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed Dec 2, 2022
1 parent 293cc92 commit 30aa32b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Expand Up @@ -486,6 +486,33 @@ export class RemoteFetcher implements IFetcher {
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error));
throw new GetUtxoDataError();
});
}

getLastBlockBySlot = async () => {
const { BackendService } = body.network.Backend;
if (body.utxos.length !== 1) {
throw new Error('the RemoteFetcher.getUtxoData expects 1 UTXO');
}
const { txHash, txIndex } = body.utxos[0];
if (BackendService == null) throw new Error(`${nameof(this.getUtxoData)} missing backend url`);
return axios(
`${BackendService}/api/txs/io/${txHash}/o/${txIndex}`,
{
method: 'get',
timeout: 2 * CONFIG.app.walletRefreshInterval,
headers: {
'yoroi-version': this.getLastLaunchVersion(),
'yoroi-locale': this.getCurrentLocale()
}
}
).then(response => [ response.data ])
.catch((error) => {
if (error.response.status === 404 && error.response.data === 'Transaction not found') {
return [ null ];
}
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error));
throw new GetUtxoDataError();
});

}
}
17 changes: 17 additions & 0 deletions packages/yoroi-extension/app/api/ada/lib/state-fetch/types.js
Expand Up @@ -419,3 +419,20 @@ export type UtxoData = {|
export type GetUtxoDataResponse = Array<UtxoData | null>;

export type GetUtxoDataFunc = (body: GetUtxoDataRequest) => Promise<GetUtxoDataResponse>;

// getLastBlockBySlot

type EpochNo = number;
type SlotNo = number;
type RelativeSlot = [EpochNo, SlotNo];
export type GetLatestBlockBySlotReq = {|
...BackendNetworkInfo,
slots: Array<RelativeSlot>,
|};
export type GetLatestBlockBySlotRes = {|
blockHashes: {|
[key: RelativeSlot]: string | null,
|}
|}
export type GetLatestBlockBySlotFunc =
(body: GetLatestBlockBySlotReq) => Promise<GetLatestBlockBySlotRes>

0 comments on commit 30aa32b

Please sign in to comment.