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

test: e2e test fiat amount displaying #3082

Merged
merged 46 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0436ad0
refactor: remove usd amount calc based ony CowSwap quote
shoom3301 Aug 22, 2023
76925b3
refactor: move useHigherUSDValue hook to fiatAmount module
shoom3301 Aug 22, 2023
3ff2993
refactor: calculate priceImpact only basing on Coingecko
shoom3301 Aug 22, 2023
36931aa
refactor: request fiat amounts only when trade is ready
shoom3301 Aug 23, 2023
315d15a
refactor: deprecate parsePrice
shoom3301 Aug 23, 2023
32affd6
feat: use native price api for fiat amounts
shoom3301 Aug 23, 2023
007afd6
feat: module for fiat prices
shoom3301 Aug 24, 2023
cc1298a
chore: remove unused file
shoom3301 Aug 24, 2023
3409abb
chore: simplify code
shoom3301 Aug 25, 2023
639f220
docs: fiat price module diagram
shoom3301 Aug 25, 2023
6e6eba5
chore: fix import
shoom3301 Aug 25, 2023
e8ab945
chore: rename
shoom3301 Aug 25, 2023
245409d
chore: remove error field from price impact
shoom3301 Aug 25, 2023
7f353e3
chore: fix build
shoom3301 Aug 25, 2023
4eb1f6d
chore: fix build
shoom3301 Aug 25, 2023
1b339f5
Merge branch 'fix/fiat-amount-api' of https://github.com/cowprotocol/…
shoom3301 Aug 25, 2023
d0e659a
test: e2e test fiat amount displaying
shoom3301 Aug 25, 2023
d0019d6
fix: display price impact unknown warning only when fiat amounts are …
shoom3301 Aug 28, 2023
3795e7d
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Aug 28, 2023
7274ad1
Merge branch 'fix/fiat-amount-api' of https://github.com/cowprotocol/…
shoom3301 Aug 28, 2023
960c22b
chore: rename var
shoom3301 Aug 28, 2023
6e3b193
chore: rename const
shoom3301 Aug 28, 2023
da2b879
chore: clean up env files
shoom3301 Aug 28, 2023
22ed725
chore: clean up code
shoom3301 Aug 28, 2023
40ac98c
chore: refactor fetchCurrencyFiatPrice
shoom3301 Aug 28, 2023
3601d0f
fix: fix UnknownImpactWarning displaying conditions
shoom3301 Aug 28, 2023
e97a8e6
chore: fix naming
shoom3301 Aug 28, 2023
1e18bbd
fix: request USDC native price on demand
shoom3301 Aug 28, 2023
d8e3483
Merge branch 'fix/fiat-amount-api-2' of https://github.com/cowprotoco…
shoom3301 Aug 28, 2023
e5b0a4e
fix: fix calc
shoom3301 Aug 28, 2023
dc2b958
fix: fix errors catching in fetchCurrencyFiatPrice
shoom3301 Aug 28, 2023
60168a2
Merge branch 'fix/fiat-amount-api-2' of https://github.com/cowprotoco…
shoom3301 Aug 28, 2023
1554ecd
chore: additional check for zero
shoom3301 Aug 29, 2023
b4e7224
chore: fix comment
shoom3301 Aug 29, 2023
c95e7de
chore: refactor useFiatValuePriceImpact
shoom3301 Aug 29, 2023
9fc2797
chore: rename getCoingeckoFiatPrice
shoom3301 Aug 29, 2023
0ca263b
chore: rename usdc -> usd
shoom3301 Aug 29, 2023
fa035e8
chore: simplify useUsdPrice
shoom3301 Aug 29, 2023
4955667
chore: rename fiat -> usd
shoom3301 Aug 29, 2023
04908d6
chore: rename fiat -> usd globally
shoom3301 Aug 29, 2023
ff84560
Merge branch 'fix/fiat-amount-api-unit-tests' of https://github.com/c…
shoom3301 Aug 29, 2023
355671f
chore: simplify useTradeUsdAmounts
shoom3301 Aug 29, 2023
45b0615
chore: coingecko fetch rate limitter and backOff
shoom3301 Aug 30, 2023
04a1791
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Aug 31, 2023
6c586f3
Merge branch 'fix/fiat-amount-api-2' of https://github.com/cowprotoco…
shoom3301 Aug 31, 2023
e0d9579
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 Aug 31, 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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ All price feeds are enabled by default, but they can be individually disabled by
| **Paraswap** | `REACT_APP_PRICE_FEED_PARASWAP_ENABLED` | `boolean` (default = `true`) | [Paraswap](https://paraswap.io/) price estimation. Used for all price estimations. |
| **1inch** | `REACT_APP_PRICE_FEED_1INCH_ENABLED` | `boolean` (default = `true`) | [Paraswap](https://1inch.exchange) price estimation. Used for all price estimations. |
| **0x** | `REACT_APP_PRICE_FEED_0X_ENABLED` | `boolean` (default = `true`) | [0x](https://0x.org/) price estimation. Used for all price estimation. |
| **Coingecko** | `REACT_APP_PRICE_FEED_COINGECKO_ENABLED` | `boolean` (default = `true`) | [Coingecko](coingecko.com) price estimation. Used only for USD estimations to calculate the slippage on the trade. |

### Metadata attached to orders (AppData)

Expand Down
38 changes: 38 additions & 0 deletions apps/cowswap-frontend-e2e/src/e2e/fiat-amounts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function getInputFiatAmount() {
return cy.get('#input-currency-input .fiat-amount').invoke('text')
}

function getInputToken() {
return cy.get('#input-currency-input .token-amount-input').should('be.enabled')
}

function parseFiatAmountText(text: string): number {
return +text.split('$')[1].replace(/,/g, '')
}

describe('Fiat amounts', () => {
beforeEach(() => {
cy.visit('/#/5/swap/WETH/COW')
})

it('Should change fiat amount after changing currency amount', () => {
getInputToken().type('1')

// Get fiat amount for 1 WETH
getInputFiatAmount().then((fiatAmountOneText) => {
const fiatAmountOne = parseFiatAmountText(fiatAmountOneText)

// Input 2 WETH
getInputToken().clear().type('2')

// Get fiat amount for 2 WETH
getInputFiatAmount().then((fiatAmountTwoText) => {
const fiatAmountTwo = parseFiatAmountText(fiatAmountTwoText)
const onePercent = fiatAmountOne * 0.01

// Check that fiat amount of 2 WETH is ~2x fiat amount of 1 WETH
expect(fiatAmountTwo).to.closeTo(fiatAmountOne * 2, onePercent)
})
})
})
})
1 change: 0 additions & 1 deletion apps/cowswap-frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ REACT_APP_PRICE_FEED_GP_ENABLED=true
REACT_APP_PRICE_FEED_PARASWAP_ENABLED=true
REACT_APP_PRICE_FEED_1INCH_ENABLED=true
REACT_APP_PRICE_FEED_0X_ENABLED=true
REACT_APP_PRICE_FEED_COINGECKO_ENABLED=true

# AppData, build yours at https://explorer.cow.fi/appdata
REACT_APP_FULL_APP_DATA_PRODUCTION='{"version":"0.7.0","appCode":"CoW Swap","environment":"production","metadata":{}}'
Expand Down
1 change: 0 additions & 1 deletion apps/cowswap-frontend/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ REACT_APP_PRICE_FEED_GP_ENABLED=true
REACT_APP_PRICE_FEED_PARASWAP_ENABLED=true
REACT_APP_PRICE_FEED_1INCH_ENABLED=true
REACT_APP_PRICE_FEED_0X_ENABLED=true
REACT_APP_PRICE_FEED_COINGECKO_ENABLED=true
# INFURA KEY
REACT_APP_INFURA_KEY=586e7e6b7c7e437aa41f5da496a749f5

Expand Down
135 changes: 0 additions & 135 deletions apps/cowswap-frontend/src/api/coingecko/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAtomValue } from 'legacy/state/application/atoms'
import { useAtomValue } from 'jotai'

import { cancellationModalContextAtom } from 'common/hooks/useCancelOrder/state'
import { CancellationModal as Pure } from 'common/pure/CancellationModal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Nullish } from 'types'
import { MIN_FIAT_SURPLUS_VALUE, MIN_FIAT_SURPLUS_VALUE_MODAL, MIN_SURPLUS_UNITS } from 'legacy/constants'
import { Order } from 'legacy/state/orders/actions'

import { useCoingeckoUsdValue } from 'modules/fiatAmount'
import { useUsdAmount } from 'modules/usdAmount'

import { getExecutedSummaryData } from 'utils/getExecutedSummaryData'
import { ParsedOrder } from 'utils/orderUtils/parseOrder'
Expand All @@ -34,7 +34,7 @@ export function useGetSurplusData(order: Order | ParsedOrder | undefined): Outpu
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(order)])

