Skip to content

fix(swap): don't default a Convert from Dollars to an empty holding - #1677

Closed
bmc08gt wants to merge 1 commit into
code/cashfrom
fix/convert-destination-fallback
Closed

bmc08gt wants to merge 1 commit into
code/cashfrom
fix/convert-destination-fallback

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Converting from Dollars opens with Dollars as the destination, and SwapViewModel swaps in the largest other entry in tokenBalances. That list can hold zero-balance rows, because TokenState.withAccounts only ever adds holdings. In Bugsnag 6ac36f88991833fd09434aad (2026.9.4), a user holding only Dollars got a leftover USDC row as the destination. All six attempts logged buy of USDC and failed with INVALID_SWAP: mint not found. The first three came before they opened the destination picker, so the fallback chose USDC, not the user.

The fallback now only considers held currencies with a displayable balance. The destination picker (SelectTokenViewModel) and iOS (Session.balances(for:)) already use that filter. With no candidate, the destination stays on Dollars.

Two cases added to SwapViewModelErrorTest: the fallback still picks the largest real holding, and an empty row is never picked.

Not covered here:

  • A Dollars-only holder still has no valid destination. Confirm likely leaves the spinner on, because ProceedWithConversion sets loading before bailing. What that user should see is still open.
  • withAccounts never prunes holdings, so stale rows still reach every tokenBalances reader.

Converting from Dollars opens with Dollars as the destination, and
SwapViewModel swaps in the largest other entry in tokenBalances. That list
can carry zero-balance rows, because TokenState.withAccounts only adds
holdings. Bugsnag 6ac36f88991833fd09434aad: a user holding only Dollars got a
leftover USDC row as the destination, and all six attempts failed with
INVALID_SWAP "mint not found".

Filter the fallback to held currencies with a displayable balance, which is
what the destination picker (SelectTokenViewModel) and iOS
(Session.balances(for:)) already do. With no candidate the destination stays
on Dollars.
@bmc08gt bmc08gt self-assigned this Oct 5, 2026
@github-actions github-actions Bot added area: tokens Token accounts, balances, token info type: fix Bug fix labels Oct 5, 2026
@bmc08gt

bmc08gt commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Folded into #1679, which carries this commit along with the disabled Convert button.

@bmc08gt bmc08gt closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tokens Token accounts, balances, token info type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant