Commit a84b764
authored
chore: update cta to respect buy regions and route correctly per chain (MetaMask#24048)
## **Description**
Fixed an issue where the MUSD CTA was incorrectly displaying when a
single unsupported chain (like BSC) was selected in the network filter.
The bug occurred because when a non-buyable chain was selected, the code
was still showing the CTA if mUSD was buyable on *any* chain (e.g.,
Mainnet or Linea), rather than hiding it completely. This was confusing
for users since they couldn't actually buy mUSD on the selected chain.
**Changes:**
- When a non-buyable chain is selected (BSC, Polygon, Arbitrum, etc.),
the CTA now correctly hides
- When a buyable chain is selected but mUSD is not available in the
user's region for that specific chain, the CTA now correctly hides
## **Changelog**
CHANGELOG entry: Fixed mUSD CTA incorrectly appearing on unsupported
chains like BSC
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/MUSD-124
## **Manual testing steps**
```gherkin
Feature: MUSD CTA visibility
Scenario: user selects BSC network
Given user is on the token list view
And user does not have any MUSD balance
And user does not have any token balance
When user selects BSC as the only network filter
Then the MUSD CTA should not be displayed
Scenario: user selects Linea network
Given user is on the token list view
And user does not have any MUSD balance
And user does not have any token balance
And mUSD is buyable in user's region on Linea
When user selects Linea as the only network filter
Then the MUSD CTA should be displayed with network icon
Scenario: user selects Mainnet network
Given user is on the token list view
And user does not have any MUSD balance
And user does not have any token balance
And mUSD is buyable in user's region on Mainnet
When user selects Mainnet as the only network filter
Then the MUSD CTA should be displayed with network icon
Scenario: user selects all networks
Given user is on the token list view
And user does not have any MUSD balance
And user does not have any token balance
And mUSD is buyable in user's region
When user has all networks selected
Then the MUSD CTA should be displayed without network icon
Scenario: user selects Linea network
Given user is on the token list view
And user does not have any MUSD balance
And user does has token balance
When user selects any network filter
Then the MUSD CTA should be displayed with network icon
Then the MUSD CTA should direct to BuyWithToken component on the chain of token being converted (soon to be constrained to that chain specifically in. separate pr)
```
## **Screenshots/Recordings**
### **Before**
<!-- [screenshots/recordings] -->
### **After**
https://github.com/user-attachments/assets/45040e69-f737-4112-baad-36f0390c3453
<!-- [screenshots/recordings] -->
## **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]
> Updates the mUSD CTA to show/hide and route per selected chain and
regional availability, with a new feature flag, network badge, and
supporting hooks/tests.
>
> - **Earn UI – mUSD CTA**:
> - Integrates `useMusdCtaVisibility` to conditionally render CTA; hides
on non-buyable/unsupported chains and when mUSD isn’t buyable in-region.
> - Shows network badge for single supported selections using
`BadgeWrapper` and `getNetworkImageSource`; aligns avatar layout.
> - Adjusts buy flow to use `selectedChainId` (fallback to
`MUSD_CONVERSION_DEFAULT_CHAIN_ID`).
> - **Hooks/Logic**:
> - Adds `useHasMusdBalance` to detect mUSD balances across chains.
> - Adds `useMusdCtaVisibility` to compute `shouldShowCta`,
`showNetworkIcon`, and `selectedChainId` based on feature flag, selected
networks, ramp token availability, and balances.
> - Introduces `MUSD_BUYABLE_CHAIN_IDS` (excludes BSC) and uses
`MUSD_TOKEN_ASSET_ID_BY_CHAIN` for routing.
> - **Feature Flags/Config**:
> - Adds env flag `MM_MUSD_CTA_ENABLED` and selector
`selectIsMusdCtaEnabledFlag`.
> - **Tests**:
> - Extensive new tests for `useHasMusdBalance`, `useMusdCtaVisibility`,
and updated CTA tests for visibility, routing, and network badge
behavior.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
cd04745. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 57050eb commit a84b764
10 files changed
Lines changed: 1275 additions & 7 deletions
File tree
- app/components/UI/Earn
- components/Musd/MusdConversionAssetListCta
- constants
- hooks
- selectors/featureFlags
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
Lines changed: 161 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| |||
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
71 | 84 | | |
72 | 85 | | |
73 | 86 | | |
| |||
373 | 386 | | |
374 | 387 | | |
375 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 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 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
376 | 537 | | |
Lines changed: 46 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| |||
37 | 45 | | |
38 | 46 | | |
39 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
40 | 51 | | |
41 | 52 | | |
42 | 53 | | |
| |||
54 | 65 | | |
55 | 66 | | |
56 | 67 | | |
57 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
58 | 72 | | |
59 | 73 | | |
60 | 74 | | |
| |||
84 | 98 | | |
85 | 99 | | |
86 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
87 | 114 | | |
88 | 115 | | |
89 | 116 | | |
90 | 117 | | |
91 | 118 | | |
92 | 119 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
98 | 138 | | |
99 | 139 | | |
100 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
| |||
0 commit comments