edge / wallet

The web wallet of the XE Blockchain.

Home Page:https://wallet.xe.network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change calculation base unit to mXE

annybs opened this issue · comments

commented

At the moment, parsing and calculations (for fees and final amounts) are all correct and in the correct units. However, XE and mXE are mixed together in places, so it's not always clear what unit calculations are in. As the wallet evolves, this is likely to create avoidable display/calculation errors.

Example: the balance store value is in mXE, as are all amounts/fees in blockchain API. On the other hand, when sending XE we parse the XE input directly to XE and calculate fees from that, then convert to mXE when submitting the transaction. This has the effect that our validator has to convert units, rather than simply comparing directly:

helpers.withParams({ b, p }, helpers.withMessage('Insufficient funds.', () => {
if (isNaN(p)) return false
return p <= (b / 1e6)
}))

It's worth noting that because of the conversion requirement, we have to copy-paste the validator for EDGE deposits. If we simply parse mXE and remove this need, we can use the same validator irrespective of currency, as long as the parsed/balance units match.

Using mXE as calculation base also simplifies minimum-amount validation, as we only need to ensure a transaction amount is greater than 0 mXE, rather than greater than 0.000001 XE. We can also round values more safely, ensuring mXE is an indivisible unit. Generally, moving towards integer calculations will improve clarity and robustness.

Once the mXE basis is in place, validation should be reviewed to ensure sub-mXE inputs are not possible e.g.

image