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

Amounts displaying refactoring #1907

Merged
merged 47 commits into from
Feb 8, 2023
Merged

Amounts displaying refactoring #1907

merged 47 commits into from
Feb 8, 2023

Conversation

shoom3301
Copy link
Collaborator

@shoom3301 shoom3301 commented Jan 20, 2023

Summary

Fixes #139 #137

image

How does it work

Docs: https://github.com/cowprotocol/cowswap/blob/fix/139/src/cow-react/utils/amountFormat/README.md
Implementation: https://github.com/cowprotocol/cowswap/blob/fix/139/src/cow-react/utils/amountFormat/index.ts#L18
Test cases: https://github.com/cowprotocol/cowswap/blob/fix/139/src/cow-react/utils/amountFormat/index.test.ts

Testing

localStorage.setItem('amountsRefactoring', '1') - run this in the browser console and reload the page to highlight places with the refactored amounts

What changed

  1. Removed usage of @cowprotocol/cow-js
  2. formatSmartAmount, formatSmart, formatSmartLocaleAware, formatMax were replaced by <TokenAmount> component
  3. Fiat amounts we replaced by <FiatAmount> component
  4. Changed formatting for swap and Limit orders form inputs (formatAmountInput function)
  5. Fixed a bug in limit orders: 1) Set up a trade (WETH -> COW) 2) Don't change the rate, just add a couple of digits at the end (4468.9031 -> 4468.903177) 3) Wait ~15 sec 4) AR: the rate resets to the previous ER: the rate doesn't change

Affected area

  1. Swap page
  2. Limit orders. Please, pay attention on the receipt modal (amounts accuracy). The component uses BigNumber.js and because of it we convert amounts using .toNumber() cast
  3. ETH flow stepper
  4. Swap fees information + tooltips
  5. Wrap/unwrap
  6. Account page balances
  7. Account locked GNO vesting
  8. Account vesting
  9. Vesting claim (status, table, investment flow, etc.)
  10. Activity details (tx, order)
  11. Cow token balance
  12. Subsidy modal
  13. Tokens list search modal
  14. Tokens page
  15. Order signing pending modal

@shoom3301 shoom3301 requested review from a team January 20, 2023 08:18
@shoom3301 shoom3301 self-assigned this Jan 20, 2023
@vercel
Copy link

vercel bot commented Jan 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
swap-dev ✅ Ready (Inspect) Visit Preview 💬 Add your feedback

🌃 Cosmos ↗︎

@github-actions
Copy link
Contributor

CLA Assistant Lite All Contributors have signed the CLA.

Copy link
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @shoom3301 , great job!

  1. However, we should think what to display when users trade with tiny amounts now:
    0000
    0 0000

  2. And it would be also great to apply these changes to the Price field onn the Limit orders page:
    price

  3. There are no changes to amounts on an order confirm screen. Is this OK?
    order confirm modal

  4. I noticed that 4 decimals are added to an amount when go to the Limit orders page and back to the Swap page:
    added

  5. Receive/from tooltip has different formatting for amounts:
    fee

Thanks!

@anxolin
Copy link
Contributor

anxolin commented Jan 24, 2023

Why 4 decimals?

The UI should show you exactly what you sign. No more, no less :)

This means:

  • For Sell orders: We show how much you receive given the current price. We use the receive token precision, and round down (so we make sure the trade is executable)
  • For buy orders: We show how much you need to pay given the current price. We use the sell token precision, and round up (so we make sure the trade is executable)

@anxolin
Copy link
Contributor

anxolin commented Jan 24, 2023

And it would be also great to apply these changes to the Price field onn the Limit orders page

Agree, price should have good precision, at least if it is a small amount.
I think the smart formatting tries to take the size of the value into account. If you are handling trillions, maybe you don't need decimals, but if you are dealing with something smaller than 0.1 you will need some.

Maybe is a matter of having XX significant digits?

@anxolin
Copy link
Contributor

anxolin commented Jan 24, 2023

Receive/from tooltip has different formatting for amounts:

Yes we should be consistent

… fix/139

� Conflicts:
�	src/cow-react/modules/trade/utils/tokenViewAmount.ts
@shoom3301
Copy link
Collaborator Author

