Skip to content

Commit bfa15d5

Browse files
fix: Spending cap flicker as decimals are determined
1 parent 98be968 commit bfa15d5

17 files changed

+262
-19
lines changed

test/integration/confirmations/signatures/permit-batch.test.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { act, fireEvent, screen } from '@testing-library/react';
22
import nock from 'nock';
3-
import mockMetaMaskState from '../../data/integration-init-state.json';
4-
import { integrationTestRender } from '../../../lib/render-helpers';
3+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
54
import * as backgroundConnection from '../../../../ui/store/background-connection';
6-
import { createMockImplementation } from '../../helpers';
75
import { tEn } from '../../../lib/i18n-helpers';
6+
import { integrationTestRender } from '../../../lib/render-helpers';
7+
import mockMetaMaskState from '../../data/integration-init-state.json';
8+
import { createMockImplementation } from '../../helpers';
89
import {
910
getMetaMaskStateWithUnapprovedPermitSign,
1011
verifyDetails,
@@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
1516
submitRequestToBackground: jest.fn(),
1617
}));
1718

19+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
20+
...jest.requireActual(
21+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
22+
),
23+
useAssetDetails: jest.fn().mockResolvedValue({
24+
decimals: '4',
25+
}),
26+
}));
27+
1828
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
1929
const backgroundConnectionMocked = {
2030
onNotification: jest.fn(),
2131
};
32+
const mockedAssetDetails = jest.mocked(useAssetDetails);
2233

2334
const renderPermitBatchSignature = async () => {
2435
const account =
@@ -58,6 +69,10 @@ describe('Permit Batch Signature Tests', () => {
5869
getTokenStandardAndDetails: { decimals: '2' },
5970
}),
6071
);
72+
mockedAssetDetails.mockImplementation(() => ({
73+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
74+
decimals: '4' as any,
75+
}));
6176
});
6277

6378
afterEach(() => {

test/integration/confirmations/signatures/permit-seaport.test.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { act, fireEvent, screen } from '@testing-library/react';
22
import nock from 'nock';
3-
import mockMetaMaskState from '../../data/integration-init-state.json';
4-
import { integrationTestRender } from '../../../lib/render-helpers';
3+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
54
import * as backgroundConnection from '../../../../ui/store/background-connection';
6-
import { createMockImplementation } from '../../helpers';
75
import { tEn } from '../../../lib/i18n-helpers';
6+
import { integrationTestRender } from '../../../lib/render-helpers';
7+
import mockMetaMaskState from '../../data/integration-init-state.json';
8+
import { createMockImplementation } from '../../helpers';
89
import {
910
getMetaMaskStateWithUnapprovedPermitSign,
1011
verifyDetails,
@@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
1516
submitRequestToBackground: jest.fn(),
1617
}));
1718

19+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
20+
...jest.requireActual(
21+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
22+
),
23+
useAssetDetails: jest.fn().mockResolvedValue({
24+
decimals: '4',
25+
}),
26+
}));
27+
1828
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
1929
const backgroundConnectionMocked = {
2030
onNotification: jest.fn(),
2131
};
32+
const mockedAssetDetails = jest.mocked(useAssetDetails);
2233

2334
const renderSeaportSignature = async () => {
2435
const account =
@@ -58,6 +69,10 @@ describe('Permit Seaport Tests', () => {
5869
getTokenStandardAndDetails: { decimals: '2' },
5970
}),
6071
);
72+
mockedAssetDetails.mockImplementation(() => ({
73+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
74+
decimals: '4' as any,
75+
}));
6176
});
6277

6378
afterEach(() => {

test/integration/confirmations/signatures/permit-single.test.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { act, fireEvent, screen } from '@testing-library/react';
22
import nock from 'nock';
3-
import mockMetaMaskState from '../../data/integration-init-state.json';
4-
import { integrationTestRender } from '../../../lib/render-helpers';
3+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
54
import * as backgroundConnection from '../../../../ui/store/background-connection';
6-
import { createMockImplementation } from '../../helpers';
75
import { tEn } from '../../../lib/i18n-helpers';
6+
import { integrationTestRender } from '../../../lib/render-helpers';
7+
import mockMetaMaskState from '../../data/integration-init-state.json';
8+
import { createMockImplementation } from '../../helpers';
89
import {
910
getMetaMaskStateWithUnapprovedPermitSign,
1011
verifyDetails,
@@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
1516
submitRequestToBackground: jest.fn(),
1617
}));
1718

19+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
20+
...jest.requireActual(
21+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
22+
),
23+
useAssetDetails: jest.fn().mockResolvedValue({
24+
decimals: '4',
25+
}),
26+
}));
27+
1828
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
1929
const backgroundConnectionMocked = {
2030
onNotification: jest.fn(),
2131
};
32+
const mockedAssetDetails = jest.mocked(useAssetDetails);
2233

2334
const renderSingleBatchSignature = async () => {
2435
const account =
@@ -58,6 +69,10 @@ describe('Permit Single Signature Tests', () => {
5869
getTokenStandardAndDetails: { decimals: '2' },
5970
}),
6071
);
72+
mockedAssetDetails.mockImplementation(() => ({
73+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
74+
decimals: '4' as any,
75+
}));
6176
});
6277

