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

Small big number bug fix on account details #846

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

marc-aurele-besner
Copy link
Collaborator

@marc-aurele-besner marc-aurele-besner commented Sep 9, 2024

User description

Small big number bug fix on account details


PR Type

Bug fix


Description

  • Fixed a bug in AccountBalancePieChart by ensuring otherNumber is correctly passed to bigNumberToNumber without converting it to a string.
  • Added a check in bigNumberToNumber utility function to return 0 if the input bigNumber is falsy, preventing potential errors.

Changes walkthrough 📝

Relevant files
Bug fix
AccountBalancePieChart.tsx
Fix conversion of `otherNumber` in AccountBalancePieChart

explorer/src/components/Consensus/Account/AccountBalancePieChart.tsx

  • Fixed conversion of otherNumber to a string before passing to
    bigNumberToNumber.
  • +1/-1     
    number.ts
    Add falsy check for `bigNumber` in utility function           

    explorer/src/utils/number.ts

  • Added a check to return 0 if bigNumber is falsy in bigNumberToNumber.
  • +1/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    netlify bot commented Sep 9, 2024

    Deploy Preview for dev-astral ready!

    Name Link
    🔨 Latest commit 4dcd795
    🔍 Latest deploy log https://app.netlify.com/sites/dev-astral/deploys/66def3d5eff2ad0008973071
    😎 Deploy Preview https://deploy-preview-846--dev-astral.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link

    github-actions bot commented Sep 9, 2024

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Type Consistency
    The function bigNumberToNumber now handles inputs that are falsy by returning 0. However, the function signature does not explicitly state the possible types for bigNumber which can now include undefined or null due to the new check. It's recommended to update the function signature or documentation to reflect this change.

    Copy link

    github-actions bot commented Sep 9, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Ensure consistent number conversion methods are used for all account properties

    Consider using a consistent method for converting account.total, account.free, and
    account.reserved to numbers. Currently, Number() is used directly in the calculation
    of otherNumber, while bigNumberToNumber() is used for transferable and staking. This
    inconsistency might lead to precision errors or bugs, especially with large numbers.
    A unified approach using bigNumberToNumber() for all conversions would ensure
    consistency and potentially avoid bugs related to number precision.

    explorer/src/components/Consensus/Account/AccountBalancePieChart.tsx [13-17]

     const otherNumber = account
    -  ? Number(account.total) - Number(account.free) - Number(account.reserved)
    +  ? bigNumberToNumber(account.total) - bigNumberToNumber(account.free) - bigNumberToNumber(account.reserved)
       : 0
     const transferable = account ? bigNumberToNumber(account.free) : 0
     const staking = account ? bigNumberToNumber(account.reserved) : 0
     
    Suggestion importance[1-10]: 9

    Why: The suggestion addresses a potential bug by ensuring consistent number conversion methods, which is crucial for maintaining precision and avoiding errors, especially with large numbers.

    9
    Enhancement
    Improve type handling in bigNumberToNumber to ensure accurate string conversions

    The bigNumberToNumber function should handle different types of inputs more
    robustly. The current implementation assumes that any non-string input can be
    directly converted to a string, which might not always be safe or accurate,
    especially for bigint and number types. Consider checking the type of bigNumber and
    handling each type appropriately to ensure accurate conversions.

    explorer/src/utils/number.ts [29]

    -if (typeof bigNumber !== 'string') bigNumber = bigNumber.toString()
    +if (typeof bigNumber === 'bigint') {
    +  bigNumber = bigNumber.toString()
    +} else if (typeof bigNumber === 'number') {
    +  bigNumber = bigNumber.toFixed(precision)
    +}
     
    Suggestion importance[1-10]: 7

    Why: The suggestion enhances the robustness of the bigNumberToNumber function by handling different input types more accurately, which improves code reliability and correctness.

    7

    @marc-aurele-besner marc-aurele-besner merged commit cd93a13 into main Sep 9, 2024
    14 checks passed
    @marc-aurele-besner marc-aurele-besner deleted the bug/fixAccountNumberBug branch September 9, 2024 13:56
    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.

    2 participants