Skip to content

Warn before a send or swap strands tokens - #6209

Open
j0ntz wants to merge 1 commit into
developfrom
jon/full-balance-send-warning
Open

j0ntz wants to merge 1 commit into
developfrom
jon/full-balance-send-warning

Conversation

@j0ntz

@j0ntz j0ntz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Description

A wallet that holds tokens needs its gas asset to move them. Nothing stops a user from
max-sending or max-swapping the whole gas balance, which strands every token left behind.

This adds a warning modal that fires before the transaction is signed, in both the send
and the swap flow:

  • src/util/stuckFundsWarning.ts decides whether the pending transaction leaves the
    source wallet without enough gas to move what stays. The threshold is the
    transaction's own fee: a wallet that cannot afford one more transaction of the same
    size counts as drained.
  • src/components/modals/StuckFundsWarningModal.tsx shows a plain ButtonsModal
    (warning border, Continue Anyway / Cancel) and resolves to a boolean.
  • SendScene2.handleSliderComplete gates every send path (ramps, gift cards, FIO, scan,
    wallet list, transfer modal all funnel through send2).
  • SwapConfirmationScene.handleSlideComplete gates swaps, where the real from-amount and
    network fee are known.

Two cases fire the warning, per the task's acceptance criteria:

  1. The wallet holds a nonzero token balance and the transaction spends effectively all
    of the gas asset.
  2. The wallet holds no tokens and the swap puts one in that same wallet while draining
    the gas needed to move it out.

UTXO chains cannot hit either case, so their behavior is unchanged.

Two cases are deliberately excluded, both raised in review:

  • A same-wallet swap whose payout is the gas asset (the "buy gas" path) credits
    toNativeAmount back into the leftover-gas figure, so it does not warn.
  • A transaction that spends a token discounts that amount from the token balance, so
    emptying the last token does not warn about tokens that will not be there.

The swap scene's terms-modal expiry deferral was generalized to cover any blocking modal,
so a quote cannot expire and close behind the warning while it is up.

Asana: https://app.asana.com/0/1215088146871429/1209102990528561

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

@j0ntz

j0ntz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence

max send fantom with tokens

max send fantom with tokens

stuck funds warning modal

stuck funds warning modal

cancel returns to send

cancel returns to send

send broadcast success

send broadcast success

send txid onchain

send txid onchain

max swap quote

max swap quote

swap stuck funds warning

swap stuck funds warning

swap cancel no execution

swap cancel no execution

Captured by the agent's in-app test run (build-and-test).

@j0ntz
j0ntz force-pushed the jon/full-balance-send-warning branch from 5abc3e6 to b3102a5 Compare September 10, 2026 00:35
@j0ntz
j0ntz marked this pull request as ready for review September 10, 2026 00:35
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/components/scenes/SwapConfirmationScene.tsx
Comment thread src/components/scenes/SwapConfirmationScene.tsx
@j0ntz
j0ntz force-pushed the jon/full-balance-send-warning branch from b3102a5 to e4fed2a Compare September 10, 2026 00:50

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e4fed2a. Configure here.

Comment thread src/util/stuckFundsWarning.ts
A wallet that holds tokens needs its gas asset to move them. Both
SendScene2 and SwapConfirmationScene now check the wallet's leftover gas
against the pending transaction's own fee, and show a warning modal with
a cancel path when the wallet would be left unable to pay one more fee.

Also covers a token-less wallet swapping its whole gas balance into a
token on that same wallet.
@j0ntz
j0ntz force-pushed the jon/full-balance-send-warning branch from e4fed2a to f0cb504 Compare September 10, 2026 01:00
@j0ntz

j0ntz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

📸 Test evidence (after fix)

swap warning after fixes

swap warning after fixes

swap warning final head

swap warning final head

Captured by the agent's in-app test run (build-and-test).

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