Skip to content

feat(swap): default the "You receive" token to USDC - #2940

Merged
JiahuiWho merged 8 commits into
masterfrom
feature/swap-default-usdc-destination
Aug 18, 2026
Merged

feat(swap): default the "You receive" token to USDC#2940
JiahuiWho merged 8 commits into
masterfrom
feature/swap-default-usdc-destination

Conversation

@JiahuiWho

@JiahuiWho JiahuiWho commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What

Closes #2914.

  1. The swap flow's You receive field now defaults to the network's USDC instead of the empty Select state.
  2. When the flow starts from USDC itself, the destination defaults to native XLM instead.
  3. Also removes the + icon from the empty Select pill.

Main Changes

Trustline Flag

  • destRequiresTrustline is derived from balances and drives everything that depends on "this swap adds a trustline":
    • the changeTrust op in getBuiltTx,
    • the 2-op fee,
    • the XLM-reserve preflight and Max deduction,
    • the review screen's trustline banner/info sheet
  • useGetBalances now exposes the pre-filter list, so a hidden held asset never gets a redundant changeTrust, doubled fee, false reserve block, or a trustline limit reset to the SDK default
  • swapTrustlineAdded telemetry gates on the changeTrust op in the submitted XDR itself, so it can't disagree with what settled on-chain

Destination icon

  • getAssetIcons gains additionalAssetIds (mirroring token prices') so the unheld destination's logo resolves through the held-token pipeline.

Testing

  • Swap.destinationDefault.test.tsx: network defaults, USDC-source → XLM, param precedence, unconfigured networks
  • getBuiltTx tests: changeTrust prepended for unheld destinations, asset taken from destAsset
  • ReviewTx.trustlineBanner tests: banner renders from the derived flag with no snapshot; derived flag overrides a stale snapshot
  • Full suite green, tsc clean; verified live on testnet (default + collision fallback, trustline banner and 2-op fee for an unheld destination, no banner/single-op fee for a hidden held destination)

Updated 08/14
https://github.com/user-attachments/assets/a0872e72-62ae-4167-a257-dabb3ac3bbb6

Copilot AI balanced review requested due to automatic review settings August 5, 2026 20:40
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PR Preview build is ready: https://github.com/stellar/freighter/releases/tag/untagged-db549df9ccb149d4c4df (SDF collaborators only — install instructions in the release description)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Defaults swap destinations to network USDC, falling back to XLM when swapping from USDC.

Changes:

  • Adds network-specific USDC defaults and initialization logic.
  • Resolves destination icons from token lists.
  • Removes the empty-state plus icon and adds tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
@shared/constants/stellar.ts Defines network USDC destinations.
extension/src/popup/views/Swap/index.tsx Applies destination defaults.
extension/src/popup/views/__tests__/Swap.destinationDefault.test.tsx Tests default-selection behavior.
extension/src/popup/components/swap/SwapAmount/hooks/useGetSwapAmountData.tsx Resolves non-held destination icons.
extension/src/popup/components/amount/AmountCard/index.tsx Removes the plus icon.
extension/src/popup/components/amount/AmountCard/styles.scss Adjusts selector sizing and padding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/src/popup/views/Swap/index.tsx
Comment thread extension/src/popup/components/swap/SwapAmount/hooks/useGetSwapAmountData.tsx Outdated
@aristidesstaffieri

Copy link
Copy Markdown
Contributor

a4ba4f044 moved the trustline decision to a balances-derived flag (destRequiresTrustline, SwapAmount/index.tsx:151) and wired it into the builder, but the disclosure and telemetry consumers still read the pick-time snapshot. There are now two sources of truth and they disagree on the path this PR adds.

ReviewTransaction/index.tsx:314:

const requiresTrustline = !!destinationTokenDetails?.requiresTrustline;

destinationTokenDetails is populated only by the picker's onClickAsset (views/Swap/index.tsx:179); the default path at :148-150 dispatches saveDestinationAsset alone, and useSwapDestinationScan bails on !details so it cannot bootstrap the value. For a user who does not hold USDC — the target case for this default — destRequiresTrustline is true and the built transaction carries changeTrust, while requiresTrustline is false and neither TrustlineBanner nor TrustlineInfoSheet renders.

Net effect: the user signs a two-op transaction that locks 0.5 XLM of reserve, with no disclosure anywhere in the flow. The fee is correctly doubled but unexplained. shouldShowXlmReservePreflight was migrated to the new flag, so the XlmReserveSheet only covers users who cannot afford the reserve — sufficiently funded accounts get no signal at all.

Same stale gate at SubmitTransaction/hooks/useSubmitTxData.tsx:114, so swapTrustlineAdded will not fire for any default-destination swap.

Suggest threading destRequiresTrustline down to ReviewTx (SwapAmount/index.tsx:876) and to the submit metric instead. The banner and sheet only need a token code, which is available from getAssetFromCanonical(destinationAsset).code without the snapshot.

Comment thread extension/src/popup/components/swap/SwapAmount/index.tsx
@JiahuiWho
JiahuiWho merged commit b1de4e6 into master Aug 18, 2026
11 checks passed
@JiahuiWho
JiahuiWho deleted the feature/swap-default-usdc-destination branch August 18, 2026 17:46
@github-actions github-actions Bot mentioned this pull request Aug 18, 2026
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.

[Swap] Default the "You receive" token to USDC

3 participants