Skip to content
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

Fix error that occurs when attempting to display transaction value for a transaction with no value argument in the transaction data (in this case approve()) #15398

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions ui/hooks/useTokenDisplayValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,26 @@ 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 &&
// and raw transaction data string is provided
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]);

Expand Down