Commit f053689
authored
fix(ramp): parse slip44 intent as native asset cp-7.61.0 (MetaMask#23689)
## **Description**
This PR adds slip44 wildcard matching support to the Deposit
`useCryptoCurrencies` hook, aligning it with the existing behavior in
the Aggregator flow.
**Reason for change:**
When navigating to the Deposit flow from the Asset Details page with a
native asset (e.g., ETH), the intent contains a wildcard asset ID like
`eip155:1/slip44:.`. However, the Deposit SDK returns native tokens with
specific slip44 coin types (e.g., `eip155:1/slip44:60`). The direct
string comparison was failing to match these, causing the native token
not to be pre-selected.
**Solution:**
Added fallback logic that parses the CAIP-19 asset ID and matches any
token with the same `chainId` and `slip44` namespace when the direct
match fails. This mirrors the existing behavior in the Aggregator
`useCryptoCurrencies` hook.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: MetaMask#23441
## **Manual testing steps**
```gherkin
Feature: Native token selection in Deposit flow
Scenario: user navigates to Deposit from Asset Details with native token
Given the user is on the Asset Details page for ETH (or any native token)
And the Deposit flow is enabled for the user's region
When user taps the "Buy" button
Then the Deposit flow opens with ETH pre-selected as the cryptocurrency
```
## **Screenshots/Recordings**
### **Before**
https://github.com/user-attachments/assets/5a7b1ca1-3939-4ab1-a693-bf8579814e98
### **After**
https://github.com/user-attachments/assets/293d0de4-a430-43d3-b0bd-c97315baecd4
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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 all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Adds slip44 wildcard CAIP-19 intent matching to pre-select native
tokens in the Deposit flow and introduces focused tests for this
behavior.
>
> - **Hook**
(`app/components/UI/Ramp/Deposit/hooks/useCryptoCurrencies.ts`):
> - Add slip44 wildcard handling by parsing CAIP-19
(`parseCAIP19AssetId`) when direct `assetId` match fails, selecting a
native token with the same `chainId` and `slip44` namespace.
> - Preserve direct `assetId` match precedence over wildcard matching.
> - Minor refactor to use a mutable `intentCrypto` before selection.
> - **Tests**
(`app/components/UI/Ramp/Deposit/hooks/useCryptoCurrencies.test.ts`):
> - Add cases for slip44 wildcard selecting native token (same/different
`chainId`).
> - Add fallback to first token when no native match found.
> - Confirm direct match is preferred over wildcard.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7d6606a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent fa3b09c commit f053689
2 files changed
Lines changed: 115 additions & 1 deletion
Lines changed: 97 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
432 | 529 | | |
433 | 530 | | |
Lines changed: 18 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
63 | 80 | | |
64 | 81 | | |
65 | 82 | | |
| |||
0 commit comments