6378
afterEach(() => {

test/integration/confirmations/signatures/permit-tradeOrder.test.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { act, screen } from '@testing-library/react';
22
import nock from 'nock';
3-
import mockMetaMaskState from '../../data/integration-init-state.json';
4-
import { integrationTestRender } from '../../../lib/render-helpers';
3+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
54
import * as backgroundConnection from '../../../../ui/store/background-connection';
6-
import { createMockImplementation } from '../../helpers';
75
import { tEn } from '../../../lib/i18n-helpers';
6+
import { integrationTestRender } from '../../../lib/render-helpers';
7+
import mockMetaMaskState from '../../data/integration-init-state.json';
8+
import { createMockImplementation } from '../../helpers';
89
import {
910
getMetaMaskStateWithUnapprovedPermitSign,
1011
verifyDetails,
@@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
1516
submitRequestToBackground: jest.fn(),
1617
}));
1718

19+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
20+
...jest.requireActual(
21+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
22+
),
23+
useAssetDetails: jest.fn().mockResolvedValue({
24+
decimals: '4',
25+
}),
26+
}));
27+
1828
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
1929
const backgroundConnectionMocked = {
2030
onNotification: jest.fn(),
2131
};
32+
const mockedAssetDetails = jest.mocked(useAssetDetails);
2233

2334
const renderTradeOrderSignature = async () => {
2435
const account =
@@ -58,6 +69,10 @@ describe('Permit Trade Order Tests', () => {
5869
getTokenStandardAndDetails: { decimals: '2' },
5970
}),
6071
);
72+
mockedAssetDetails.mockImplementation(() => ({
73+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
74+
decimals: '4' as any,
75+
}));
6176
});
6277

6378
afterEach(() => {

test/integration/confirmations/signatures/permit.test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
MetaMetricsEventName,
88
} from '../../../../shared/constants/metametrics';
99
import { shortenAddress } from '../../../../ui/helpers/utils/util';
10+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
1011
import * as backgroundConnection from '../../../../ui/store/background-connection';
1112
import { integrationTestRender } from '../../../lib/render-helpers';
1213
import mockMetaMaskState from '../../data/integration-init-state.json';
@@ -18,10 +19,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
1819
submitRequestToBackground: jest.fn(),
1920
}));
2021

22+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
23+
...jest.requireActual(
24+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
25+
),
26+
useAssetDetails: jest.fn().mockResolvedValue({
27+
decimals: '4',
28+
}),
29+
}));
30+
2131
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
2232
const backgroundConnectionMocked = {
2333
onNotification: jest.fn(),
2434
};
35+
const mockedAssetDetails = jest.mocked(useAssetDetails);
2536

2637
describe('Permit Confirmation', () => {
2738
beforeEach(() => {
@@ -31,6 +42,10 @@ describe('Permit Confirmation', () => {
3142
getTokenStandardAndDetails: { decimals: '2', standard: 'ERC20' },
3243
}),
3344
);
45+
mockedAssetDetails.mockImplementation(() => ({
46+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
47+
decimals: '4' as any,
48+
}));
3449
});
3550

3651
afterEach(() => {

test/integration/confirmations/signatures/personalSign.test.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { ApprovalType } from '@metamask/controller-utils';
2-
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
32
import { CHAIN_IDS } from '@metamask/transaction-controller';
3+
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
44
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
55
import {
66
MetaMetricsEventCategory,
77
MetaMetricsEventLocation,
88
MetaMetricsEventName,
99
} from '../../../../shared/constants/metametrics';
1010
import { shortenAddress } from '../../../../ui/helpers/utils/util';
11+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
1112
import * as backgroundConnection from '../../../../ui/store/background-connection';
1213
import { integrationTestRender } from '../../../lib/render-helpers';
1314
import mockMetaMaskState from '../../data/integration-init-state.json';
@@ -17,7 +18,17 @@ jest.mock('../../../../ui/store/background-connection', () => ({
1718
submitRequestToBackground: jest.fn(),
1819
}));
1920

21+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
22+
...jest.requireActual(
23+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
24+
),
25+
useAssetDetails: jest.fn().mockResolvedValue({
26+
decimals: '4',
27+
}),
28+
}));
29+
2030
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
31+
const mockedAssetDetails = jest.mocked(useAssetDetails);
2132

