Skip to content

fix: cp-12.18.0 Infinite loader on approve request #32548

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 4 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ import {
} from '../../../../../../../../test/data/confirmations/contract-interaction';
import mockState from '../../../../../../../../test/data/mock-state.json';
import { renderHookWithProvider } from '../../../../../../../../test/lib/render-helpers';
import { getTokenStandardAndDetails } from '../../../../../../../store/actions';
import { getTokenStandardAndDetailsByChain } from '../../../../../../../store/actions';
import { useIsNFT } from './use-is-nft';

jest.mock('../../../../../../../store/actions', () => ({
...jest.requireActual('../../../../../../../store/actions'),
getTokenStandardAndDetails: jest.fn(),
getTokenStandardAndDetailsByChain: jest.fn(),
}));

describe('useIsNFT', () => {
it('identifies NFT in token with 0 decimals', async () => {
const getTokenStandardAndDetailsMock = jest
.fn()
.mockImplementation(() => ({ standard: TokenStandard.ERC721 }));
const mockGetTokenStandardAndDetailsByChain = jest.mocked(
getTokenStandardAndDetailsByChain,
);

(getTokenStandardAndDetails as jest.Mock).mockImplementation(
getTokenStandardAndDetailsMock,
beforeEach(() => {
jest.clearAllMocks();
mockGetTokenStandardAndDetailsByChain.mockImplementation(() =>
Promise.resolve({
standard: TokenStandard.ERC721,
}),
);
});

it('identifies NFT in token with 0 decimals', async () => {
const transactionMeta = genUnapprovedContractInteractionConfirmation({
address: CONTRACT_INTERACTION_SENDER_ADDRESS,
}) as TransactionMeta;
Expand All @@ -36,15 +41,19 @@ describe('useIsNFT', () => {
await waitForNextUpdate();

expect(result.current.isNFT).toMatchInlineSnapshot(`true`);
expect(mockGetTokenStandardAndDetailsByChain).toHaveBeenCalledWith(
transactionMeta.txParams.to,
transactionMeta.txParams.from,
undefined,
transactionMeta.chainId,
);
});

it('identifies fungible in token with greater than 0 decimals', async () => {
const getTokenStandardAndDetailsMock = jest
.fn()
.mockImplementation(() => ({ standard: TokenStandard.ERC20 }));

(getTokenStandardAndDetails as jest.Mock).mockImplementation(
getTokenStandardAndDetailsMock,
mockGetTokenStandardAndDetailsByChain.mockImplementation(() =>
Promise.resolve({
standard: TokenStandard.ERC20,
}),
);

const transactionMeta = genUnapprovedContractInteractionConfirmation({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import { TokenStandard } from '../../../../../../../../shared/constants/transaction';
import { useAsyncResult } from '../../../../../../../hooks/useAsync';
import { getTokenStandardAndDetails } from '../../../../../../../store/actions';
import { getTokenStandardAndDetailsByChain } from '../../../../../../../store/actions';

export const useIsNFT = (
transactionMeta: TransactionMeta,
): { isNFT: boolean; pending: boolean } => {
const { value, pending } = useAsyncResult(async () => {
return await getTokenStandardAndDetails(
return await getTokenStandardAndDetailsByChain(
transactionMeta?.txParams?.to as string,
transactionMeta?.txParams?.from as string,
undefined,
transactionMeta?.chainId as string,
);
}, [transactionMeta?.txParams?.to]);

Expand Down
Loading