Skip to content

Conversation

@urnotsam
Copy link
Contributor

@urnotsam urnotsam commented Aug 27, 2025

PR Type

Bug fix, Enhancement


Description

  • Fixed ERC20 value display for transactions with invalid decimals.

  • Replaced deprecated utils.formatUnits with formatUnits from ethers.

  • Improved handling of decimals parsing for ERC20 tokens.

  • Ensured correct value formatting for ERC20 and EVM_Internal tokens.


Changes walkthrough 📝

Relevant files
Bug fix
calculateValue.ts
Fix and enhance ERC20 value formatting logic                         

src/frontend/utils/calculateValue.ts

  • Replaced utils.formatUnits with formatUnits from ethers.
  • Improved decimals parsing with additional validation.
  • Enhanced value formatting logic for ERC20/EVM_Internal tokens.
  • Ensured fallback to 18 decimals if parsing fails.
  • +6/-4     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🏅 Score: 93
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Decimals Parsing Robustness

    The new logic for parsing decimals in contractInfo improves safety, but edge cases (e.g., decimals as a float, string with whitespace, or undefined) should be validated to ensure no unexpected behavior occurs.

    const decimalsValue = tokenTx.contractInfo.decimals && !isNaN(parseInt(tokenTx.contractInfo.decimals)) 
      ? parseInt(tokenTx.contractInfo.decimals) 
      : 18
    Value Formatting Consistency

    The switch from utils.formatUnits to formatUnits from ethers should be checked for any subtle differences in formatting or rounding that could affect displayed values, especially for very large or small numbers.

    ? formatUnits(tokenTx.tokenValue, decimalsValue)
    : roundTokenValue(formatUnits(tokenTx.tokenValue, decimalsValue))

    Comment on lines +31 to +39
    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))
    Copy link
    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))

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants