Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/frontend/utils/calculateValue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import web3 from 'web3'
import { utils } from 'ethers'
import { formatUnits } from 'ethers'
import { TokenTx, TokenType, TransactionType } from '../../types'
import BN from 'bn.js'
import { fromWeiNoTrailingComma } from './fromWeiNoTrailingComma'
Expand Down Expand Up @@ -28,13 +28,15 @@ export const calculateTokenValue = (
): string => {
try {
if (txType === TokenType.ERC_20 || txType === TokenType.EVM_Internal) {
const decimalsValue = tokenTx.contractInfo.decimals ? parseInt(tokenTx.contractInfo.decimals) : 18
const decimalsValue = tokenTx.contractInfo.decimals && !isNaN(parseInt(tokenTx.contractInfo.decimals))
? parseInt(tokenTx.contractInfo.decimals)
: 18

return tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
? 'unlimited'
: fullValue
? utils.formatUnits(tokenTx.tokenValue, decimalsValue)
: roundTokenValue(utils.formatUnits(tokenTx.tokenValue, decimalsValue))
? formatUnits(tokenTx.tokenValue, decimalsValue)
: roundTokenValue(formatUnits(tokenTx.tokenValue, decimalsValue))
Comment on lines +31 to +39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Ensure that tokenTx.tokenValue is a valid string or BigNumber before passing it to formatUnits, as invalid input may cause runtime errors. Add a check to handle undefined or null values for tokenTx.tokenValue. [possible issue, importance: 7]

Suggested change
const decimalsValue = tokenTx.contractInfo.decimals && !isNaN(parseInt(tokenTx.contractInfo.decimals))
? parseInt(tokenTx.contractInfo.decimals)
: 18
return tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
? 'unlimited'
: fullValue
? utils.formatUnits(tokenTx.tokenValue, decimalsValue)
: roundTokenValue(utils.formatUnits(tokenTx.tokenValue, decimalsValue))
? formatUnits(tokenTx.tokenValue, decimalsValue)
: roundTokenValue(formatUnits(tokenTx.tokenValue, decimalsValue))
const decimalsValue = tokenTx.contractInfo.decimals && !isNaN(parseInt(tokenTx.contractInfo.decimals))
? parseInt(tokenTx.contractInfo.decimals)
: 18
if (!tokenTx.tokenValue) {
return '0';
}
return tokenTx.tokenValue === '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
? 'unlimited'
: fullValue
? formatUnits(tokenTx.tokenValue, decimalsValue)
: roundTokenValue(formatUnits(tokenTx.tokenValue, decimalsValue))


// : round(web3.utils.fromWei(tokenTx.tokenValue, "ether"));
} else if (txType === TokenType.ERC_721) {
Expand Down
Loading