fix: Empty token buffer decode error (#84)

This commit is contained in:
Shardul Aeer 2021-09-19 01:00:22 +05:30 committed by GitHub
parent 80b0fa4605
commit 3f213aa5ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -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");
}
}
}
);