Skip to content

Commit 3f213aa

Browse files
fix: Empty token buffer decode error (#84)
1 parent 80b0fa4 commit 3f213aa

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/context/Token.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,18 @@ export function useOwnedTokenAccount(
128128
listener = provider.connection.onAccountChange(
129129
tokenAccount.publicKey,
130130
(info) => {
131-
const token = parseTokenAccountData(info.data);
132-
if (token.amount !== tokenAccount.account.amount) {
133-
const index = _OWNED_TOKEN_ACCOUNTS_CACHE.indexOf(tokenAccount);
134-
assert.ok(index >= 0);
135-
_OWNED_TOKEN_ACCOUNTS_CACHE[index].account = token;
136-
setRefresh((r) => r + 1);
131+
if (info.data.length !== 0) {
132+
try {
133+
const token = parseTokenAccountData(info.data);
134+
if (token.amount !== tokenAccount.account.amount) {
135+
const index = _OWNED_TOKEN_ACCOUNTS_CACHE.indexOf(tokenAccount);
136+
assert.ok(index >= 0);
137+
_OWNED_TOKEN_ACCOUNTS_CACHE[index].account = token;
138+
setRefresh((r) => r + 1);
139+
}
140+
} catch (error) {
141+
console.log("Failed to decode token AccountInfo");
142+
}
137143
}
138144
}
139145
);

0 commit comments

Comments
 (0)