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

Update balance on create viewing key #221

Open
wants to merge 1 commit into
base: bsc
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/pages/Exchange/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
51 changes: 32 additions & 19 deletions src/stores/UserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down