@elena-zh thank you!
All must be fixed

@elena-zh
Copy link
Contributor

elena-zh commented Feb 1, 2023

Hey @shoom3301 , great job!
Some issues I see:

  1. I don't think that we should show all decimals on Receive/From fields
    receive
  2. The same with the tooltip: I tried to explain in the thread that is would be great to leave it as it is now (using formatted amounts) instead of the current view:
    tooltip
    Sorry if I mixed you up and explained no clear it
  3. Seems that now the form is overloaded with numbers now
    image

Is it possible to use 4-decimals rounding for amounts that >1, and use the current logic (up to 18 decimals) when amounts are less than 1?
Can't insist on this, but think that it would be a bit nicer from UI perspective.

  1. It would be great to add a space between the number and a token name in the last sentence. And not to show the full amount (as we agreed to show it in input fields only)
    B or space

Thanks!

@shoom3301
Copy link
Collaborator Author

shoom3301 commented Feb 2, 2023

@elena-zh thanks, fixed!

Is it possible to use 4-decimals rounding for amounts that >1, and use the current logic (up to 18 decimals) when amounts are less than 1?

It could create other problems, so I would like to think about it in another task

@elena-zh
Copy link
Contributor

elena-zh commented Feb 2, 2023

Some edge cases that I see now:

  1. Amounts in the To/From fields do not match with the tooltip:
    image
  2. When a value is huge, lots of 0 are displayed in its end:
    image
    image
    image
    Received amount is in imcorrect on the modal:
    image
  3. Price still can show only zeros in the field
    image
  4. Amount is not rounded to 6 decimals in the Review limit order modal
    image

Copy link
Collaborator

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more comments. I'll eventually reach 0 :D

@elena-zh
Copy link
Contributor

elena-zh commented Feb 7, 2023

Hey @shoom3301 , amazing job! All issues I reported are fixed.
Some of them, as I mentioned above, are reported in separate tasks.
However, 1 tiny issue is found with localization of amounts:
France: there should be comma instead of period to separate a decimal part
fra
Germany: the same (there should be comma instead of period to separate a decimal part):
germ
Rus: the same (there should be comma instead of period to separate a decimal part):
image

Could you please take a look into this issue?

@shoom3301
Copy link
Collaborator Author

image

@elena-zh thanks! Fixed!
Anyway, I would discuss it with the team, because I don't like the format of RU localization :) I used to see dots instead of commas

Copy link
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved!!!

@shoom3301
Copy link
Collaborator Author

@SocketSecurity ignore [email protected]
@SocketSecurity ignore [email protected]
@SocketSecurity ignore [email protected]

Copy link
Collaborator

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is approved, no more comments \o/

Now testing the app, a few comments :D

ru language:
Screenshot 2023-02-08 at 11 36 51
Shouldn't the thousands separator apply also to the input numbers?

pt-br language
Screenshot 2023-02-08 at 11 35 33
I haven't seen all comments but I assume Elena has mentioned this.
The decimal separator is different in the display fields from the input field.
To be fair, this has been like this since the start.
Are we keeping this behaviour?

ar language (arabic)
Screenshot 2023-02-08 at 11 34 35
Hehe, this is funny.
Not sure we want to do something about this, but anyway.
With this language we can notice that the decimals part is not respecting the language locale.

@elena-zh
Copy link
Contributor

elena-zh commented Feb 8, 2023

Hey @alfetopito

I haven't seen all comments but I assume Elena has mentioned this.
The decimal separator is different in the display fields from the input field.
To be fair, this has been like this since the start.
Are we keeping this behaviour?

I think it was discussed in https://cowservices.slack.com/archives/C0361CDG8GP/p1675354573189409?thread_ts=1675337080.573789&cid=C0361CDG8GP : there is a separate task for this #213 , and it will be addressed (one day) in a separate PR.

@shoom3301
Copy link
Collaborator Author

Thanks @alfetopito !
We definitely should add formatting for inputs, but it requires enough efforts, so I think we should address it in the next iteration

@shoom3301 shoom3301 merged commit c2ed079 into develop Feb 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2023
@alfetopito alfetopito deleted the fix/139 branch February 8, 2023 13:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Difficult to edit a token amount when it is <0.0001
5 participants