const surplusFiatValue = useCoingeckoUsdValue(surplusAmount).value
const surplusFiatValue = useUsdAmount(surplusAmount).value
const showFiatValue = Number(surplusFiatValue?.toExact()) >= MIN_FIAT_SURPLUS_VALUE

const showSurplus = shouldShowSurplus(surplusFiatValue, surplusAmount)
Expand Down
14 changes: 7 additions & 7 deletions apps/cowswap-frontend/src/common/hooks/useRateInfoParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Currency, CurrencyAmount } from '@uniswap/sdk-core'

import { Nullish } from 'types'

import { useHigherUSDValue } from 'modules/fiatAmount'
import { useTradeUsdAmounts } from 'modules/usdAmount'
import { useWalletInfo } from 'modules/wallet'

import { usePrice } from 'common/hooks/usePrice'
Expand All @@ -29,13 +29,13 @@ export function useRateInfoParams(
[activeRate]
)

const activeRateFiatAmount = useHigherUSDValue(
const {
inputAmount: { value: invertedActiveRateFiatAmount },
outputAmount: { value: activeRateFiatAmount },
} = useTradeUsdAmounts(
tryParseCurrencyAmount(parseRate(true), inputCurrencyAmount?.currency || undefined),
tryParseCurrencyAmount(parseRate(false), outputCurrencyAmount?.currency || undefined)
).value

const invertedActiveRateFiatAmount = useHigherUSDValue(
tryParseCurrencyAmount(parseRate(true), inputCurrencyAmount?.currency || undefined)
).value
)

