Skip to content

Delay SPL token balance fallback refresh#94

Merged
GabrielePicco merged 1 commit into
mainfrom
fix/spl-token-delayed-balance-refresh
Jun 3, 2026
Merged

Delay SPL token balance fallback refresh#94
GabrielePicco merged 1 commit into
mainfrom
fix/spl-token-delayed-balance-refresh

Conversation

@GabrielePicco
Copy link
Copy Markdown
Contributor

@GabrielePicco GabrielePicco commented Jun 3, 2026

Summary

  • delay post-transfer/delegate/withdraw fallback balance refresh by 2.5s
  • let processed account subscriptions update SPL balances before the full refresh runs

Validation

  • yarn build
  • git diff --check

Summary by CodeRabbit

  • Refactor
    • Adjusted balance refresh timing after transfers and delegation operations to use scheduled delays instead of immediate updates.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spl-tokens Ready Ready Preview, Comment Jun 3, 2026 1:42pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 965deed6-afa9-4e1e-8628-d304260b4051

📥 Commits

Reviewing files that changed from the base of the PR and between b62e133 and 5842400.

📒 Files selected for processing (1)
  • spl-tokens/app/src/App.tsx

Walkthrough

This PR introduces a delayed balance refresh mechanism for token operations. A new constant parameterizes the refresh delay, and a memoized callback schedules refreshBalances() via setTimeout. This scheduled refresh is then applied to the transfer flow and delegate/undelegate handlers, replacing immediate refresh calls.

Changes

Delayed Balance Refresh Integration

Layer / File(s) Summary
Delayed refresh mechanism
spl-tokens/app/src/App.tsx
Added BALANCE_FALLBACK_REFRESH_DELAY_MS constant and scheduleBalanceFallbackRefresh() memoized callback that defers refreshBalances() via setTimeout.
Operation handler updates
spl-tokens/app/src/App.tsx
Updated performTransfer, "Delegate", and "Undelegate" handlers to schedule delayed balance refresh after their operations instead of calling refreshBalances() immediately, with adjusted hook dependencies.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/spl-token-delayed-balance-refresh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@GabrielePicco GabrielePicco marked this pull request as ready for review June 3, 2026 13:42
@GabrielePicco GabrielePicco merged commit b174d04 into main Jun 3, 2026
9 of 10 checks passed
@GabrielePicco GabrielePicco deleted the fix/spl-token-delayed-balance-refresh branch June 3, 2026 13:42
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5842400b03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +735 to +737
setTimeout(() => {
refreshBalances().catch(console.error);
}, BALANCE_FALLBACK_REFRESH_DELAY_MS);
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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant