Skip to content

Change calculation base unit to mXE #146

@annybs

Description

@annybs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions