Skip to content

Commit

Permalink
Merge pull request #565 from telosnetwork/562-get-wtlos-balance-from-…
Browse files Browse the repository at this point in the history
…contract-while-we-fix-indexer

adding workaround for WTLOS balance
  • Loading branch information
pmjanus authored Aug 23, 2023
2 parents caea7e2 + ff3620b commit 3096251
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/antelope/stores/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export const useBalancesStore = defineStore(store_name, {
// if the chain index is healthy, we use it to fetch the all the balances at once
if (chain_settings.isIndexerHealthy()) {
this.trace('updateBalancesForAccount', 'Indexer OK!');

// Workaround-WTLOS: to fix the WTLOS balance while the indexer is not doing it after a successful withdraw (unwrap)
// We need to get the value ready to overwrite immediately and therefore avoid the blink
const wrapTokens = chain_settings.getWrappedSystemToken();
const authenticator = account.authenticator as EVMAuthenticator;
const wrapBalance = await authenticator.getERC20TokenBalance(account.account, wrapTokens.address);

// now we call the indexer
const newBalances = await chain_settings.getBalances(account.account);

if (this.__balances[label].length === 0) {
Expand All @@ -127,6 +135,10 @@ export const useBalancesStore = defineStore(store_name, {
newBalances.forEach((balance) => {
this.processBalanceForToken(label, balance.token, balance.amount);
});

// Workaround-WTLOS: now we overwrite the value with the one taken from the contract
this.processBalanceForToken(label, wrapTokens, wrapBalance);

this.sortBalances(label);

useFeedbackStore().unsetLoading('updateBalancesForAccount');
Expand Down

0 comments on commit 3096251

Please sign in to comment.