2233
const backgroundConnectionMocked = {
2334
onNotification: jest.fn(),
@@ -68,6 +79,10 @@ const getMetaMaskStateWithUnapprovedPersonalSign = (accountAddress: string) => {
6879
describe('PersonalSign Confirmation', () => {
6980
beforeEach(() => {
7081
jest.resetAllMocks();
82+
mockedAssetDetails.mockImplementation(() => ({
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
84+
decimals: '4' as any,
85+
}));
7186
});
7287

7388
it('displays the header account modal with correct data', async () => {

test/integration/confirmations/transactions/alerts.test.tsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { randomUUID } from 'crypto';
2-
import { act, fireEvent, screen } from '@testing-library/react';
32
import { ApprovalType } from '@metamask/controller-utils';
3+
import { act, fireEvent, screen } from '@testing-library/react';
44
import nock from 'nock';
5-
import mockMetaMaskState from '../../data/integration-init-state.json';
6-
import { integrationTestRender } from '../../../lib/render-helpers';
5+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
76
import * as backgroundConnection from '../../../../ui/store/background-connection';
8-
import { createMockImplementation, mock4byte } from '../../helpers';
7+
import { integrationTestRender } from '../../../lib/render-helpers';
98
import { createTestProviderTools } from '../../../stub/provider';
9+
import mockMetaMaskState from '../../data/integration-init-state.json';
10+
import { createMockImplementation, mock4byte } from '../../helpers';
1011
import { getUnapprovedApproveTransaction } from './transactionDataHelpers';
1112

1213
jest.mock('../../../../ui/store/background-connection', () => ({
@@ -15,7 +16,17 @@ jest.mock('../../../../ui/store/background-connection', () => ({
1516
callBackgroundMethod: jest.fn(),
1617
}));
1718

19+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
20+
...jest.requireActual(
21+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
22+
),
23+
useAssetDetails: jest.fn().mockResolvedValue({
24+
decimals: '4',
25+
}),
26+
}));
27+
1828
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
29+
const mockedAssetDetails = jest.mocked(useAssetDetails);
1930

2031
const backgroundConnectionMocked = {
2132
onNotification: jest.fn(),
@@ -92,6 +103,10 @@ describe('Contract Interaction Confirmation Alerts', () => {
92103
setupSubmitRequestToBackgroundMocks();
93104
const APPROVE_NFT_HEX_SIG = '0x095ea7b3';
94105
mock4byte(APPROVE_NFT_HEX_SIG);
106+
mockedAssetDetails.mockImplementation(() => ({
107+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
108+
decimals: '4' as any,
109+
}));
95110
});
96111

97112
afterEach(() => {

test/integration/confirmations/transactions/contract-deployment.test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
MetaMetricsEventLocation,
1414
MetaMetricsEventName,
1515
} from '../../../../shared/constants/metametrics';
16+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
1617
import * as backgroundConnection from '../../../../ui/store/background-connection';
1718
import { tEn } from '../../../lib/i18n-helpers';
1819
import { integrationTestRender } from '../../../lib/render-helpers';
@@ -26,7 +27,17 @@ jest.mock('../../../../ui/store/background-connection', () => ({
2627
callBackgroundMethod: jest.fn(),
2728
}));
2829

30+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
31+
...jest.requireActual(
32+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
33+
),
34+
useAssetDetails: jest.fn().mockResolvedValue({
35+
decimals: '4',
36+
}),
37+
}));
38+
2939
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
40+
const mockedAssetDetails = jest.mocked(useAssetDetails);
3041

3142
const backgroundConnectionMocked = {
3243
onNotification: jest.fn(),
@@ -136,6 +147,10 @@ describe('Contract Deployment Confirmation', () => {
136147
setupSubmitRequestToBackgroundMocks();
137148
const DEPOSIT_HEX_SIG = '0xd0e30db0';
138149
mock4byte(DEPOSIT_HEX_SIG);
150+
mockedAssetDetails.mockImplementation(() => ({
151+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
152+
decimals: '4' as any,
153+
}));
139154
});
140155

141156
afterEach(() => {

test/integration/confirmations/transactions/contract-interaction.test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
MetaMetricsEventLocation,
1414
MetaMetricsEventName,
1515
} from '../../../../shared/constants/metametrics';
16+
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
1617
import * as backgroundConnection from '../../../../ui/store/background-connection';
1718
import { tEn } from '../../../lib/i18n-helpers';
1819
import { integrationTestRender } from '../../../lib/render-helpers';
@@ -31,7 +32,17 @@ jest.mock('../../../../ui/store/background-connection', () => ({
3132
callBackgroundMethod: jest.fn(),
3233
}));
3334

35+
jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
36+
...jest.requireActual(
37+
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
38+
),
39+
useAssetDetails: jest.fn().mockResolvedValue({
40+
decimals: '4',
41+
}),
42+
}));
43+
3444
const mockedBackgroundConnection = jest.mocked(backgroundConnection);
45+
const mockedAssetDetails = jest.mocked(useAssetDetails);
3546

3647
const backgroundConnectionMocked = {
3748
onNotification: jest.fn(),
@@ -156,6 +167,10 @@ describe('Contract Interaction Confirmation', () => {
156167
setupSubmitRequestToBackgroundMocks();
157168
const MINT_NFT_HEX_SIG = '0x3b4b1381';
158169
mock4byte(MINT_NFT_HEX_SIG);
170+
mockedAssetDetails.mockImplementation(() => ({
171+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
172+
decimals: '4' as any,
173+
}));
159174
});
160175

161176
afterEach(() => {

0 commit comments

Comments
 (0)