telosnetwork / open-block-explorer

The Open Block Explorer (OBE) is the first open source block explorer that is designed to support all AntelopeIO-based blockchains.
https://explorer.telos.net
Apache License 2.0
27 stars 24 forks source link

REX unstaking balance bug prevents unstaking - disable input sanitation. #733

Closed DouglasHorn closed 9 months ago

DouglasHorn commented 1 year ago

Describe the bug A known issue is that OBE is incorrectly calculating the matured REX balance by roughly 99.9% at one place on the page (but not the other). Input sanitation prevents the user from using the interface to unstake. Disabling input sanitation will allow users to unstake.

To Reproduce The display bug is described in https://github.com/telosnetwork/open-block-explorer/issues/685

  1. Login to OBE at explorer.telos.net/account/ with an account that has a matured REX balance > 0 TLOS.

  2. Go to the Unstake Page

  3. The Matured Balance is shown correctly at the top of the page but lower on the same page, directly above the input box, the amount shown is incorrect.

  4. If a value <= the actual matured balance is input the page flags it as an "invalid amount" and prevents the Unstake TLOS button from being unstaked. (UI note: the red lettering on a dark purple background is practically unreadable.)

Screenshots

Screenshot 2023-07-30 at 1 10 07 PM

Proposed Solution The best solution would be to correct the calculated amount of matured REX shown per Issue 685, but that has not been done.

The fastest solution would simply be to remove the error handling on the Unstake button to allow invalid amounts to be attempted. While this risks users getting an error message if they try to unstake an amount greater than their matured balance, that is preferable to not being able to unstake the balance.

Viterbo commented 1 year ago

The problem here is the so-called max available which is a completely incorrect number (it is 28 and it should be 28800). It gets truncated by the comma.

This is the line that is creating this error (in master branch): https://github.com/telosnetwork/open-block-explorer/blob/master/src/utils/string-utils.ts#L72

export function assetToAmount(asset: string): number {
    try {
        const qty: string = asset.split(' ')[0];
        return parseFloat(qty); // << here is the bug line ("12,345.6789" -> 12)
    } catch (error) {
        return 0;
    }
}

Which is already fixed here (in develop branch): https://github.com/telosnetwork/open-block-explorer/blob/develop/src/utils/string-utils.ts#L72C67-L72C67

export function assetToAmount(asset: string): number {
    try {
        const qty: string = asset.split(' ')[0];
        return parseFloat(qty.replace(/,/g, '')); // remove commas
    } catch (error) {
        return 0;
    }
}
donnyquixotic commented 9 months ago

Resolved