Skip to content

Bugfix/contract id search (#2679)#2680

Closed
piyalbasu wants to merge 1 commit intomasterfrom
emergency-release
Closed

Bugfix/contract id search (#2679)#2680
piyalbasu wants to merge 1 commit intomasterfrom
emergency-release

Conversation

@piyalbasu
Copy link
Copy Markdown
Contributor

  • Handle contract ID results from Stellar Expert asset search

The Stellar Expert API now returns contract IDs (C...) alongside classic {code}-{issuer} assets. Route contract-ID results through the token lookup flow and fix findAssetBalance to match by contractId so already-added tokens show the correct button state.

  • Add e2e test for adding a token via contract ID from Stellar Expert search

Covers the full add-token flow when Stellar Expert returns a contract ID instead of {code}-{issuer}: search -> click Add -> confirm on the ToggleToken page.

  • Fix e2e test to check ellipsis button on the specific E2E token row

The previous assertion failed because it matched multiple rows. Use the specific ManageAssetRowButton__ellipsis-E2E test ID to assert the owned contract token shows the ellipsis menu instead of "Add".

  • Address code review feedback for contract ID search changes
  • Hoist isContractId check out of balances.find() loop in findAssetBalance

The check is invariant to the loop iteration — hoisting it makes the three lookup strategies (native, contract, classic) distinct top-level branches.

  • Address review feedback: move stubs to helpers and skip abort telemetry

Agent-Logs-Url: https://github.com/stellar/freighter/sessions/01d13312-6e53-44c0-936a-8b25cf011859

  • Use Stellar Expert metadata directly for contract ID results

Stellar Expert already returns code, token_name, decimals, domain, and tomlInfo for contract ID records. Use this data to build ManageAssetCurrency rows directly instead of making redundant RPC calls via fetchTokenData.

  • Fix issuer field for contract ID results to use token contract

tomlInfo.issuer can be a different address than the token's own contract ID. Always use record.asset (the token contract) as issuer so findAssetBalance correctly matches balance.contractId. Update stub to use a divergent tomlInfo.issuer to prevent this class of bug from passing tests silently.

  • Show custom token error when swapping SEP-41 tokens

Extract swap error logic into getSwapErrorMessage helper. Known errors surface first regardless of asset type; unrecognized errors for contract-ID assets show "Swapping custom tokens is not supported yet."


* Handle contract ID results from Stellar Expert asset search

The Stellar Expert API now returns contract IDs (C...) alongside classic
{code}-{issuer} assets. Route contract-ID results through the token lookup
flow and fix findAssetBalance to match by contractId so already-added
tokens show the correct button state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add e2e test for adding a token via contract ID from Stellar Expert search

Covers the full add-token flow when Stellar Expert returns a contract ID
instead of {code}-{issuer}: search -> click Add -> confirm on the
ToggleToken page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix e2e test to check ellipsis button on the specific E2E token row

The previous assertion failed because it matched multiple rows. Use the
specific ManageAssetRowButton__ellipsis-E2E test ID to assert the owned
contract token shows the ellipsis menu instead of "Add".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address code review feedback for contract ID search changes

- Use discriminated union (StellarExpertResult) for fetchStellarExpertData
  return type instead of placeholder ManageAssetCurrency objects (#6, #2)
- Fetch contract token data in parallel with Promise.allSettled (#1)
- Use top-level Page import instead of inline import() type (#7)
- Use precise ManageAssetCode selector for row filtering in e2e tests (#8)
- Add unit tests for findAssetBalance with contract ID matching (#9)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Hoist isContractId check out of balances.find() loop in findAssetBalance

The check is invariant to the loop iteration — hoisting it makes the
three lookup strategies (native, contract, classic) distinct top-level
branches.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Address review feedback: move stubs to helpers and skip abort telemetry

Agent-Logs-Url: https://github.com/stellar/freighter/sessions/01d13312-6e53-44c0-936a-8b25cf011859

Co-authored-by: piyalbasu <6789586+piyalbasu@users.noreply.github.com>

* Use Stellar Expert metadata directly for contract ID results

Stellar Expert already returns code, token_name, decimals, domain, and
tomlInfo for contract ID records. Use this data to build ManageAssetCurrency
rows directly instead of making redundant RPC calls via fetchTokenData.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix issuer field for contract ID results to use token contract

tomlInfo.issuer can be a different address than the token's own contract
ID. Always use record.asset (the token contract) as issuer so
findAssetBalance correctly matches balance.contractId. Update stub to
use a divergent tomlInfo.issuer to prevent this class of bug from
passing tests silently.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Show custom token error when swapping SEP-41 tokens

Extract swap error logic into getSwapErrorMessage helper. Known errors
surface first regardless of asset type; unrecognized errors for
contract-ID assets show "Swapping custom tokens is not supported yet."

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: piyalbasu <6789586+piyalbasu@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 4, 2026 00:38
@piyalbasu piyalbasu closed this Apr 4, 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

This PR updates the asset search + manage-assets flow to correctly handle Stellar Expert search results that return Soroban contract IDs (C…) alongside classic {code}-{issuer} assets, and improves related balance matching and swap error messaging.

Changes:

  • Update findAssetBalance to match Soroban assets by balance.contractId when the searched asset issuer is a contract ID.
  • Extend Stellar Expert asset search mapping to build ManageAssetCurrency rows for contract-ID records using Stellar Expert-provided metadata.
  • Add unit + e2e coverage for contract-ID search behavior (manage assets button state + add-token flow) and add a swap error helper for custom-token swap messaging.

Reviewed changes

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

Show a summary per file
File Description
extension/src/popup/helpers/balance.ts Adds contract-ID branch to findAssetBalance so owned Soroban tokens are detected via contractId.
extension/src/popup/helpers/tests/balance.test.js Adds unit tests covering classic and contract-ID matching behavior for findAssetBalance.
extension/src/popup/components/swap/SwapAmount/hooks/useSimulateSwapData.tsx Extracts swap error selection into getSwapErrorMessage and adds a custom-token swap message for contract-ID assets.
extension/src/popup/components/swap/SwapAmount/hooks/tests/useSimulateSwapData.test.ts Adds unit tests for getSwapErrorMessage behavior across classic/contract assets and error shapes.
extension/src/popup/components/manageAssets/SearchAsset/hooks/useAssetLookup.ts Maps Stellar Expert contract-ID records into ManageAssetCurrency rows using metadata fields (code/name/decimals/domain/tomlInfo).
extension/e2e-tests/helpers/stubs.ts Adds Stellar Expert search stub that returns a contract-ID record with realistic tomlInfo.issuer divergence.
extension/e2e-tests/addAssetContractSearch.test.ts Adds e2e coverage for contract-ID search results: owned-token ellipsis state, not-owned “Add” state, and full add-token confirmation flow.

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

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