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

feature/default_network_editable
Alex Donesky 2 years ago committed by Dan J Miller
parent f503a634f0
commit d363bdbb21
  1. 10
      ui/hooks/useTokenDisplayValue.js

@ -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]);

Loading…
Cancel
Save