From 913b666cbb62ee65bdb94470a48996da4c96915d Mon Sep 17 00:00:00 2001 From: sproxet Date: Sun, 25 Sep 2022 14:46:17 +0700 Subject: [PATCH] Call getElysiumPropertyInfo with multiple values simultaneously. --- src/daemon/firod.ts | 11 +++++------ .../components/ElysiumPage/AddTokenForm.vue | 9 +++++++-- src/renderer/renderer.js | 16 +++------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/daemon/firod.ts b/src/daemon/firod.ts index 1bcc2076..9a82cd5e 100644 --- a/src/daemon/firod.ts +++ b/src/daemon/firod.ts @@ -1610,12 +1610,11 @@ export class Firod { } // Get information about an Elysium property from its property id or from the tx that created it. - async getElysiumPropertyInfo(property: number | string): Promise { - if (typeof property == 'number') { - return (await this.send(null, null, 'getElysiumPropertyInfo', {propertyId: property})); - } else { - return (await this.send(null, null, 'getElysiumPropertyInfo', {propertyCreationTxid: property})); - } + async getElysiumPropertyInfo(properties: [number | string][]): Promise { + return (await this.send(null, null, 'getElysiumPropertyInfo', { + propertyIds: properties.filter(p => typeof p == 'number'), + propertyCreationTxids: properties.filter(p => typeof p == 'string') + })); } // calcPublicTxFee and calcPrivateTxFee require an address as input despite the fact that the response is the same diff --git a/src/renderer/components/ElysiumPage/AddTokenForm.vue b/src/renderer/components/ElysiumPage/AddTokenForm.vue index c81945c4..fca00381 100644 --- a/src/renderer/components/ElysiumPage/AddTokenForm.vue +++ b/src/renderer/components/ElysiumPage/AddTokenForm.vue @@ -79,8 +79,13 @@ export default { watch: { async query() { try { - const p = await $daemon.getElysiumPropertyInfo(Number(this.query) || this.query); - this.property = p.creationTx != "0000000000000000000000000000000000000000000000000000000000000000" ? p : {notFound: true}; + const p = (await $daemon.getElysiumPropertyInfo([Number(this.query) || this.query]))[0]; + if (!p || p.creationTx == "0000000000000000000000000000000000000000000000000000000000000000") { + this.property = {notFound: true}; + return; + } + + this.property = p; } catch (e) { if (e.name != 'FirodErrorResponse') throw e; this.property = {notFound: true}; diff --git a/src/renderer/renderer.js b/src/renderer/renderer.js index dea668d6..687bc37c 100644 --- a/src/renderer/renderer.js +++ b/src/renderer/renderer.js @@ -71,16 +71,7 @@ window.$addElysiumTokenData = async () => { if (!$store.getters['App/enableElysium']) return; const tokensNeedingData = $store.getters['Elysium/selectedAndOwnedTokens'].filter(token => !$store.getters['Elysium/tokenData'][token]); if (!tokensNeedingData.length) return; - - const tokenData = (await Promise.all(tokensNeedingData.map(async token => { - try { - return await $daemon.getElysiumPropertyInfo(token); - } catch (e) { - console.warn(`Failed to get elysium property info for ${token}: ${e}`); - } - }))).filter(x => x); - - $store.commit('Elysium/addTokenData', tokenData); + $store.commit('Elysium/addTokenData', await $daemon.getElysiumPropertyInfo(tokensNeedingData)); }; $store.watch(() => $store.getters['Elysium/selectedAndOwnedTokens'], async (selectedAndOwnedTokens, oldValue) => { @@ -99,9 +90,8 @@ $store.watch(() => $store.getters['ApiStatus/currentBlockHeight'], async (newVal if (newValue == oldValue) return; const tokenData = $store.getters['Elysium/tokenData']; - const coinsNeedingData = Object.values(tokenData).filter(td => !td.id).map(td => td.creationTx); - const coinData = await Promise.all(coinsNeedingData.map(coin => $daemon.getElysiumPropertyInfo(coin))); - $store.commit('Elysium/addTokenData', coinData); + const tokensNeedingData = Object.values(tokenData).filter(td => !td.id).map(td => td.creationTx); + $store.commit('Elysium/addTokenData', await $daemon.getElysiumPropertyInfo(tokensNeedingData)); }) // Show the waiting screen with reason, or, if reason may be undefined, close it.