Skip to content

Commit

Permalink
Broadcast cache update when there's a change refreshing accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Sep 19, 2023
1 parent 6019456 commit 39900c8
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/features/account/AccountTokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,32 @@ const AccountTokenList = ({ onLayout }: Props) => {
syncTokenAccounts({ cluster, acct: currentAccount, anchorProvider }),
)
await Promise.all(
[...visibleTokens].map((mintStr) => {
[...visibleTokens].map(async (mintStr) => {
const ata = getAssociatedTokenAddressSync(
new PublicKey(mintStr),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
new PublicKey(currentAccount!.solanaAddress!),
)
const ataStr = ata.toBase58()
// Trigger a refetch on all visible token accounts
return cache.search(
getAssociatedTokenAddressSync(
new PublicKey(mintStr),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
new PublicKey(currentAccount!.solanaAddress!),
),
undefined,
const result = await cache.search(
ata,
cache.keyToAccountParser.get(ataStr),
false,
true,
)
if (
!cache.genericCache.has(ataStr) ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line
result != cache.genericCache[ataStr]
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cache.updateCache(ataStr, result)
}
return result
}),
)
})
Expand Down

0 comments on commit 39900c8

Please sign in to comment.