You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(card): disable swaps if selected address is different from priority token owner address (#21454)
<!--
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**
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
Implements account address validation for the Card feature's "Add Funds"
functionality.
The feature now disables swaps when the priority token owner address
doesn't match the user's selected EVM or Solana account address.
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: Disabled "Add Funds" button when priority token address
doesn't match selected account on Card feature
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: Card Add Funds Swap Validation
Scenario: Add Funds button enabled when accounts match
Given the priority token address matches the selected account
When the Card Home loads
Then the "Add Funds" button should be enabled
Scenario: Add Funds button disabled when accounts don't match
Given the priority token address doesn't match the selected account
When the Card Home loads
Then the "Add Funds" button should be disabled
Scenario: EVM addresses compared case-insensitively
Given an EVM account with address "0x1234...5678"
And a priority token with address "0xABCD...5678" (different case)
When comparing addresses
Then they should match (case-insensitive)
Scenario: Solana addresses compared case-sensitively
Given a Solana account with address "SolanaAddress123"
And a priority token with address "solanaaddress123" (different case)
When comparing addresses
Then they should NOT match (case-sensitive)
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/75b7c5f1-44ce-491d-a728-be8b58092e7a
## **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]
> Disables the Card Home Add Funds action based on a new
address-matching hook, adds disabled styling/tests, and improves SDK
error logging for external wallet fetches.
>
> - **Card Home**:
> - Integrates `useIsSwapEnabledForPriorityToken` to gate `Add Funds` by
address match; sets `disabled` and applies
`styles.halfWidthButtonDisabled` when not allowed.
> - Updates `ButtonsSection` deps to include
`isSwapEnabledForPriorityToken`.
> - **New Hook**: `useIsSwapEnabledForPriorityToken`
> - Returns true when not authenticated; otherwise requires priority
token owner address to match selected account (EVM case-insensitive,
Solana case-sensitive).
> - **Styles**: Adds `halfWidthButtonDisabled` in `CardHome.styles.ts`.
> - **Tests**:
> - Adds `useIsSwapEnabledForPriorityToken.test.ts` covering auth and
EVM/Solana comparisons.
> - Extends `CardHome.test.tsx` to verify `Add Funds` enabled/disabled
behavior and styling; updates snapshots.
> - **SDK** (`CardSDK.ts`): Enhances error logging by attempting to
parse and log JSON bodies when fetching external and priority wallet
details fails.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
5af32de. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
0 commit comments