Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions spl-tokens/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const CONFIGURED_SETUP_QUEUE_KEYPAIR = (() => {
})();

export const BLOCKHASH_CACHE_MAX_AGE_MS = 30000
const BALANCE_FALLBACK_REFRESH_DELAY_MS = 2500

const toBase64 = (u8: Uint8Array): string => {
if (typeof Buffer !== 'undefined') return Buffer.from(u8).toString('base64');
Expand Down Expand Up @@ -730,6 +731,12 @@ const App: React.FC = () => {
console.log("[refresh] done");
}, [connection, mint, selectedTokenProgram]);

const scheduleBalanceFallbackRefresh = useCallback(() => {
setTimeout(() => {
refreshBalances().catch(console.error);
}, BALANCE_FALLBACK_REFRESH_DELAY_MS);
Comment on lines +735 to +737
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cancel stale delayed balance refreshes

If a user clicks Reset or runs a new Setup in the 2.5s after a transfer/delegate/withdraw succeeds, this pending timer still invokes the refreshBalances closure captured from the old mint/token program and then calls setAccounts(updated). That can overwrite the current account cards with ATAs and balances for the previous mint after the UI has switched context; keep only the latest timer or cancel it on mint/token-program changes/unmount before applying the fallback refresh.

Useful? React with 👍 / 👎.

}, [refreshBalances]);

// Refresh on mount and whenever the key set or connections change
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => { refreshBalances().catch(console.error); }, [connection, mint]);
Expand Down Expand Up @@ -1020,14 +1027,14 @@ const App: React.FC = () => {
`(from ${src.keypair.publicKey.toBase58()} (sender ata: ${srcAta.toBase58()}), to ${dst.keypair.publicKey.toBase58()} (destination ata: ${dstAta.toBase58()}))`
);
await ephemeralConnection!.current!.getAccountInfo(shuttleWalletAta);
await refreshBalances();
scheduleBalanceFallbackRefresh();
} catch (e: any) {
setTransactionSuccess(null);
setTransactionError(await formatTransactionError(e, conn));
} finally {
setIsSubmitting(false);
}
}, [accounts, connection, confirmOrThrow, decimals, fromBalance, getCachedEphemeralBlockhash, mint, privateMaxDelayMs, privateMinDelayMs, privateSplitCount, refreshBalances, selectedTokenProgram, toBalance, transferVisibility]);
}, [accounts, connection, confirmOrThrow, decimals, fromBalance, getCachedEphemeralBlockhash, mint, privateMaxDelayMs, privateMinDelayMs, privateSplitCount, scheduleBalanceFallbackRefresh, selectedTokenProgram, toBalance, transferVisibility]);

const handleTransfer = useCallback(async () => {
await performTransfer(srcIndex, dstIndex, amountStr);
Expand Down Expand Up @@ -1857,7 +1864,7 @@ const App: React.FC = () => {
console.log("Shuttle wallet ata: ", shuttleWalletAta.toBase58());
console.log("Shuttle eata: ", shuttleEphemeralAta.toBase58());

await refreshBalances();
scheduleBalanceFallbackRefresh();
} catch (e: any) {
setTransactionError(await formatTransactionError(e, connection));
} finally {
Expand Down Expand Up @@ -1957,7 +1964,7 @@ const App: React.FC = () => {
console.log("Shuttle wallet ata: ", shuttleWalletAta.toBase58());
console.log("Shuttle eata: ", shuttleEphemeralAta.toBase58());
console.log("Shuttle ata: ", shuttleAta.toBase58());
await refreshBalances();
scheduleBalanceFallbackRefresh();
} catch (e: any) {
setTransactionError(await formatTransactionError(e, connection));
} finally {
Expand Down
Loading