From 4d9e50983a916c80ed4b5382ef9adfa5f66d89f1 Mon Sep 17 00:00:00 2001 From: Clipart Date: Mon, 14 Jun 2021 21:39:47 +0100 Subject: [PATCH] Update balance on create viewing key --- src/pages/Exchange/utils.tsx | 1 + src/stores/UserStore.ts | 51 ++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/pages/Exchange/utils.tsx b/src/pages/Exchange/utils.tsx index fb35ec01..c794afa3 100644 --- a/src/pages/Exchange/utils.tsx +++ b/src/pages/Exchange/utils.tsx @@ -32,6 +32,7 @@ export const createViewingKey = async (user: any, callback?: Function) => { try { console.log(user.chainId, user.snip20Address); await user.keplrWallet.suggestToken(user.chainId, user.snip20Address); + await user.updateSnip20BalanceForAddress(user.snip20Address) callback(true); } catch (error) { console.log(error); diff --git a/src/stores/UserStore.ts b/src/stores/UserStore.ts index 25597cf3..3df9fc63 100644 --- a/src/stores/UserStore.ts +++ b/src/stores/UserStore.ts @@ -328,27 +328,27 @@ export class UserStoreEx extends StoreConstructor { try { const client = isSigner ? new AsyncSender( - address, - this.address, - this.keplrOfflineSigner, - // @ts-ignore - window.getEnigmaUtils(this.chainId), - { - init: { - amount: [{ amount: '300000', denom: 'uscrt' }], - gas: '300000', - }, - exec: { - amount: [{ amount: '500000', denom: 'uscrt' }], - gas: '500000', - }, + address, + this.address, + this.keplrOfflineSigner, + // @ts-ignore + window.getEnigmaUtils(this.chainId), + { + init: { + amount: [{ amount: '300000', denom: 'uscrt' }], + gas: '300000', }, - BroadcastMode.Async, - ) + exec: { + amount: [{ amount: '500000', denom: 'uscrt' }], + gas: '500000', + }, + }, + BroadcastMode.Async, + ) : new CosmWasmClient( - address, - // @ts-ignore - ); + address, + // @ts-ignore + ); this.syncLocalStorage(); this.getBalances(); return client; @@ -509,6 +509,19 @@ export class UserStoreEx extends StoreConstructor { } }; + @action public updateSnip20BalanceForAddress = async (address: string) => { + while (!this.address && !this.secretjs && this.stores.tokens.allData.length === 0) { + await sleep(100); + } + if (!address) return; + + const token = this.stores.tokens.allData.find(t => t.dst_address === address); + if (!token) return; + if (token.display_props.symbol === 'sSCRT') await this.updateSScrtBalance(); + + await this.refreshTokenBalance(token.display_props.symbol); + }; + @action public updateBalanceForSymbol = async (symbol: string) => { while (!this.address && !this.secretjs && this.stores.tokens.allData.length === 0) { await sleep(100);