mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
fix(18574): fix new BigNumber() not a number: undefined for setApprovalForAll method (#18660)
This commit is contained in:
parent
ac64cc9e38
commit
1e5f481a51
@ -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
|
// 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 };
|
return { toAddress, tokenId };
|
||||||
}
|
}
|
||||||
|
const tokenValue = getTokenValueParam(tokenData);
|
||||||
|
const tokenDecimals = tokenDetails?.decimals;
|
||||||
const tokenAmount =
|
const tokenAmount =
|
||||||
tokenData &&
|
tokenData &&
|
||||||
tokenDetails?.decimals &&
|
tokenValue &&
|
||||||
calcTokenAmount(
|
tokenDecimals &&
|
||||||
getTokenValueParam(tokenData),
|
calcTokenAmount(tokenValue, tokenDecimals).toString(10);
|
||||||
tokenDetails?.decimals,
|
|
||||||
).toString(10);
|
|
||||||
|
|
||||||
const decimals =
|
const decimals = tokenDecimals && Number(tokenDecimals?.toString(10));
|
||||||
tokenDetails?.decimals && Number(tokenDetails.decimals?.toString(10));
|
|
||||||
|
|
||||||
if (tokenDetails?.standard === TokenStandard.ERC20) {
|
if (tokenDetails?.standard === TokenStandard.ERC20) {
|
||||||
tokenId = undefined;
|
tokenId = undefined;
|
||||||
|
@ -37,12 +37,16 @@ describe('useAssetDetails', () => {
|
|||||||
let getTokenStandardAndDetailsStub;
|
let getTokenStandardAndDetailsStub;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
getTokenStandardAndDetailsStub = jest
|
getTokenStandardAndDetailsStub = jest.spyOn(
|
||||||
.spyOn(Actions, 'getTokenStandardAndDetails')
|
Actions,
|
||||||
.mockImplementation(() => Promise.resolve({}));
|
'getTokenStandardAndDetails',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return object with tokenSymbol set to an empty string, when getAssetDetails returns and empty object', async () => {
|
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 toAddress = '000000000000000000000000000000000000dead';
|
||||||
const tokenAddress = '0x1';
|
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 () => {
|
it('should return object with correct tokenValues for an ERC721 token', async () => {
|
||||||
const tokenAddress = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D';
|
const tokenAddress = '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D';
|
||||||
const toAddress = '000000000000000000000000000000000000dead';
|
const toAddress = '000000000000000000000000000000000000dead';
|
||||||
|
Loading…
Reference in New Issue
Block a user