Skip to content

fix: Spending cap flicker as decimals are determined #29206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions test/integration/confirmations/signatures/permit-batch.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { act, fireEvent, screen } from '@testing-library/react';
import nock from 'nock';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { integrationTestRender } from '../../../lib/render-helpers';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { createMockImplementation } from '../../helpers';
import { tEn } from '../../../lib/i18n-helpers';
import { integrationTestRender } from '../../../lib/render-helpers';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { createMockImplementation } from '../../helpers';
import {
getMetaMaskStateWithUnapprovedPermitSign,
verifyDetails,
Expand All @@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
submitRequestToBackground: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const backgroundConnectionMocked = {
onNotification: jest.fn(),
};
const mockedAssetDetails = jest.mocked(useAssetDetails);

const renderPermitBatchSignature = async () => {
const account =
Expand Down Expand Up @@ -58,6 +69,10 @@ describe('Permit Batch Signature Tests', () => {
getTokenStandardAndDetails: { decimals: '2' },
}),
);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
21 changes: 18 additions & 3 deletions test/integration/confirmations/signatures/permit-seaport.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { act, fireEvent, screen } from '@testing-library/react';
import nock from 'nock';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { integrationTestRender } from '../../../lib/render-helpers';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { createMockImplementation } from '../../helpers';
import { tEn } from '../../../lib/i18n-helpers';
import { integrationTestRender } from '../../../lib/render-helpers';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { createMockImplementation } from '../../helpers';
import {
getMetaMaskStateWithUnapprovedPermitSign,
verifyDetails,
Expand All @@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
submitRequestToBackground: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const backgroundConnectionMocked = {
onNotification: jest.fn(),
};
const mockedAssetDetails = jest.mocked(useAssetDetails);

const renderSeaportSignature = async () => {
const account =
Expand Down Expand Up @@ -58,6 +69,10 @@ describe('Permit Seaport Tests', () => {
getTokenStandardAndDetails: { decimals: '2' },
}),
);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
21 changes: 18 additions & 3 deletions test/integration/confirmations/signatures/permit-single.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { act, fireEvent, screen } from '@testing-library/react';
import nock from 'nock';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { integrationTestRender } from '../../../lib/render-helpers';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { createMockImplementation } from '../../helpers';
import { tEn } from '../../../lib/i18n-helpers';
import { integrationTestRender } from '../../../lib/render-helpers';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { createMockImplementation } from '../../helpers';
import {
getMetaMaskStateWithUnapprovedPermitSign,
verifyDetails,
Expand All @@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
submitRequestToBackground: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const backgroundConnectionMocked = {
onNotification: jest.fn(),
};
const mockedAssetDetails = jest.mocked(useAssetDetails);

const renderSingleBatchSignature = async () => {
const account =
Expand Down Expand Up @@ -58,6 +69,10 @@ describe('Permit Single Signature Tests', () => {
getTokenStandardAndDetails: { decimals: '2' },
}),
);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { act, screen } from '@testing-library/react';
import nock from 'nock';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { integrationTestRender } from '../../../lib/render-helpers';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { createMockImplementation } from '../../helpers';
import { tEn } from '../../../lib/i18n-helpers';
import { integrationTestRender } from '../../../lib/render-helpers';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { createMockImplementation } from '../../helpers';
import {
getMetaMaskStateWithUnapprovedPermitSign,
verifyDetails,
Expand All @@ -15,10 +16,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
submitRequestToBackground: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const backgroundConnectionMocked = {
onNotification: jest.fn(),
};
const mockedAssetDetails = jest.mocked(useAssetDetails);

const renderTradeOrderSignature = async () => {
const account =
Expand Down Expand Up @@ -58,6 +69,10 @@ describe('Permit Trade Order Tests', () => {
getTokenStandardAndDetails: { decimals: '2' },
}),
);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
15 changes: 15 additions & 0 deletions test/integration/confirmations/signatures/permit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { shortenAddress } from '../../../../ui/helpers/utils/util';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { integrationTestRender } from '../../../lib/render-helpers';
import mockMetaMaskState from '../../data/integration-init-state.json';
Expand All @@ -18,10 +19,20 @@ jest.mock('../../../../ui/store/background-connection', () => ({
submitRequestToBackground: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const backgroundConnectionMocked = {
onNotification: jest.fn(),
};
const mockedAssetDetails = jest.mocked(useAssetDetails);

describe('Permit Confirmation', () => {
beforeEach(() => {
Expand All @@ -31,6 +42,10 @@ describe('Permit Confirmation', () => {
getTokenStandardAndDetails: { decimals: '2', standard: 'ERC20' },
}),
);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
17 changes: 16 additions & 1 deletion test/integration/confirmations/signatures/personalSign.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ApprovalType } from '@metamask/controller-utils';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import { CHAIN_IDS } from '@metamask/transaction-controller';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
import {
MetaMetricsEventCategory,
MetaMetricsEventLocation,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { shortenAddress } from '../../../../ui/helpers/utils/util';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { integrationTestRender } from '../../../lib/render-helpers';
import mockMetaMaskState from '../../data/integration-init-state.json';
Expand All @@ -17,7 +18,17 @@ jest.mock('../../../../ui/store/background-connection', () => ({
submitRequestToBackground: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const mockedAssetDetails = jest.mocked(useAssetDetails);

const backgroundConnectionMocked = {
onNotification: jest.fn(),
Expand Down Expand Up @@ -68,6 +79,10 @@ const getMetaMaskStateWithUnapprovedPersonalSign = (accountAddress: string) => {
describe('PersonalSign Confirmation', () => {
beforeEach(() => {
jest.resetAllMocks();
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

it('displays the header account modal with correct data', async () => {
Expand Down
23 changes: 19 additions & 4 deletions test/integration/confirmations/transactions/alerts.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { randomUUID } from 'crypto';
import { act, fireEvent, screen } from '@testing-library/react';
import { ApprovalType } from '@metamask/controller-utils';
import { act, fireEvent, screen } from '@testing-library/react';
import nock from 'nock';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { integrationTestRender } from '../../../lib/render-helpers';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { createMockImplementation, mock4byte } from '../../helpers';
import { integrationTestRender } from '../../../lib/render-helpers';
import { createTestProviderTools } from '../../../stub/provider';
import mockMetaMaskState from '../../data/integration-init-state.json';
import { createMockImplementation, mock4byte } from '../../helpers';
import { getUnapprovedApproveTransaction } from './transactionDataHelpers';

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

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const mockedAssetDetails = jest.mocked(useAssetDetails);

const backgroundConnectionMocked = {
onNotification: jest.fn(),
Expand Down Expand Up @@ -92,6 +103,10 @@ describe('Contract Interaction Confirmation Alerts', () => {
setupSubmitRequestToBackgroundMocks();
const APPROVE_NFT_HEX_SIG = '0x095ea7b3';
mock4byte(APPROVE_NFT_HEX_SIG);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
MetaMetricsEventLocation,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { tEn } from '../../../lib/i18n-helpers';
import { integrationTestRender } from '../../../lib/render-helpers';
Expand All @@ -26,7 +27,17 @@ jest.mock('../../../../ui/store/background-connection', () => ({
callBackgroundMethod: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const mockedAssetDetails = jest.mocked(useAssetDetails);

const backgroundConnectionMocked = {
onNotification: jest.fn(),
Expand Down Expand Up @@ -136,6 +147,10 @@ describe('Contract Deployment Confirmation', () => {
setupSubmitRequestToBackgroundMocks();
const DEPOSIT_HEX_SIG = '0xd0e30db0';
mock4byte(DEPOSIT_HEX_SIG);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
MetaMetricsEventLocation,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { useAssetDetails } from '../../../../ui/pages/confirmations/hooks/useAssetDetails';
import * as backgroundConnection from '../../../../ui/store/background-connection';
import { tEn } from '../../../lib/i18n-helpers';
import { integrationTestRender } from '../../../lib/render-helpers';
Expand All @@ -31,7 +32,17 @@ jest.mock('../../../../ui/store/background-connection', () => ({
callBackgroundMethod: jest.fn(),
}));

jest.mock('../../../../ui/pages/confirmations/hooks/useAssetDetails', () => ({
...jest.requireActual(
'../../../../ui/pages/confirmations/hooks/useAssetDetails',
),
useAssetDetails: jest.fn().mockResolvedValue({
decimals: '4',
}),
}));

const mockedBackgroundConnection = jest.mocked(backgroundConnection);
const mockedAssetDetails = jest.mocked(useAssetDetails);

const backgroundConnectionMocked = {
onNotification: jest.fn(),
Expand Down Expand Up @@ -156,6 +167,10 @@ describe('Contract Interaction Confirmation', () => {
setupSubmitRequestToBackgroundMocks();
const MINT_NFT_HEX_SIG = '0x3b4b1381';
mock4byte(MINT_NFT_HEX_SIG);
mockedAssetDetails.mockImplementation(() => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
decimals: '4' as any,
}));
});

afterEach(() => {
Expand Down
Loading
Loading