Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process multiple items on the api side, not on the caller side #3741

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading