-
Notifications
You must be signed in to change notification settings - Fork 212
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
Token-manager: use bn.js #432
Conversation
Match the order of the stake table
b8a7ff2 was added to fix the following UI inconsistency: |
We need to test how this handles amounts when token balances are decimal, given that BN.js only works with integers. |
@2color Looking good! 💯 I added support for decimals. |
Sweet! Would be good to add tests as a next step too.
On Mon, 24 Sep 2018 at 13:38 Coveralls ***@***.***> wrote:
[image: Coverage Status] <https://coveralls.io/builds/19154017>
Coverage decreased (-0.8%) to 96.212% when pulling *f996026
<f996026>
on 2color:use-bn* into *d62f2b6
<d62f2b6>
on aragon:master*.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#432 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB5mP-s1uthCZKx0Rb9AzVA_8DA3FrBxks5ueMQzgaJpZM4WgBS3>
.
--
Daniel Norman
|
Ahh... this is probably due to radspec :(. Good catch. |
@chris-remus There's still a bug that @bpierre reported when the token decimal base is 100. I made the wrong assumption in the last commit. I'm trying to better understand the different possible values for |
@izqui The percentages should be fixed now |
apps/token-manager/app/src/utils.js
Outdated
.filter(({ amount }) => !amount.isZero()) | ||
.map(stake => ({ | ||
...stake, | ||
percentage: stake.amount.mul(pctPrecision).div(total), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly, the reason I did the calculations with native numbers originally was that I hit problems with this type of arithmetic with BNs. Give it a go with http://aragon.aragonpm.com/#/4color.aragonid.eth/
Also fixes the detection of the rest item in the panel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💫🔢 Amazing!
Just two minor things :)
@@ -93,7 +95,7 @@ class AssignVotePanelContent extends React.Component { | |||
<TextInput.Number | |||
value={amount} | |||
onChange={this.handleAmountChange} | |||
min={0} | |||
min={minimum} | |||
step="any" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step should also be minimum
, to avoid people adding decimal precision that will be lost in the contract
apps/token-manager/app/src/utils.js
Outdated
fraction = `${zeros}${fraction}` | ||
const whole = amount.div(base).toString() | ||
|
||
return `${whole}${fraction === '0' ? '' : `.${fraction.slice(0, 2)}`}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice UI touch
Merged, thank you @2color! 🎉 💯 |
Thanks for following through! Nicely polished 🥇 |
Some related changes: - Add tests (Jest). - Support decimals. - New algorithm to calculate stake percentages (remove 0% values). - Sort holders table in descending order.
Some related changes: - Add tests (Jest). - Support decimals. - New algorithm to calculate stake percentages (remove 0% values). - Sort holders table in descending order.
The PR allows the assigning/minting of sums larger than 100.
Fixes #266
Approach
Notes
When discussed with @sohkai, Brett suggested converting the strings to BN.js object in the web worker. When done that way, the BN.js objects were serialised as normal objects with the BN.js properties and required reinitialisation in the react application. Therefor I left the numbers in the worker as strings.
Extras
Sorted the balances to match the stake percentage table for a more coherent UI.