From 8b9f98a1cefaf13ea522f3d3a8a29d2d0848176c Mon Sep 17 00:00:00 2001 From: yushi Date: Thu, 14 Nov 2024 23:30:07 +0800 Subject: [PATCH 1/6] adapt to backend return value change --- .../app/api/ada/lib/state-fetch/remoteFetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js index 8ef431f6d5..5b77f34656 100644 --- a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js +++ b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js @@ -568,7 +568,7 @@ export class RemoteFetcher implements IFetcher { } ).then(response => [ response.data ]) .catch((error) => { - if (error.response.status === 404 && error.response.data === 'Transaction not found') { + if (error.response.status === 404 && error.response.data === 'No outputs found') { return [ null ]; } Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error)); From 2842b2d671a162750a5fe21c50165f34e25c81f2 Mon Sep 17 00:00:00 2001 From: yushi Date: Thu, 14 Nov 2024 23:44:20 +0800 Subject: [PATCH 2/6] allow multiple foreign inputs --- .../app/connector/stores/ConnectorStore.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js index 5c7b730e80..1854e4b011 100644 --- a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js +++ b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js @@ -532,10 +532,13 @@ export default class ConnectorStore extends Store { const foreignInputDetails = []; if (foreignInputs.length) { - const foreignUtxos = await this.stores.substores.ada.stateFetchStore.fetcher.getUtxoData({ - network, - utxos: foreignInputs, - }); + 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]; + })); for (let i = 0; i < foreignUtxos.length; i++) { const foreignUtxo = foreignUtxos[i]; if (foreignUtxo == null || typeof foreignUtxo !== 'object') { From 28b630da0d804994b0132a999144aa1f3166ec6e Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 15 Nov 2024 14:16:59 +0300 Subject: [PATCH 3/6] function ref fix --- .../app/api/ada/lib/state-fetch/remoteFetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js index 5b77f34656..ee9a789159 100644 --- a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js +++ b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js @@ -578,7 +578,7 @@ export class RemoteFetcher implements IFetcher { getLatestBlockBySlot: GetLatestBlockBySlotFunc = async (body) => { const { BackendService } = body.network.Backend; - if (BackendService == null) throw new Error(`${nameof(this.getUtxoData)} missing backend url`); + if (BackendService == null) throw new Error(`${nameof(this.getLatestBlockBySlot)} missing backend url`); return axios( `${BackendService}/api/v2.1/lastBlockBySlot`, { From 303db7379fa4dc19192dcb07a782683428039acd Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 15 Nov 2024 14:28:38 +0300 Subject: [PATCH 4/6] process multiple items on the api side, not on the caller side --- .../api/ada/lib/state-fetch/remoteFetcher.js | 40 +++++++++---------- .../app/connector/stores/ConnectorStore.js | 11 ++--- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js index ee9a789159..dc62ef3a9f 100644 --- a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js +++ b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js @@ -551,29 +551,27 @@ export class RemoteFetcher implements IFetcher { getUtxoData: GetUtxoDataRequest => Promise = 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) => { diff --git a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js index 1854e4b011..5c7b730e80 100644 --- a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js +++ b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js @@ -532,13 +532,10 @@ export default class ConnectorStore extends Store { 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') { From 643ac5ca26d82f1f56cae4dcbc647f71d9dd18e4 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 15 Nov 2024 14:31:02 +0300 Subject: [PATCH 5/6] return fix --- .../app/api/ada/lib/state-fetch/remoteFetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js index dc62ef3a9f..a121f7b213 100644 --- a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js +++ b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js @@ -563,7 +563,7 @@ export class RemoteFetcher implements IFetcher { 'yoroi-locale': this.getCurrentLocale() } } - ).then(response => [ response.data ]) + ).then(response => response.data) .catch((error) => { if (error.response.status === 404 && error.response.data === 'No outputs found') { return [ null ]; From eb9ba57d371caba1c30ca9b7491cf2d00b3d53f6 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 15 Nov 2024 14:31:09 +0300 Subject: [PATCH 6/6] return fix --- .../app/api/ada/lib/state-fetch/remoteFetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js index a121f7b213..55e0e75355 100644 --- a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js +++ b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js @@ -566,7 +566,7 @@ export class RemoteFetcher implements IFetcher { ).then(response => response.data) .catch((error) => { if (error.response.status === 404 && error.response.data === 'No outputs found') { - return [ null ]; + return null; } Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error)); throw new GetUtxoDataError();