return useSafeMemoObject({
chainId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Currency, CurrencyAmount, Price } from '@uniswap/sdk-core'

import { useHigherUSDValue } from 'modules/fiatAmount'
import { useUsdAmount } from 'modules/usdAmount'

import { rawToTokenAmount } from 'utils/rawToTokenAmount'

Expand All @@ -19,5 +19,5 @@ export function useExecutionPriceFiat(
): CurrencyAmount<Currency> | null {
const amount = executionPrice ? getPriceQuoteAmount(executionPrice, isInverted) : undefined

return useHigherUSDValue(amount).value
return useUsdAmount(amount).value
}
2 changes: 1 addition & 1 deletion apps/cowswap-frontend/src/common/pure/FiatAmount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function FiatAmount({ amount, defaultValue, className, accurate = false }
const accuracySymbol = accurate ? '' : '≈ '

return (
<Wrapper title={title} className={className} highlight={highlight}>
<Wrapper title={title} className={(className || '') + ' fiat-amount'} highlight={highlight}>
{formattedAmount ? accuracySymbol + '$' : ''}
{formattedAmount || defaultValue}
</Wrapper>
Expand Down
7 changes: 7 additions & 0 deletions apps/cowswap-frontend/src/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'

/**
* https://github.com/rndlabs/composable-cow/blob/main/src/ComposableCoW.sol
* Information about ComposableCoW conditional orders
Expand All @@ -21,3 +23,8 @@ export type SafeTransactionParams = {
confirmations: number
safeTxHash: string
}

export interface TradeAmounts {
readonly inputAmount: CurrencyAmount<Currency>
readonly outputAmount: CurrencyAmount<Currency>
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useAtomValue, useSetAtom } from 'jotai'
import { selectAtom } from 'jotai/utils'
import React, { useEffect, useMemo, useCallback, useRef, PropsWithChildren } from 'react'

import { useRecentActivityLastPendingOrder } from 'legacy/hooks/useRecentActivity'
import {
useSetAtom,
useAtomValue,
handleFollowPendingTxPopupAtom,
handleHidePopupPermanentlyAtom,
showFollowTxPopupAtom,
followPendingTxPopupAtom,
selectAtom,
handleCloseOrderPopupAtom,
} from 'legacy/state/application/atoms'
import { Order } from 'legacy/state/orders/actions'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans } from '@lingui/macro'

import { MouseoverTooltip } from 'legacy/components/Tooltip'

import { useHigherUSDValue } from 'modules/fiatAmount'
import { useUsdAmount } from 'modules/usdAmount'

import { FiatAmount } from 'common/pure/FiatAmount'

Expand All @@ -14,9 +14,9 @@ type FiatBalanceCellProps = {
balance: CurrencyAmount<Token> | undefined
}

export default function FiatBalanceCell({ balance }: FiatBalanceCellProps) {
export function FiatBalanceCell({ balance }: FiatBalanceCellProps) {
const hasBalance = balance?.greaterThan(0)
const fiatValue = useHigherUSDValue(balance).value
const fiatValue = useUsdAmount(balance).value

return (
<BalanceValue hasBalance={!!hasBalance}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CardsSpinner, ExtLink } from 'pages/Account/styled'

import BalanceCell from './BalanceCell'
import FavouriteTokenButton from './FavouriteTokenButton'
import FiatBalanceCell from './FiatBalanceCell'
import { FiatBalanceCell } from './FiatBalanceCell'
import {
ApproveLabel,
BalanceValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useAtomValue } from 'legacy/state/application/atoms'
import { useAtomValue } from 'jotai'

import { useModalIsOpen, useToggleModal } from 'legacy/state/application/hooks'
import { ApplicationModal } from 'legacy/state/application/reducer'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useSetAtom } from 'jotai'
import React, { ReactNode, useCallback, useEffect } from 'react'

import { Currency } from '@uniswap/sdk-core'

import { getActivityState, useActivityDerivedState } from 'legacy/hooks/useActivityDerivedState'
import { useMultipleActivityDescriptors } from 'legacy/hooks/useRecentActivity'
import { handleFollowPendingTxPopupAtom, useSetAtom } from 'legacy/state/application/atoms'
import { handleFollowPendingTxPopupAtom } from 'legacy/state/application/atoms'

import { useSetIsConfirmationModalOpen } from 'modules/swap/state/surplusModal'
import { useWalletInfo } from 'modules/wallet'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { computeSlippageAdjustedAmounts } from 'legacy/utils/prices'

import { useHigherUSDValue } from 'modules/fiatAmount'
import { PriceUpdatedBanner } from 'modules/trade/pure/PriceUpdatedBanner'
import { useTradeUsdAmounts } from 'modules/usdAmount'

import { CurrencyLogo } from 'common/pure/CurrencyLogo'
import { FiatValue } from 'common/pure/FiatValue'
Expand Down Expand Up @@ -100,8 +101,10 @@ export default function SwapModalHeader({

const theme = useContext(ThemeContext)

const fiatValueInput = useHigherUSDValue(trade.inputAmountWithoutFee).value
const fiatValueOutput = useHigherUSDValue(trade.outputAmountWithoutFee).value
const {
inputAmount: { value: fiatValueInput },
outputAmount: { value: fiatValueOutput },
} = useTradeUsdAmounts(trade.inputAmountWithoutFee, trade.outputAmountWithoutFee)

const [slippageIn, slippageOut] = useMemo(
() => [slippageAdjustedAmounts[Field.INPUT], slippageAdjustedAmounts[Field.OUTPUT]],
Expand Down
Loading
Loading