Skip to content

Conversation

@amitabh94
Copy link
Contributor

@amitabh94 amitabh94 commented Jun 27, 2025

Description

Fixes a crash that occurs when viewing asset details for Solana tokens in the Bridge flow. The issue was caused by getTokenDetails assuming all non-EVM asset addresses are already in CAIP format, when the Bridge API sometimes returns raw Solana addresses.

Related issues

Fixes #16734
Fixes SWAPS-2525

Manual testing steps

  1. Navigate to Bridge feature
  2. Select Solana as source or destination chain
  3. Select any Solana token from the token list
  4. Tap on the asset detail info button
  5. Verify the asset details screen loads without crashing
  6. Verify contract address and other details display correctly

Screenshots/Recordings

Before:

ScreenRecording_06-25-2025.17-44-43_1.MOV

After:

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-06-27.at.14.16.00.mp4

Pre-merge author checklist

  • I've followed MetaMask Coding Standards
  • I've clearly explained what problem this PR solves
  • I've linked the issue that this PR fixes
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I've added unit tests if applicable

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed)
  • I confirm that this PR addresses the issue linked above
  • I've checked that all unit tests pass

Solution Details

Root Cause

The getTokenDetails function was calling parseCaipAssetType directly on asset.address for non-EVM assets, assuming it was already in CAIP format. However, the Bridge API sometimes returns raw Solana addresses instead of CAIP-formatted addresses, causing parseCaipAssetType to throw an error.

Fix Applied

Implemented the same defensive approach used in useTokenHistoricalPrices:

// Detect if address is already in CAIP format
const isCaipAssetType = asset.address.startsWith(`${asset.chainId}`);

// Convert to CAIP format if needed
const normalizedCaipAssetTypeAddress = isCaipAssetType
  ? asset.address
  : `${asset.chainId}/token:${asset.address}`;

Benefits

  • Fixes crash: Solana asset details now load without errors
  • Backward compatible: Handles both raw and CAIP format addresses
  • Consistent pattern: Uses same approach as useTokenHistoricalPrices
  • Zero breaking changes: All existing functionality preserved
  • Future-proof: Works with any non-EVM chain automatically

Testing

  • Added comprehensive unit tests covering both scenarios
  • All 12 tests pass including new test cases
  • Verified with existing Bridge test suite
  • Manual testing confirms crash is resolved

@amitabh94 amitabh94 added QA Passed QA testing has been completed and passed Run Smoke E2E labels Jun 27, 2025
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-swaps-and-bridge Swaps and Bridge team label Jun 27, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jun 27, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 0877a7f
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/98188281-909f-4eb6-ac50-e3f23f91c348

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@amitabh94 amitabh94 changed the title fix(bridge): prevent crash when viewing Solana asset details fix(bridge): fix: cp-7.47.3 prevent crash when viewing Solana asset details Jun 27, 2025
@amitabh94 amitabh94 marked this pull request as ready for review June 27, 2025 19:12
@amitabh94 amitabh94 requested a review from a team as a code owner June 27, 2025 19:12
@amitabh94 amitabh94 enabled auto-merge June 27, 2025 19:28
@github-actions
Copy link
Contributor

github-actions bot commented Jun 27, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 0361cae
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/0b0c9907-e49f-4637-9afc-ea3c2989e151

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@github-actions
Copy link
Contributor

github-actions bot commented Jun 27, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 4db6fa9
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/b55943d5-fa74-4ffa-8b74-ebc6c53965f6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@sonarqubecloud
Copy link

Merged via the queue into main with commit 86633c5 Jun 28, 2025
54 of 56 checks passed
@amitabh94 amitabh94 deleted the SWAPS-2525-fix-app-crash-solana-asset-detail branch June 28, 2025 01:14
@github-actions github-actions bot locked and limited conversation to collaborators Jun 28, 2025
@metamaskbot metamaskbot added the release-7.51.0 Issue or pull request that will be included in release 7.51.0 label Jun 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

QA Passed QA testing has been completed and passed release-7.51.0 Issue or pull request that will be included in release 7.51.0 team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: App crashes when selecting asset detail info from swap token list for solana swaps

4 participants