Port contract token search fix back to main#803
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
SearchTokenResponsetyping 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
-
formatTokensFromSearchResultsmis-classifies native XLM results from stellar.expert. Whenresult.asset === "XLM", this falls through to the classic-asset path,issuerbecomesundefined, andgetTokenType(${tokenCode}:${issuer})resolves to a credit asset (e.g.CREDIT_ALPHANUM4) instead ofNATIVE. This also passes anundefinedissuer intohasExistingTrustline, 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 returnsissuer: "",isNative: true, andtokenType: TokenTypeWithCustomToken.NATIVE(and optionallyhasTrustline: 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Porting this PR from emergency v1.14.25 release to
mainbranch.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.