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( listener = provider.connection.onAccountChange(
tokenAccount.publicKey, tokenAccount.publicKey,
(info) => { (info) => {
const token = parseTokenAccountData(info.data); if (info.data.length !== 0) {
if (token.amount !== tokenAccount.account.amount) { try {
const index = _OWNED_TOKEN_ACCOUNTS_CACHE.indexOf(tokenAccount); const token = parseTokenAccountData(info.data);
assert.ok(index >= 0); if (token.amount !== tokenAccount.account.amount) {
_OWNED_TOKEN_ACCOUNTS_CACHE[index].account = token; const index = _OWNED_TOKEN_ACCOUNTS_CACHE.indexOf(tokenAccount);
setRefresh((r) => r + 1); assert.ok(index >= 0);
_OWNED_TOKEN_ACCOUNTS_CACHE[index].account = token;
setRefresh((r) => r + 1);
}
} catch (error) {
console.log("Failed to decode token AccountInfo");
}
} }
} }
); );