1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

fix(18574): fix new BigNumber() not a number: undefined for setApprovalForAll method (#18660)

This commit is contained in:
Danica Shen 2023-04-19 19:20:18 +02:00 committed by GitHub
parent ac64cc9e38
commit 1e5f481a51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 11 deletions

View File

@ -261,17 +261,15 @@ export async function getAssetDetails(
// if we can't determine any token standard or details return the data we can extract purely from the parsed transaction data
return { toAddress, tokenId };
}
const tokenValue = getTokenValueParam(tokenData);
const tokenDecimals = tokenDetails?.decimals;
const tokenAmount =
tokenData &&
tokenDetails?.decimals &&
calcTokenAmount(
getTokenValueParam(tokenData),
tokenDetails?.decimals,
).toString(10);
tokenValue &&
tokenDecimals &&
calcTokenAmount(tokenValue, tokenDecimals).toString(10);
const decimals =
tokenDetails?.decimals && Number(tokenDetails.decimals?.toString(10));
const decimals = tokenDecimals && Number(tokenDecimals?.toString(10));
if (tokenDetails?.standard === TokenStandard.ERC20) {
tokenId = undefined;

View File

@ -37,12 +37,16 @@ describe('useAssetDetails', () => {
let getTokenStandardAndDetailsStub;
beforeEach(() => {
getTokenStandardAndDetailsStub = jest
.spyOn(Actions, 'getTokenStandardAndDetails')
.mockImplementation(() => Promise.resolve({}));
getTokenStandardAndDetailsStub = jest.spyOn(
Actions,
'getTokenStandardAndDetails',
);
});
it('should return object with tokenSymbol set to an empty string, when getAssetDetails returns and empty object', async () => {
getTokenStandardAndDetailsStub.mockImplementation(() =>
Promise.resolve({}),
);
const toAddress = '000000000000000000000000000000000000dead';
const tokenAddress = '0x1';
@ -106,6 +110,46 @@ describe('useAssetDetails', () => {
});
});
it('should return object with correct tokenValues for an ERC20 token with no decimals', async () => {
const userAddress = '0xf04a5cc80b1e94c69b48f5ee68a08cd2f09a7c3e';
const tokenAddress = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
const toAddress = '000000000000000000000000000000000000dead';
const transactionData = `0xa9059cbb000000000000000000000000${toAddress}00000000000000000000000000000000000000000000000000000000000001f4`;
const standard = TokenStandard.ERC20;
const symbol = 'WETH';
const balance = '1';
getTokenStandardAndDetailsStub.mockImplementation(() =>
Promise.resolve({
standard,
balance,
symbol,
}),
);
const { result, waitForNextUpdate } = renderUseAssetDetails({
tokenAddress,
userAddress,
transactionData,
});
await waitForNextUpdate();
expect(result.current).toStrictEqual({
assetAddress: tokenAddress,
assetName: undefined,
assetStandard: standard,
toAddress: `0x${toAddress}`,
tokenAmount: undefined,
tokenId: undefined,
tokenImage: undefined,
tokenSymbol: symbol,
userBalance: balance,
decimals: undefined,
});
});
it('should return object with correct tokenValues for an ERC721 token', async () => {
const tokenAddress = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D';
const toAddress = '000000000000000000000000000000000000dead';