Skip to content

Commit 4df801b

Browse files
Add MM Pay provider fallback and Across routing support
1 parent 4a4f0ae commit 4df801b

38 files changed

Lines changed: 1495 additions & 129 deletions

app/components/UI/Perps/components/PerpsProgressBar/PerpsProgressBar.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,32 @@ describe('PerpsProgressBar', () => {
876876
);
877877
});
878878

879+
it('resumes progress from persisted state for the same withdrawal', () => {
880+
const mockPersistentProgress = {
881+
progress: 99,
882+
lastUpdated: Date.now(),
883+
activeWithdrawalId: 'withdrawal1',
884+
};
885+
886+
mockUsePerpsSelector.mockReturnValue(mockPersistentProgress);
887+
mockUseWithdrawalRequests.mockReturnValue({
888+
withdrawalRequests: [mockWithdrawalRequests[0]],
889+
isLoading: false,
890+
error: null,
891+
refetch: jest.fn(),
892+
});
893+
894+
const { getByTestId } = renderWithProvider(
895+
<PerpsProgressBar {...defaultProps} />,
896+
);
897+
898+
expect(getByTestId('perps-progress-bar')).toBeTruthy();
899+
expect(mockController.updateWithdrawalProgress).not.toHaveBeenCalledWith(
900+
25,
901+
'withdrawal1',
902+
);
903+
});
904+
879905
it('handles withdrawal without ID gracefully', () => {
880906
const withdrawalWithoutId = {
881907
...mockWithdrawalRequests[0],

app/components/UI/Perps/components/PerpsProgressBar/PerpsProgressBar.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { usePerpsSelector } from '../../hooks/usePerpsSelector';
1515
import {
1616
TransactionMeta,
1717
TransactionStatus,
18-
TransactionType,
1918
} from '@metamask/transaction-controller';
2019
import Engine from '../../../../../core/Engine';
2120
import DevLogger from '../../../../../core/SDKConnect/utils/DevLogger';
@@ -25,6 +24,7 @@ import {
2524
PROGRESS_BAR_COMPLETION_DELAY_MS,
2625
} from '@metamask/perps-controller';
2726
import { HYPERLIQUID_WITHDRAWAL_PROGRESS_INTERVAL_MS } from '../../constants/perpsUIConfig';
27+
import { hasPerpsDepositTransactionType } from '../../../../../util/transactions/metamask-pay';
2828

2929
interface PerpsProgressBarProps {
3030
/**
@@ -178,10 +178,7 @@ export const PerpsProgressBar: React.FC<PerpsProgressBarProps> = ({
178178
}: {
179179
transactionMeta: TransactionMeta;
180180
}) => {
181-
if (
182-
transactionMeta.type === TransactionType.perpsDeposit ||
183-
transactionMeta.type === TransactionType.perpsDepositAndOrder
184-
) {
181+
if (hasPerpsDepositTransactionType(transactionMeta)) {
185182
const progress = getProgressFromStatus(transactionMeta.status);
186183
setTransactionProgress(progress);
187184

app/components/UI/Perps/hooks/usePerpsDepositProgress.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
TransactionMeta,
33
TransactionStatus,
4-
TransactionType,
54
} from '@metamask/transaction-controller';
65
import { useEffect, useRef, useState } from 'react';
76
import Engine from '../../../../core/Engine';
87
import { usePerpsLiveAccount } from './stream/usePerpsLiveAccount';
8+
import { hasPerpsDepositTransactionType } from '../../../../util/transactions/metamask-pay';
99

1010
/**
1111
* Hook to track deposit progress state for UI components
@@ -36,10 +36,7 @@ export const usePerpsDepositProgress = () => {
3636
}: {
3737
transactionMeta: TransactionMeta;
3838
}) => {
39-
if (
40-
transactionMeta.type !== TransactionType.perpsDepositAndOrder &&
41-
transactionMeta.type !== TransactionType.perpsDeposit
42-
) {
39+
if (!hasPerpsDepositTransactionType(transactionMeta)) {
4340
return;
4441
}
4542

app/components/UI/Perps/hooks/usePerpsTransactionHistory.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
import { useSelector } from 'react-redux';
33
import usePrevious from '../../../hooks/usePrevious';
44
import { BigNumber } from 'bignumber.js';
5-
import { TransactionType } from '@metamask/transaction-controller';
65
import Engine from '../../../../core/Engine';
76
import DevLogger from '../../../../core/SDKConnect/utils/DevLogger';
87
import type { CaipAccountId } from '@metamask/utils';
@@ -19,6 +18,7 @@ import {
1918
transformUserHistoryToTransactions,
2019
transformWalletPerpsDepositsToTransactions,
2120
} from '../utils/transactionTransforms';
21+
import { hasPerpsDepositTransactionType } from '../../../../util/transactions/metamask-pay';
2222

2323
interface UsePerpsTransactionHistoryParams {
2424
startTime?: number;
@@ -71,8 +71,7 @@ export const usePerpsTransactionHistory = ({
7171
(tx) =>
7272
selectedAddress &&
7373
areAddressesEqual(tx.txParams?.from ?? '', selectedAddress) &&
74-
(tx.type === TransactionType.perpsDeposit ||
75-
tx.type === TransactionType.perpsDepositAndOrder),
74+
hasPerpsDepositTransactionType(tx),
7675
);
7776
return transformWalletPerpsDepositsToTransactions(filtered);
7877
}, [walletTransactions, selectedAddress]);

app/components/UI/Perps/utils/transactionTransforms.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import {
2020
} from '../types/transactionHistory';
2121

2222
jest.mock('../../../Views/confirmations/utils/transaction-pay');
23-
jest.mock('../../../Views/confirmations/utils/transaction');
23+
jest.mock('../../../Views/confirmations/utils/transaction', () => ({
24+
...jest.requireActual('../../../Views/confirmations/utils/transaction'),
25+
parseStandardTokenTransactionData: jest.fn(),
26+
}));
2427
jest.mock('../../../../util/transactions', () => ({
2528
...jest.requireActual('../../../../util/transactions'),
2629
calcTokenAmount: jest.fn((value: string) => (Number(value) / 1e6).toString()),
@@ -1913,5 +1916,18 @@ describe('transactionTransforms', () => {
19131916
expect(result[0].title).toBe('Deposit');
19141917
expect(result[0].depositWithdrawal?.amountNumber).toBe(0);
19151918
});
1919+
1920+
it('uses Deposit title and zero amount when parsed token data is missing a value', () => {
1921+
mockParseStandardTokenTransactionData.mockReturnValue({
1922+
args: {},
1923+
} as never);
1924+
1925+
const result = transformWalletPerpsDepositsToTransactions([
1926+
createMockTx(),
1927+
] as never);
1928+
1929+
expect(result[0].title).toBe('Deposit');
1930+
expect(result[0].depositWithdrawal?.amountNumber).toBe(0);
1931+
});
19161932
});
19171933
});

app/components/UI/Perps/utils/transactionTransforms.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { getTokenTransferData } from '../../../Views/confirmations/utils/transac
2222
import { parseStandardTokenTransactionData } from '../../../Views/confirmations/utils/transaction';
2323
import { calcTokenAmount } from '../../../../util/transactions';
2424
import { ARBITRUM_USDC } from '../../../Views/confirmations/constants/perps';
25+
import { hasPerpsDepositTransactionType } from '../../../../util/transactions/metamask-pay';
2526

2627
/**
2728
* Determines the close direction category for aggregation purposes.
@@ -627,11 +628,7 @@ export function transformWalletPerpsDepositsToTransactions(
627628
transactions: TransactionMeta[],
628629
): PerpsTransaction[] {
629630
return transactions
630-
.filter(
631-
(tx) =>
632-
tx.type === TransactionType.perpsDeposit ||
633-
tx.type === TransactionType.perpsDepositAndOrder,
634-
)
631+
.filter((tx) => hasPerpsDepositTransactionType(tx))
635632
.map((tx) => {
636633
const tokenData = getTokenTransferData(tx);
637634
const decoded = tokenData?.data

app/components/UI/TransactionElement/index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
getMonetizedPrimitive,
6767
} from '../../../core/Analytics/events/transactions';
6868
import { getTransactionTypeValue } from '../../../core/Engine/controllers/transaction-controller/metrics_properties/base';
69+
import { MM_PAY_DETAIL_TRANSACTION_TYPES } from '../../../util/transactions/metamask-pay';
6970

7071
const createStyles = (colors, typography) =>
7172
StyleSheet.create({
@@ -149,15 +150,7 @@ const transactionIconReceivedFailed = require('../../../images/transaction-icons
149150
const transactionIconSwapFailed = require('../../../images/transaction-icons/swap-failed.png');
150151
/* eslint-enable import-x/no-commonjs */
151152

152-
const NEW_TRANSACTION_DETAILS_TYPES = [
153-
TransactionType.musdClaim,
154-
TransactionType.musdConversion,
155-
TransactionType.perpsDeposit,
156-
TransactionType.perpsDepositAndOrder,
157-
TransactionType.predictClaim,
158-
TransactionType.predictDeposit,
159-
TransactionType.predictWithdraw,
160-
];
153+
const NEW_TRANSACTION_DETAILS_TYPES = [...MM_PAY_DETAIL_TRANSACTION_TYPES];
161154

162155
const INTENT_STATUS = {
163156
SUBMITTED: 'SUBMITTED',

app/components/UI/TransactionElement/utils.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ import {
4747
import { selectSingleTokenByAddressAndChainId } from '../../../selectors/tokensController';
4848
import { selectTickerByChainId } from '../../../selectors/networkController';
4949
import { selectContractExchangeRatesByChainId } from '../../../selectors/tokenRatesController';
50+
import { MM_PAY_POSITIVE_TRANSFER_TRANSACTION_TYPES } from '../../../util/transactions/metamask-pay';
5051

51-
const POSITIVE_TRANSFER_TRANSACTION_TYPES = [
52-
TransactionType.musdConversion,
53-
TransactionType.perpsDeposit,
54-
TransactionType.perpsDepositAndOrder,
55-
TransactionType.predictDeposit,
56-
TransactionType.predictWithdraw,
57-
];
52+
const POSITIVE_TRANSFER_TRANSACTION_TYPES =
53+
MM_PAY_POSITIVE_TRANSFER_TRANSACTION_TYPES;
5854

5955
function getTokenTransfer(args) {
6056
const {

app/components/UI/TransactionElement/utils.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ describe('Transaction Element Utils', () => {
381381
TransactionType.predictDeposit,
382382
strings('transactions.tx_review_predict_deposit'),
383383
],
384+
[
385+
TransactionType.predictAcrossDeposit,
386+
strings('transactions.tx_review_predict_deposit'),
387+
],
384388
[
385389
TransactionType.predictWithdraw,
386390
strings('transactions.tx_review_predict_withdraw'),
@@ -389,6 +393,10 @@ describe('Transaction Element Utils', () => {
389393
TransactionType.musdConversion,
390394
strings('transactions.tx_review_musd_conversion'),
391395
],
396+
[
397+
TransactionType.perpsAcrossDeposit,
398+
strings('transactions.tx_review_perps_deposit'),
399+
],
392400
])('if %s', async (transactionType, title) => {
393401
const args = {
394402
tx: {

app/components/Views/confirmations/components/activity/transaction-details-hero/transaction-details-hero.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ describe('TransactionDetailsHero', () => {
204204
expect(getByText('$75.50')).toBeDefined();
205205
});
206206

207+
it('renders amount for perpsDepositAndOrder transactions', () => {
208+
useTransactionDetailsMock.mockReturnValue({
209+
transactionMeta: {
210+
...TRANSACTION_META_MOCK,
211+
type: TransactionType.perpsDepositAndOrder,
212+
} as unknown as TransactionMeta,
213+
});
214+
215+
const { getByText } = render();
216+
217+
expect(getByText('$123.46')).toBeDefined();
218+
});
219+
220+
it('renders nothing for predictClaim transactions', () => {
221+
useTransactionDetailsMock.mockReturnValue({
222+
transactionMeta: {
223+
...TRANSACTION_META_MOCK,
224+
type: TransactionType.predictClaim,
225+
} as unknown as TransactionMeta,
226+
});
227+
228+
const { queryByTestId } = render();
229+
230+
expect(queryByTestId('transaction-details-hero')).toBeNull();
231+
});
232+
207233
it('renders nothing for musdClaim without valid claim data', () => {
208234
useTransactionDetailsMock.mockReturnValue({
209235
transactionMeta: {

0 commit comments

Comments
 (0)