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

Change calculation base unit to mXE #146

Open
annybs opened this issue Jan 21, 2022 · 0 comments
Open

Change calculation base unit to mXE #146

annybs opened this issue Jan 21, 2022 · 0 comments

Comments

@annybs
Copy link
Member

annybs commented Jan 21, 2022

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

@annybs annybs self-assigned this Jan 21, 2022
@annybs annybs removed their assignment Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant