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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f51235b
Remove formatting of trade amounts using formatSmartAmount()
shoom3301 Jan 20, 2023
9730904
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Jan 31, 2023
7e16a0e
Fix tokenViewAmount
shoom3301 Feb 1, 2023
0d14cdf
Fix tokenViewAmount
shoom3301 Feb 1, 2023
3cdce9e
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Feb 2, 2023
80a3c65
Fix formatSmartAmount usage
shoom3301 Feb 2, 2023
a7d2c61
Use toSignificant() strategy for tokenViewAmount()
shoom3301 Feb 2, 2023
d446afc
Fix e2e test
shoom3301 Feb 2, 2023
192d99b
Fix e2e test
shoom3301 Feb 2, 2023
4ec3ba1
Amounts formatting
shoom3301 Feb 5, 2023
35feae0
Remove redundant deps from format.ts
shoom3301 Feb 5, 2023
b6a6e7a
Refactor TokenAmount for Account balances
shoom3301 Feb 5, 2023
97b91e9
Refactor TokenAmount for LockedGnoVesting
shoom3301 Feb 5, 2023
19db9a9
Refactor TokenAmount for Claim page and Invest
shoom3301 Feb 5, 2023
877edcc
Remove formatSmartLocaleAware
shoom3301 Feb 5, 2023
4d0ee9b
Remove formatSmartAmount
shoom3301 Feb 5, 2023
ff3d36d
Remove formatMax
shoom3301 Feb 5, 2023
2f79b6c
Remove formatSmart
shoom3301 Feb 5, 2023
649792d
Remove @cowprotocol/cow-js
shoom3301 Feb 5, 2023
55e9406
Fix trimTrailingZeros
shoom3301 Feb 5, 2023
1dd32a3
Use FiatAmount component
shoom3301 Feb 5, 2023
4e180ff
Fix tests
shoom3301 Feb 6, 2023
3c1d13d
More tests
shoom3301 Feb 6, 2023
2efa6cc
Amounts formatting docs
shoom3301 Feb 6, 2023
f7ab8fc
Amounts formatting docs
shoom3301 Feb 6, 2023
aaf6bf6
Amounts formatting docs
shoom3301 Feb 6, 2023
38af95b
Fix code style issues with Prettier
lint-action Feb 6, 2023
913d48f
Amounts formatting docs
shoom3301 Feb 6, 2023
fe00dfd
Merge remote-tracking branch 'origin/fix/139' into fix/139
shoom3301 Feb 6, 2023
99f5786
Fix code-style
shoom3301 Feb 6, 2023
3c6c4d2
Fix legacyBigNumberToCurrencyAmount
shoom3301 Feb 6, 2023
d998891
Fix percent displaying
shoom3301 Feb 7, 2023
047fd2e
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Feb 7, 2023
1f09d6f
Fix amounts formatting
shoom3301 Feb 7, 2023
11c52c9
Fix code style
shoom3301 Feb 7, 2023
19f4cd7
TODOs, Docs, feature flag for amounts formatting
shoom3301 Feb 7, 2023
9f98ef1
Rename FF
shoom3301 Feb 7, 2023
57177f4
Fix code style issues with Prettier
lint-action Feb 7, 2023
958b204
Fix issues
shoom3301 Feb 7, 2023
94ae0a3
Merge remote-tracking branch 'origin/fix/139' into fix/139
shoom3301 Feb 7, 2023
83382af
Round balance amount
shoom3301 Feb 7, 2023
d8b1bec
Fix issues
shoom3301 Feb 7, 2023
36c967d
Show less than 0.0001 for tokens with 0 decimals
shoom3301 Feb 7, 2023
8e5199f
Fix e2e test
shoom3301 Feb 7, 2023
97df229
Fix issues
shoom3301 Feb 8, 2023
149a6a4
Fix (v)COW balance displaying
shoom3301 Feb 8, 2023
be28eb0
Fix zero trim regarding locale
shoom3301 Feb 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function LimitOrdersWidget() {
[settingState.showRecipient, isWrapOrUnwrap]
)
const priceImpact = usePriceImpact(useLimitOrdersPriceImpactParams())
const inputViewAmount = tokenViewAmount(inputCurrencyAmount, inputCurrencyBalance, orderKind === OrderKind.SELL)
const inputViewAmount = tokenViewAmount(inputCurrencyAmount)

const inputCurrencyInfo: CurrencyInfo = {
field: Field.INPUT,
Expand All @@ -100,9 +100,7 @@ export function LimitOrdersWidget() {
label: isWrapOrUnwrap ? undefined : isSellOrder ? 'You receive at least' : 'You receive exactly',
currency: outputCurrency,
rawAmount: isWrapOrUnwrap ? inputCurrencyAmount : outputCurrencyAmount,
viewAmount: isWrapOrUnwrap
? inputViewAmount
: tokenViewAmount(outputCurrencyAmount, outputCurrencyBalance, orderKind === OrderKind.BUY),
viewAmount: isWrapOrUnwrap ? inputViewAmount : tokenViewAmount(outputCurrencyAmount),
balance: outputCurrencyBalance,
fiatAmount: outputCurrencyFiatAmount,
receiveAmountInfo: null,
Expand Down
4 changes: 2 additions & 2 deletions src/cow-react/modules/swap/containers/NewSwapWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function NewSwapWidget() {
field: Field.INPUT,
currency: currencies.INPUT || null,
rawAmount: parsedAmounts.INPUT || null,
viewAmount: tokenViewAmount(parsedAmounts.INPUT, inputCurrencyBalance, independentField === Field.INPUT),
viewAmount: tokenViewAmount(parsedAmounts.INPUT),
balance: inputCurrencyBalance,
fiatAmount: useHigherUSDValue(trade?.inputAmountWithoutFee),
receiveAmountInfo: independentField === Field.OUTPUT && trade ? getInputReceiveAmountInfo(trade) : null,
Expand All @@ -94,7 +94,7 @@ export function NewSwapWidget() {
field: Field.OUTPUT,
currency: currencies.OUTPUT || null,
rawAmount: parsedAmounts.OUTPUT || null,
viewAmount: tokenViewAmount(parsedAmounts.OUTPUT, outputCurrencyBalance, independentField === Field.OUTPUT),
viewAmount: tokenViewAmount(parsedAmounts.OUTPUT),
balance: outputCurrencyBalance,
fiatAmount: useHigherUSDValue(trade?.outputAmountWithoutFee),
receiveAmountInfo: independentField === Field.INPUT && trade ? getOutputReceiveAmountInfo(trade) : null,
Expand Down
18 changes: 3 additions & 15 deletions src/cow-react/modules/trade/utils/tokenViewAmount.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import { formatSmartAmount } from 'utils/format'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
import { maxAmountSpend } from 'utils/maxAmountSpend'
import { AMOUNT_PRECISION } from 'constants/index'

export function tokenViewAmount(
amount: CurrencyAmount<Currency> | undefined | null,
balance: CurrencyAmount<Currency> | null,
isIndependentField: boolean
): string {
if (isIndependentField) {
return amount?.toExact() || ''
}

const maxBalance = balance ? maxAmountSpend(balance) : undefined
const isInputCurrencyHasMaxAmount = !!(maxBalance && amount?.equalTo(maxBalance))

return (isInputCurrencyHasMaxAmount ? amount?.toExact() : formatSmartAmount(amount)) || ''
export function tokenViewAmount(amount: CurrencyAmount<Currency> | undefined | null): string {
return amount?.toFixed(AMOUNT_PRECISION) || ''
}