Skip to content

Commit

Permalink
Merge pull request #3741 from Emurgo/ruslan/api-fix-proposal
Browse files Browse the repository at this point in the history
process multiple items on the api side, not on the caller side
  • Loading branch information
yushih authored Nov 15, 2024
2 parents 28b630d + eb9ba57 commit 3a3727a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,29 +551,27 @@ export class RemoteFetcher implements IFetcher {

getUtxoData: GetUtxoDataRequest => Promise<GetUtxoDataResponse> = async (body) => {
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 === 'No outputs found') {
return [ null ];
return Promise.all(body.utxos.map(({ txHash, txIndex }) => {
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()
}
}
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error));
throw new GetUtxoDataError();
});
).then(response => response.data)
.catch((error) => {
if (error.response.status === 404 && error.response.data === 'No outputs found') {
return null;
}
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error));
throw new GetUtxoDataError();
});
}));
}

getLatestBlockBySlot: GetLatestBlockBySlotFunc = async (body) => {
Expand Down
11 changes: 4 additions & 7 deletions packages/yoroi-extension/app/connector/stores/ConnectorStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,10 @@ export default class ConnectorStore extends Store<StoresMap, ActionsMap> {

const foreignInputDetails = [];
if (foreignInputs.length) {
const foreignUtxos = await Promise.all(foreignInputs.map(async (foreignInput) => {
// currently this endpoint only supports querying one at a time
return (await this.stores.substores.ada.stateFetchStore.fetcher.getUtxoData({
network,
utxos: [foreignInput],
}))[0];
}));
const foreignUtxos = await this.stores.substores.ada.stateFetchStore.fetcher.getUtxoData({
network,
utxos: foreignInputs,
});
for (let i = 0; i < foreignUtxos.length; i++) {
const foreignUtxo = foreignUtxos[i];
if (foreignUtxo == null || typeof foreignUtxo !== 'object') {
Expand Down

0 comments on commit 3a3727a

Please sign in to comment.