Commit 1a588d5
authored
feat(card): add selectIsUserInSupportedCardCountry (#27695)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
Extracts the Card supported-country check into a dedicated
`selectIsUserInSupportedCardCountry` selector and refactors
`selectDisplayCardButton` to use it.
**Why**: The geo-location vs supported-countries logic was inlined in
`selectDisplayCardButton`. Extracting it into a named selector improves
readability, enables reuse, and simplifies testing. The display logic
becomes clearer: show the Card button when the user is in a supported
country and the feature flag is on.
**What changed**:
- **`selectIsUserInSupportedCardCountry`**: New selector that returns
whether the user's `geoLocation` is in the feature-flag
`cardSupportedCountries` map with value `true`. Uses
`selectCardGeoLocation` and `selectCardSupportedCountries`.
- **`selectDisplayCardButton`**: Refactored to use
`selectIsUserInSupportedCardCountry` instead of inline geo/countries
logic. The condition `(cardSupportedCountries)?.[geoLocation] === true
&& displayCardButtonFeatureFlag` is now `isUserInSupportedCardCountry &&
displayCardButtonFeatureFlag`.
- **Tests**: Added unit tests for `selectIsUserInSupportedCardCountry`
covering supported country, unsupported country, UNKNOWN geoLocation,
explicitly false country, and empty/missing supported countries.
## **Changelog**
CHANGELOG entry: Extracted Card supported-country check into
`selectIsUserInSupportedCardCountry` selector.
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: Card button display in supported vs unsupported countries
Scenario: Card button shows in supported country with feature flag
Given I am in a supported country (e.g. US, GB)
And the Card display feature flag is enabled
When I view the app home/tab bar
Then the Card button should be visible
Scenario: Card button hidden in unsupported country
Given I am in an unsupported country (or geoLocation is UNKNOWN)
And the Card display feature flag is enabled
When I view the app home/tab bar
Then the Card button should not be visible (unless cardholder/alwaysShow)
```
## **Screenshots/Recordings**
No visual design changes — Card button visibility logic is unchanged;
only the selector structure was refactored.
## **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]
> **Low Risk**
> Low risk refactor that extracts existing geoLocation/supported-country
logic into a dedicated selector and wires it into
`selectDisplayCardButton`, with added unit coverage; behavior should
remain the same aside from potential edge cases around missing/empty
country maps.
>
> **Overview**
> Introduces a new selector, `selectIsUserInSupportedCardCountry`, to
centralize the "geoLocation is in `cardSupportedCountries` with value
`true`" check.
>
> Refactors `selectDisplayCardButton` to depend on this selector instead
of inlining the supported-country lookup, and adds focused unit tests
covering supported/unsupported/`UNKNOWN` geoLocation, explicitly
disabled countries, and empty supported-country maps.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
d09eb3c. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 623cfc0 commit 1a588d5
2 files changed
Lines changed: 89 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
720 | 721 | | |
721 | 722 | | |
722 | 723 | | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
723 | 802 | | |
724 | 803 | | |
725 | 804 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
213 | 220 | | |
214 | 221 | | |
215 | 222 | | |
216 | | - | |
217 | | - | |
218 | 223 | | |
219 | 224 | | |
| 225 | + | |
220 | 226 | | |
221 | 227 | | |
222 | 228 | | |
223 | | - | |
224 | | - | |
225 | 229 | | |
226 | 230 | | |
| 231 | + | |
227 | 232 | | |
228 | 233 | | |
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
232 | | - | |
233 | | - | |
234 | | - | |
| 237 | + | |
235 | 238 | | |
236 | 239 | | |
237 | 240 | | |
| |||
0 commit comments