Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Call getElysiumPropertyInfo with multiple values simultaneously.
Browse files Browse the repository at this point in the history
  • Loading branch information
sproxet committed Sep 25, 2022
1 parent 2ab98d1 commit 913b666
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
11 changes: 5 additions & 6 deletions src/daemon/firod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ElysiumPropertyData> {
if (typeof property == 'number') {
return <ElysiumPropertyData>(await this.send(null, null, 'getElysiumPropertyInfo', {propertyId: property}));
} else {
return <ElysiumPropertyData>(await this.send(null, null, 'getElysiumPropertyInfo', {propertyCreationTxid: property}));
}
async getElysiumPropertyInfo(properties: [number | string][]): Promise<ElysiumPropertyData[]> {
return <ElysiumPropertyData[]>(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
Expand Down
9 changes: 7 additions & 2 deletions src/renderer/components/ElysiumPage/AddTokenForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
16 changes: 3 additions & 13 deletions src/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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.
Expand Down

0 comments on commit 913b666

Please sign in to comment.