Skip to content

Commit

Permalink
fix: fix balances race condition (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
emccorson committed Feb 29, 2024
1 parent 1ca4f13 commit 7e545ae
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions apps/namada-interface/src/slices/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ const balancesAtom = (() => {
currency: { address: nativeToken },
} = get(chainAtom);

// TODO: should we be throwing away old balances here?
const balances = get(base);
set(base, {});

accounts.forEach(async (account) => {
const result = await namada.queryBalances(account.address, [
Expand All @@ -202,11 +201,7 @@ const balancesAtom = (() => {
(acc, curr) => ({ ...acc, [curr.token]: new BigNumber(curr.amount) }),
{} as Balance
);
balances[account.address] = balance;
set(
base,
{ ...balances } // object clone ensures jotai realises object has changed
);
set(base, { ...get(base), [account.address]: balance });
});
}
);
Expand Down

0 comments on commit 7e545ae

Please sign in to comment.