1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Fix error that occurs when attempting to display transaction value for an approval transaction with no value argument in the transaction data (#15398)

This commit is contained in:
Alex Donesky 2022-08-01 11:42:58 -05:00 committed by GitHub
parent bca9a61d6b
commit fc304680d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,8 @@ export function useTokenDisplayValue(
isTokenTransaction = true,
) {
const tokenData = useTokenData(transactionData, isTokenTransaction);
const tokenValue = getTokenValueParam(tokenData);
const shouldCalculateTokenValue = Boolean(
// If we are currently processing a token transaction
isTokenTransaction &&
@ -42,15 +44,17 @@ export function useTokenDisplayValue(
transactionData &&
// and a token object has been provided
token &&
// and we are able to parse the token details from the raw data
tokenData?.args?.length,
// and the provided token object contains a defined decimal value we need to calculate amount
token.decimals &&
// and we are able to parse the token detail we to calculate amount from the raw data
tokenValue,
);
const displayValue = useMemo(() => {
if (!shouldCalculateTokenValue) {
return null;
}
const tokenValue = getTokenValueParam(tokenData);
return calcTokenAmount(tokenValue, token.decimals).toString(10);
}, [shouldCalculateTokenValue, tokenData, token]);