Skip to content

Commit

Permalink
fix: Empty token buffer decode error (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
secretshardul authored Sep 18, 2021
1 parent 80b0fa4 commit 3f213aa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/context/Token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ export function useOwnedTokenAccount(
listener = provider.connection.onAccountChange(
tokenAccount.publicKey,
(info) => {
const token = parseTokenAccountData(info.data);
if (token.amount !== tokenAccount.account.amount) {
const index = _OWNED_TOKEN_ACCOUNTS_CACHE.indexOf(tokenAccount);
assert.ok(index >= 0);
_OWNED_TOKEN_ACCOUNTS_CACHE[index].account = token;
setRefresh((r) => r + 1);
if (info.data.length !== 0) {
try {
const token = parseTokenAccountData(info.data);
if (token.amount !== tokenAccount.account.amount) {
const index = _OWNED_TOKEN_ACCOUNTS_CACHE.indexOf(tokenAccount);
assert.ok(index >= 0);
_OWNED_TOKEN_ACCOUNTS_CACHE[index].account = token;
setRefresh((r) => r + 1);
}
} catch (error) {
console.log("Failed to decode token AccountInfo");
}
}
}
);
Expand Down

0 comments on commit 3f213aa

Please sign in to comment.