Skip to content

Commit 7648fd7

Browse files
feat: cp-7.60.0 validate source amount in metamask pay (#22758)
## **Description** Validate the raw source amount in MetaMask Pay after quotes are retrieved. Also validate the source network fee using the max raw amount, rather than the estimated USD value. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: [#6263](MetaMask/MetaMask-planning#6263) #22722 ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **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] > Validates MetaMask Pay source amounts and max network fees using new totals fields, consolidates insufficient-fee alerts, updates fee displays/metrics, and bumps transaction-pay-controller to v7. > > - **Confirmations / Pay**: > - **Validation & totals**: Use `totals.fees.sourceNetwork.estimate.usd` for displayed network fees and validate fees with raw amounts (`sourceAmount.raw` + `fees.sourceNetwork.max.*`). > - **Alerts**: Add `AlertKeys.InsufficientPayTokenFees`; fold native-fee checks into `useInsufficientPayTokenBalanceAlert`; remove `useInsufficientPayTokenNativeAlert`; update alert metrics mapping and alert filtering; rename prop to `pendingAmountUsd`. > - **UI**: `BridgeFeeRow` sums provider + source network estimate + target network; tooltip network fee uses estimate. > - **Metrics**: `mm_pay_network_fee_usd` now from `fees.sourceNetwork.estimate.usd`; strategy/quote metrics unchanged. > - **Tokens**: `useTokenWithBalance` now exposes `balanceRaw`. > - **Selectors**: Default `selectTransactionPayTokensByTransactionId` to `[]`. > - **I18n**: Update `insufficient_pay_token_balance_fees.message` copy. > - **Dependencies**: Bump `@metamask/transaction-pay-controller` to `^7.0.0`. > - **Tests**: Update/add tests for new fee fields, alerts, metrics, and token balance raw support. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 7a2c188. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 4a528d0 commit 7648fd7

20 files changed

+389
-357
lines changed

app/components/Views/confirmations/components/rows/bridge-fee-row/bridge-fee-row.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('BridgeFeeRow', () => {
5252
useTransactionTotalsMock.mockReturnValue({
5353
fees: {
5454
provider: { usd: '1.00' },
55-
sourceNetwork: { usd: '0.20' },
55+
sourceNetwork: { estimate: { usd: '0.20' } },
5656
targetNetwork: { usd: '0.03' },
5757
},
5858
} as TransactionPayTotals);

app/components/Views/confirmations/components/rows/bridge-fee-row/bridge-fee-row.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function BridgeFeeRow() {
4040

4141
return formatFiat(
4242
new BigNumber(totals.fees.provider.usd)
43-
.plus(totals.fees.sourceNetwork.usd)
43+
.plus(totals.fees.sourceNetwork.estimate.usd)
4444
.plus(totals.fees.targetNetwork.usd),
4545
);
4646
}, [totals, formatFiat]);
@@ -133,7 +133,7 @@ function FeesTooltip({
133133
const networkFeeUsd = useMemo(
134134
() =>
135135
formatFiat(
136-
new BigNumber(totals.fees.sourceNetwork.usd).plus(
136+
new BigNumber(totals.fees.sourceNetwork.estimate.usd).plus(
137137
totals.fees.targetNetwork.usd,
138138
),
139139
),

app/components/Views/confirmations/constants/alerts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum AlertKeys {
66
InsufficientBalance = 'insufficient_balance',
77
InsufficientPayTokenBalance = 'insufficient_pay_token_balance',
88
InsufficientPayTokenNative = 'insufficient_pay_token_native',
9+
InsufficientPayTokenFees = 'insufficient_pay_token_fees',
910
InsufficientPredictBalance = 'insufficient_predict_balance',
1011
NoPayTokenQuotes = 'no_pay_token_quotes',
1112
PendingTransaction = 'pending_transaction',

app/components/Views/confirmations/hooks/alerts/useConfirmationAlerts.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { useSignedOrSubmittedAlert } from './useSignedOrSubmittedAlert';
1515
import { usePendingTransactionAlert } from './usePendingTransactionAlert';
1616
import { useInsufficientPayTokenBalanceAlert } from './useInsufficientPayTokenBalanceAlert';
1717
import { useNoPayTokenQuotesAlert } from './useNoPayTokenQuotesAlert';
18-
import { useInsufficientPayTokenNativeAlert } from './useInsufficientPayTokenNativeAlert';
1918
import { useInsufficientPredictBalanceAlert } from './useInsufficientPredictBalanceAlert';
2019
import { useBurnAddressAlert } from './useBurnAddressAlert';
2120

@@ -28,7 +27,6 @@ jest.mock('./usePendingTransactionAlert');
2827
jest.mock('./useBatchedUnusedApprovalsAlert');
2928
jest.mock('./useInsufficientPayTokenBalanceAlert');
3029
jest.mock('./useNoPayTokenQuotesAlert');
31-
jest.mock('./useInsufficientPayTokenNativeAlert');
3230
jest.mock('./useInsufficientPredictBalanceAlert');
3331
jest.mock('./useBurnAddressAlert');
3432

@@ -118,15 +116,6 @@ describe('useConfirmationAlerts', () => {
118116
},
119117
];
120118

121-
const mockInsufficientPayTokenNativeAlert: Alert[] = [
122-
{
123-
key: 'InsufficientPayTokenNativeAlert',
124-
title: 'Test Insufficient Pay Token Native Alert',
125-
message: ALERT_MESSAGE_MOCK,
126-
severity: Severity.Danger,
127-
},
128-
];
129-
130119
const mockInsufficientPredictBalanceAlert: Alert[] = [
131120
{
132121
key: 'InsufficientPredictBalanceAlert',
@@ -155,7 +144,6 @@ describe('useConfirmationAlerts', () => {
155144
(useBatchedUnusedApprovalsAlert as jest.Mock).mockReturnValue([]);
156145
(useInsufficientPayTokenBalanceAlert as jest.Mock).mockReturnValue([]);
157146
(useNoPayTokenQuotesAlert as jest.Mock).mockReturnValue([]);
158-
(useInsufficientPayTokenNativeAlert as jest.Mock).mockReturnValue([]);
159147
(useInsufficientPredictBalanceAlert as jest.Mock).mockReturnValue([]);
160148
(useBurnAddressAlert as jest.Mock).mockReturnValue([]);
161149
});
@@ -219,9 +207,6 @@ describe('useConfirmationAlerts', () => {
219207
(useNoPayTokenQuotesAlert as jest.Mock).mockReturnValue(
220208
mockNoPayTokenQuotesAlert,
221209
);
222-
(useInsufficientPayTokenNativeAlert as jest.Mock).mockReturnValue(
223-
mockInsufficientPayTokenNativeAlert,
224-
);
225210
(useInsufficientPredictBalanceAlert as jest.Mock).mockReturnValue(
226211
mockInsufficientPredictBalanceAlert,
227212
);
@@ -238,7 +223,6 @@ describe('useConfirmationAlerts', () => {
238223
...mockSignedOrSubmittedAlert,
239224
...mockInsufficientPayTokenBalanceAlert,
240225
...mockNoPayTokenQuotesAlert,
241-
...mockInsufficientPayTokenNativeAlert,
242226
...mockInsufficientPredictBalanceAlert,
243227
...mockBurnAddressAlert,
244228
...mockUpgradeAccountAlert,

app/components/Views/confirmations/hooks/alerts/useConfirmationAlerts.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Alert } from '../../types/alerts';
99
import { useBatchedUnusedApprovalsAlert } from './useBatchedUnusedApprovalsAlert';
1010
import { useInsufficientPayTokenBalanceAlert } from './useInsufficientPayTokenBalanceAlert';
1111
import { useNoPayTokenQuotesAlert } from './useNoPayTokenQuotesAlert';
12-
import { useInsufficientPayTokenNativeAlert } from './useInsufficientPayTokenNativeAlert';
1312
import { useInsufficientPredictBalanceAlert } from './useInsufficientPredictBalanceAlert';
1413
import { useBurnAddressAlert } from './useBurnAddressAlert';
1514

@@ -27,7 +26,6 @@ function useTransactionAlerts(): Alert[] {
2726
const insufficientPayTokenBalanceAlert =
2827
useInsufficientPayTokenBalanceAlert();
2928
const noPayTokenQuotesAlert = useNoPayTokenQuotesAlert();
30-
const insufficientPayTokenNativeAlert = useInsufficientPayTokenNativeAlert();
3129
const insufficientPredictBalanceAlert = useInsufficientPredictBalanceAlert();
3230
const burnAddressAlert = useBurnAddressAlert();
3331

@@ -39,7 +37,6 @@ function useTransactionAlerts(): Alert[] {
3937
...signedOrSubmittedAlert,
4038
...insufficientPayTokenBalanceAlert,
4139
...noPayTokenQuotesAlert,
42-
...insufficientPayTokenNativeAlert,
4340
...insufficientPredictBalanceAlert,
4441
...burnAddressAlert,
4542
],
@@ -50,7 +47,6 @@ function useTransactionAlerts(): Alert[] {
5047
signedOrSubmittedAlert,
5148
insufficientPayTokenBalanceAlert,
5249
noPayTokenQuotesAlert,
53-
insufficientPayTokenNativeAlert,
5450
insufficientPredictBalanceAlert,
5551
burnAddressAlert,
5652
],

0 commit comments

Comments
 (0)