Skip to content

Port contract token search fix back to main#803

Merged
CassioMG merged 1 commit intomainfrom
cg-port-customtoken-search-to-main
Apr 7, 2026
Merged

Port contract token search fix back to main#803
CassioMG merged 1 commit intomainfrom
cg-port-customtoken-search-to-main

Conversation

@CassioMG
Copy link
Copy Markdown
Contributor

@CassioMG CassioMG commented Apr 7, 2026

What

Porting this PR from emergency v1.14.25 release to main branch.

The scripts/setup-xcode-latest-stable changes also included on that same PR have already been merged to master so we only need to port the other changes.

@CassioMG CassioMG changed the title Fix crash when adding contract tokens from stellar.expert search Port contract token search fix back to main Apr 7, 2026
@CassioMG CassioMG marked this pull request as ready for review April 7, 2026 00:42
Copilot AI review requested due to automatic review settings April 7, 2026 00:42
@CassioMG CassioMG self-assigned this Apr 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ports the emergency fix for adding Soroban contract tokens from stellar.expert search results back to main, updating parsing/type definitions and adding UI/store guardrails to prevent crashes and unsupported swap flows.

Changes:

  • Update token search parsing to correctly handle stellar.expert contract-token records (raw contract IDs) and tolerate missing tomlInfo.
  • Extend SearchTokenResponse typing to match stellar.expert’s current schema and add tests covering contract-token parsing/fallback.
  • Prevent swap pathfinding for custom/Soroban tokens and add new localized error messaging.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/hooks/useTokenLookup.ts Adds contract-token detection/parsing + hardens icon extraction against missing tomlInfo.
src/config/types.ts Updates SearchTokenResponse schema (optional tomlInfo, new top-level metadata fields).
src/components/screens/AddTokenScreen/AddTokenBottomSheetContent.tsx Adds defensive contract-id selection to avoid new Asset() crashes.
tests/hooks/useTokenLookup.test.tsx Adds tests for contract-token parsing and missing-metadata fallback behavior.
src/ducks/swap.ts Blocks swap pathfinding for custom/Soroban tokens and surfaces a specific error message.
src/components/screens/SwapScreen/screens/SwapAmountScreen.tsx Adjusts path-error toast effect dependencies.
src/i18n/locales/en/translations.json Adds swap error string for unsupported custom token swaps.
src/i18n/locales/pt/translations.json Adds Portuguese swap error string for unsupported custom token swaps.
Comments suppressed due to low confidence (1)

src/hooks/useTokenLookup.ts:237

  • formatTokensFromSearchResults mis-classifies native XLM results from stellar.expert. When result.asset === "XLM", this falls through to the classic-asset path, issuer becomes undefined, and getTokenType(${tokenCode}:${issuer}) resolves to a credit asset (e.g. CREDIT_ALPHANUM4) instead of NATIVE. This also passes an undefined issuer into hasExistingTrustline, which can never match the native balance identifier (issuer should be ""). Consider adding an explicit native-asset branch (e.g. result.asset === NATIVE_TOKEN_CODE) that returns issuer: "", isNative: true, and tokenType: TokenTypeWithCustomToken.NATIVE (and optionally hasTrustline: true).
      // Path 3: stellar.expert — Classic asset (asset format: "CODE-ISSUER-TYPE")
      const [tokenCode, issuer] = result.asset.split("-");
      const tokenIdentifier = getTokenIdentifier({
        type: TokenTypeWithCustomToken.CUSTOM_TOKEN,
        code: tokenCode,
        issuer: {
          key: issuer,
        },
      });
      const iconUrl = icons[tokenIdentifier]?.imageUrl;

      return {
        tokenCode,
        domain: result.domain ?? "",
        hasTrustline: hasExistingTrustline(userBalances, tokenCode, issuer),
        iconUrl,
        issuer: issuer ?? "",
        isNative: result.asset === NATIVE_TOKEN_CODE,
        tokenType: getTokenType(`${tokenCode}:${issuer}`),
      };

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

@CassioMG CassioMG merged commit 62d5d91 into main Apr 7, 2026
40 of 41 checks passed
@CassioMG CassioMG deleted the cg-port-customtoken-search-to-main branch April 7, 2026 01:27
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.

2 participants