Skip to content

Bugfix/contract id search#2679

Merged
piyalbasu merged 9 commits intoemergency-releasefrom
bugfix/contract-id-search
Apr 4, 2026
Merged

Bugfix/contract id search#2679
piyalbasu merged 9 commits intoemergency-releasefrom
bugfix/contract-id-search

Conversation

@piyalbasu
Copy link
Copy Markdown
Contributor

@piyalbasu piyalbasu commented Apr 3, 2026

Closes #2677

This pull request adds comprehensive support and testing for assets identified by contract IDs (Soroban tokens) throughout the extension, especially in asset search, balance lookup, and swap error handling. It introduces new e2e and unit tests, improves the asset lookup logic to handle contract ID results from Stellar Expert, and ensures user-friendly error messages when attempting unsupported swaps with contract assets.

Contract ID (Soroban token) support in asset search and balances:

  • Added new helper and e2e tests to verify that searching for assets by contract ID in the "Manage Assets" flow correctly displays "Add" or "Already Added" states and allows adding tokens returned as contract IDs. (addAssetContractSearch.test.ts, helpers/stubs.ts) [1] [2]
  • Updated the asset lookup logic to recognize and properly construct asset details for contract ID results from Stellar Expert, including mapping fields like code, token_name, decimals, and TOML info. (useAssetLookup.ts) [1] [2] [3]
  • Enhanced the findAssetBalance helper to match balances by contract ID for Soroban tokens, with new unit tests verifying classic and contract asset handling. (balance.ts, balance.test.js) [1] [2] [3]

Swap error handling improvements:

  • Implemented a utility (getSwapErrorMessage) that surfaces clear, user-friendly error messages when swaps involve contract ID assets, including a specific message for unsupported custom token swaps, and added thorough unit tests. (useSimulateSwapData.tsx, useSimulateSwapData.test.ts) [1] [2] [3]

These changes ensure the extension can robustly handle Soroban contract tokens in asset management and provide clear feedback to users during swaps and asset searches.

piyalbasu and others added 5 commits April 3, 2026 16:57
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>
…earch

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>
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>
- 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>
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>
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 popup asset search flow to correctly handle Stellar Expert search results that return Soroban contract IDs (in addition to classic CODE-ISSUER assets), and ensures ownership detection works for contract-based token balances.

Changes:

  • Extend useAssetLookup to detect contract IDs from Stellar Expert results and resolve them via the existing token lookup flow.
  • Update findAssetBalance to match Soroban balances by contractId when the “issuer” is a contract ID.
  • Add unit tests for findAssetBalance and new Playwright E2E coverage for searching/adding contract-ID-returned tokens.

Reviewed changes

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

File Description
extension/src/popup/helpers/balance.ts Adds contract-id matching in findAssetBalance for Soroban token balances.
extension/src/popup/helpers/tests/balance.test.js Adds unit tests covering classic vs contract-id balance matching.
extension/src/popup/components/manageAssets/SearchAsset/hooks/useAssetLookup.ts Parses Stellar Expert results into classic rows vs contract IDs, then fetches token details for contract IDs.
extension/e2e-tests/addAssetContractSearch.test.ts Adds E2E tests covering “already added”, “Add”, and add-confirm flows for contract-ID search results.

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

@piyalbasu
Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

@copilot apply changes based on the comments in this thread

Applied both changes from the review in commit 45e00f0:

  1. Stubs refactoring: Moved stubAssetSearchWithContractId into helpers/stubs.ts and updated addAssetContractSearch.test.ts to import stubAssetSearchWithContractId and stubAccountBalancesE2e from there, removing the duplicated local stubs.

  2. Abort signal check: Updated the Promise.allSettled loop in useAssetLookup.ts to guard captureException/console.error with !signal.aborted, so rejections caused by request cancellation no longer generate noisy error telemetry.

piyalbasu and others added 3 commits April 3, 2026 18:52
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>
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>
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>
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


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

Copy link
Copy Markdown
Contributor

@CassioMG CassioMG left a comment

Choose a reason for hiding this comment

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

LGTM!

@piyalbasu piyalbasu merged commit a4f2205 into emergency-release Apr 4, 2026
7 checks passed
@piyalbasu piyalbasu deleted the bugfix/contract-id-search branch April 4, 2026 00:33
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.

4 participants