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

Fix conedison dependency issue #589

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = {
// Jest does not always resolve src/test (probably because of babel's TypeScript transpilation):
'^test/*': '<rootDir>/src/test',

'@uniswap/conedison/format': '@uniswap/conedison/dist/format.js',
'@uniswap/conedison/provider': '@uniswap/conedison/dist/provider/index.js',
'utils/conedison/format': 'utils/conedison/dist/format.js',
'utils/conedison/provider': 'utils/conedison/dist/provider/index.js',
},
setupFiles: ['<rootDir>/test/setup.ts'],
setupFilesAfterEnv: ['jest-extended/all', '<rootDir>/test/setup-jest.ts'],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"@fontsource/inter": "^4.5.1",
"@popperjs/core": "^2.4.4",
"@reduxjs/toolkit": "^1.6.1",
"@uniswap/conedison": "^1.5.3",
"@uniswap/permit2-sdk": "^1.2.0",
"@uniswap/redux-multicall": "^1.1.8",
"@uniswap/router-sdk": "^1.3.0",
Expand All @@ -72,6 +71,8 @@
"@uniswap/universal-router-sdk": "^1.3.8",
"@uniswap/v2-sdk": "^3.0.1",
"@uniswap/v3-sdk": "^3.8.2",
"@walletconnect/ethereum-provider-v1": "npm:@walletconnect/ethereum-provider@^1.8.0",
"@walletconnect/ethereum-provider-v2": "npm:@walletconnect/ethereum-provider@^2.4.6",
"@web3-react/core": "^8.2.0",
"@web3-react/eip1193": "^8.2.0",
"@web3-react/empty": "^8.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { t, Trans } from '@lingui/macro'
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
import { TextButton } from 'components/Button'
import { loadingTransitionCss } from 'css/loading'
Expand All @@ -14,6 +13,7 @@ import { TradeState } from 'state/routing/types'
import { Field } from 'state/swap'
import styled from 'styled-components/macro'
import { AnimationSpeed, ThemedText } from 'theme'
import { formatCurrencyAmount, NumberType } from 'utils/conedison/format'
import { maxAmountSpend } from 'utils/maxAmountSpend'

import Column from '../Column'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Price.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { formatCurrencyAmount, formatPrice, NumberType } from '@uniswap/conedison/format'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
import Row from 'components/Row'
import { useCallback, useMemo, useState } from 'react'
import { InterfaceTrade } from 'state/routing/types'
import { formatCurrencyAmount, formatPrice, NumberType } from 'utils/conedison/format'
import { ThemedText } from 'theme'

import { TextButton } from '../Button'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/PriceImpactRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Trans } from '@lingui/macro'
import { formatPriceImpact } from '@uniswap/conedison/format'
import { formatPriceImpact } from 'utils/conedison/format'
import Row from 'components/Row'
import Tooltip, { SmallToolTipBody, TooltipText } from 'components/Tooltip'
import { PriceImpact } from 'hooks/usePriceImpact'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/RoutingDiagram/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Trans } from '@lingui/macro'
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
import { formatCurrencyAmount, NumberType } from 'utils/conedison/format'
import { Protocol } from '@uniswap/router-sdk'
import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core'
import { FeeAmount } from '@uniswap/v3-sdk'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Summary/Details.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from '@lingui/macro'
import { formatCurrencyAmount, formatPriceImpact, NumberType } from '@uniswap/conedison/format'
import { formatCurrencyAmount, formatPriceImpact, NumberType } from 'utils/conedison/format'
import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core'
import Column from 'components/Column'
import { useIsDialogPageCentered } from 'components/Dialog'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Summary/Estimate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from '@lingui/macro'
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
import { formatCurrencyAmount, NumberType } from 'utils/conedison/format'
import { formatSlippage, Slippage } from 'hooks/useSlippage'
import { ReactNode, useMemo } from 'react'
import { InterfaceTrade } from 'state/routing/types'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Summary/Summary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatPriceImpact } from '@uniswap/conedison/format'
import { formatPriceImpact } from 'utils/conedison/format'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
import { PriceImpact } from 'hooks/usePriceImpact'
import { ArrowDown, ArrowRight } from 'icons'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Summary/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t, Trans } from '@lingui/macro'
import { formatPriceImpact } from '@uniswap/conedison/format'
import { formatPriceImpact } from 'utils/conedison/format'
import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core'
import ActionButton, { Action, ActionButtonColor } from 'components/ActionButton'
import Column from 'components/Column'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Toolbar/GasEstimateTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatCurrencyAmount, NumberType } from '@uniswap/conedison/format'
import { formatCurrencyAmount, NumberType } from 'utils/conedison/format'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { BottomSheetModal } from 'components/BottomSheetModal'
import Column from 'components/Column'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Swap/Toolbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t, Trans } from '@lingui/macro'
import { formatCurrencyAmount, formatPriceImpact, NumberType } from '@uniswap/conedison/format'
import { formatCurrencyAmount, formatPriceImpact, NumberType } from 'utils/conedison/format'
import ActionButton from 'components/ActionButton'
import Column from 'components/Column'
import Expando from 'components/Expando'
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePermitAllowance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { t } from '@lingui/macro'
import { signTypedData } from '@uniswap/conedison/provider/signing'
import { AllowanceTransfer, MaxAllowanceTransferAmount, PERMIT2_ADDRESS, PermitSingle } from '@uniswap/permit2-sdk'
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
Expand All @@ -10,6 +9,7 @@ import { useSingleCallResult } from 'hooks/multicall'
import { useContract } from 'hooks/useContract'
import ms from 'ms.macro'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { signTypedData } from 'utils/conedison/provider/signing'
import { isUserRejection } from 'utils/jsonRpcError'

import { usePerfEventHandler } from './usePerfEventHandler'
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePriceImpact.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatPriceImpact } from '@uniswap/conedison/format'
import { formatPriceImpact } from 'utils/conedison/format'
import { CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { InterfaceTrade } from 'state/routing/types'
import { renderHook } from 'test'
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSlippage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatPriceImpact } from '@uniswap/conedison/format'
import { formatPriceImpact } from 'utils/conedison/format'
import { CurrencyAmount, Percent, Token } from '@uniswap/sdk-core'
import useAutoSlippageTolerance, { DEFAULT_AUTO_SLIPPAGE } from 'hooks/useAutoSlippageTolerance'
import { useAtomValue } from 'jotai/utils'
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useUniversalRouter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransactionResponse } from '@ethersproject/abstract-provider'
import { sendTransaction } from '@uniswap/conedison/provider/index'
import { sendTransaction } from 'utils/conedison/provider/index'
import { TradeType } from '@uniswap/sdk-core'
import { SwapRouter, UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk'
import { SupportedChainId } from 'constants/chains'
Expand All @@ -22,7 +22,7 @@ const SWAP_TRANSACTION_INFO = {
slippageTolerance: OPTIONS.slippageTolerance,
}

jest.mock('@uniswap/conedison/provider/index', () => ({
jest.mock('utils/conedison/provider/index', () => ({
sendTransaction: jest.fn().mockResolvedValue(RESPONSE),
}))

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useUniversalRouter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber'
import { t } from '@lingui/macro'
import { sendTransaction } from '@uniswap/conedison/provider/index'
import { sendTransaction } from 'utils/conedison/provider/index'
import { Percent } from '@uniswap/sdk-core'
import { SwapRouter, UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk'
import { FeeOptions, toHex } from '@uniswap/v3-sdk'
Expand Down
184 changes: 184 additions & 0 deletions src/utils/conedison/format.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import { Percent } from '@uniswap/sdk-core'

import { formatNumber, formatPriceImpact, formatSlippage, formatUSDPrice, NumberType } from './format'

it('formats token reference numbers correctly', () => {
expect(formatNumber(1234567000000000, NumberType.TokenNonTx)).toBe('>999T')
expect(formatNumber(1002345, NumberType.TokenNonTx)).toBe('1.00M')
expect(formatNumber(1234, NumberType.TokenNonTx)).toBe('1,234.00')
expect(formatNumber(0.00909, NumberType.TokenNonTx)).toBe('0.009')
expect(formatNumber(0.09001, NumberType.TokenNonTx)).toBe('0.090')
expect(formatNumber(0.00099, NumberType.TokenNonTx)).toBe('<0.001')
expect(formatNumber(0, NumberType.TokenNonTx)).toBe('0')
})

it('formats token transaction numbers correctly', () => {
expect(formatNumber(1234567.8901, NumberType.TokenTx)).toBe('1,234,567.89')
expect(formatNumber(765432.1, NumberType.TokenTx)).toBe('765,432.10')

expect(formatNumber(7654.321, NumberType.TokenTx)).toBe('7,654.32')
expect(formatNumber(765.4321, NumberType.TokenTx)).toBe('765.432')
expect(formatNumber(76.54321, NumberType.TokenTx)).toBe('76.5432')
expect(formatNumber(7.654321, NumberType.TokenTx)).toBe('7.65432')
expect(formatNumber(7.60000054321, NumberType.TokenTx)).toBe('7.60')
expect(formatNumber(7.6, NumberType.TokenTx)).toBe('7.60')
expect(formatNumber(7, NumberType.TokenTx)).toBe('7.00')

expect(formatNumber(0.987654321, NumberType.TokenTx)).toBe('0.98765')
expect(formatNumber(0.9, NumberType.TokenTx)).toBe('0.90')
expect(formatNumber(0.901000123, NumberType.TokenTx)).toBe('0.901')
expect(formatNumber(0.000000001, NumberType.TokenTx)).toBe('<0.00001')
expect(formatNumber(0, NumberType.TokenTx)).toBe('0')
})

it('formats fiat estimates on token details pages correctly', () => {
expect(formatNumber(1234567.891, NumberType.FiatTokenDetails)).toBe('$1.23M')
expect(formatNumber(1234.5678, NumberType.FiatTokenDetails)).toBe('$1,234.57')
expect(formatNumber(1.048942, NumberType.FiatTokenDetails)).toBe('$1.049')

expect(formatNumber(0.001231, NumberType.FiatTokenDetails)).toBe('$0.00123')
expect(formatNumber(0.00001231, NumberType.FiatTokenDetails)).toBe('$0.0000123')

expect(formatNumber(0.0000001234, NumberType.FiatTokenDetails)).toBe('$0.000000123')
expect(formatNumber(0.000000009876, NumberType.FiatTokenDetails)).toBe('<$0.00000001')
})

it('formats fiat estimates for tokens correctly', () => {
expect(formatNumber(1234567.891, NumberType.FiatTokenPrice)).toBe('$1.23M')
expect(formatNumber(1234.5678, NumberType.FiatTokenPrice)).toBe('$1,234.57')

expect(formatNumber(0.010235, NumberType.FiatTokenPrice)).toBe('$0.0102')
expect(formatNumber(0.001231, NumberType.FiatTokenPrice)).toBe('$0.00123')
expect(formatNumber(0.00001231, NumberType.FiatTokenPrice)).toBe('$0.0000123')

expect(formatNumber(0.0000001234, NumberType.FiatTokenPrice)).toBe('$0.000000123')
expect(formatNumber(0.000000009876, NumberType.FiatTokenPrice)).toBe('<$0.00000001')
})

it('formats fiat estimates for token stats correctly', () => {
expect(formatNumber(1234576, NumberType.FiatTokenStats)).toBe('$1.2M')
expect(formatNumber(234567, NumberType.FiatTokenStats)).toBe('$234.6K')
expect(formatNumber(123.456, NumberType.FiatTokenStats)).toBe('$123.46')
expect(formatNumber(1.23, NumberType.FiatTokenStats)).toBe('$1.23')
expect(formatNumber(0.123, NumberType.FiatTokenStats)).toBe('$0.12')
expect(formatNumber(0.00123, NumberType.FiatTokenStats)).toBe('<$0.01')
expect(formatNumber(0, NumberType.FiatTokenStats)).toBe('-')
})

it('formats gas USD prices correctly', () => {
expect(formatNumber(1234567.891, NumberType.FiatGasPrice)).toBe('$1.23M')
expect(formatNumber(18.448, NumberType.FiatGasPrice)).toBe('$18.45')
expect(formatNumber(0.0099, NumberType.FiatGasPrice)).toBe('<$0.01')
})

it('formats USD token quantities prices correctly', () => {
expect(formatNumber(1234567.891, NumberType.FiatTokenQuantity)).toBe('$1.23M')
expect(formatNumber(18.448, NumberType.FiatTokenQuantity)).toBe('$18.45')
expect(formatNumber(0.0099, NumberType.FiatTokenQuantity)).toBe('<$0.01')
expect(formatNumber(0, NumberType.FiatTokenQuantity)).toBe('$0.00')
})

it('formats Swap text input/output numbers correctly', () => {
expect(formatNumber(1234567.8901, NumberType.SwapTradeAmount)).toBe('1234570')
expect(formatNumber(765432.1, NumberType.SwapTradeAmount)).toBe('765432')

expect(formatNumber(7654.321, NumberType.SwapTradeAmount)).toBe('7654.32')
expect(formatNumber(765.4321, NumberType.SwapTradeAmount)).toBe('765.432')
expect(formatNumber(76.54321, NumberType.SwapTradeAmount)).toBe('76.5432')
expect(formatNumber(7.654321, NumberType.SwapTradeAmount)).toBe('7.65432')
expect(formatNumber(7.60000054321, NumberType.SwapTradeAmount)).toBe('7.60')
expect(formatNumber(7.6, NumberType.SwapTradeAmount)).toBe('7.60')
expect(formatNumber(7, NumberType.SwapTradeAmount)).toBe('7.00')

expect(formatNumber(0.987654321, NumberType.SwapTradeAmount)).toBe('0.98765')
expect(formatNumber(0.9, NumberType.SwapTradeAmount)).toBe('0.90')
expect(formatNumber(0.901000123, NumberType.SwapTradeAmount)).toBe('0.901')
expect(formatNumber(0.000000001, NumberType.SwapTradeAmount)).toBe('0.000000001')
expect(formatNumber(0, NumberType.SwapTradeAmount)).toBe('0')
})

it('formats NFT numbers correctly', () => {
expect(formatNumber(1234567000000000, NumberType.NFTTokenFloorPrice)).toBe('>999T')
expect(formatNumber(1002345, NumberType.NFTTokenFloorPrice)).toBe('1M')
expect(formatNumber(1234, NumberType.NFTTokenFloorPrice)).toBe('1.23K')
expect(formatNumber(12.34467, NumberType.NFTTokenFloorPrice)).toBe('12.34')
expect(formatNumber(12.1, NumberType.NFTTokenFloorPrice)).toBe('12.1')
expect(formatNumber(0.00909, NumberType.NFTTokenFloorPrice)).toBe('0.009')
expect(formatNumber(0.09001, NumberType.NFTTokenFloorPrice)).toBe('0.09')
expect(formatNumber(0.00099, NumberType.NFTTokenFloorPrice)).toBe('<0.001')
expect(formatNumber(0, NumberType.NFTTokenFloorPrice)).toBe('0')

expect(formatNumber(12.1, NumberType.NFTTokenFloorPriceTrailingZeros)).toBe('12.10')
expect(formatNumber(0.09001, NumberType.NFTTokenFloorPriceTrailingZeros)).toBe('0.090')

expect(formatNumber(0.987654321, NumberType.NFTCollectionStats)).toBe('0.98765')
expect(formatNumber(0.9, NumberType.NFTCollectionStats)).toBe('0.9')
expect(formatNumber(76543.21, NumberType.NFTCollectionStats)).toBe('76543.2')
expect(formatNumber(7.60000054321, NumberType.NFTCollectionStats)).toBe('7.6')
expect(formatNumber(1234567890, NumberType.NFTCollectionStats)).toBe('1.23457B')
expect(formatNumber(1234567000000000, NumberType.NFTCollectionStats)).toBe('>999T')
})

describe('formatUSDPrice', () => {
it('should correctly format 0.000000009876', () => {
expect(formatUSDPrice(0.000000009876)).toBe('<$0.00000001')
})
it('should correctly format 0.00001231', () => {
expect(formatUSDPrice(0.00001231)).toBe('$0.0000123')
})
it('should correctly format 0.001231', () => {
expect(formatUSDPrice(0.001231)).toBe('$0.00123')
})
it('should correctly format 0.0', () => {
expect(formatUSDPrice(0.0)).toBe('$0.00')
})
it('should correctly format 0', () => {
expect(formatUSDPrice(0)).toBe('$0.00')
})
it('should correctly format 1.048942', () => {
expect(formatUSDPrice(1.048942)).toBe('$1.049')
})
it('should correctly format 0.10235', () => {
expect(formatUSDPrice(0.10235)).toBe('$0.102')
})
it('should correctly format 1234.5678', () => {
expect(formatUSDPrice(1_234.5678)).toBe('$1,234.57')
})
it('should correctly format 1234567.8910', () => {
expect(formatUSDPrice(1_234_567.891)).toBe('$1.23M')
})
it('should correctly format 1000000000000', () => {
expect(formatUSDPrice(1_000_000_000_000)).toBe('$1.00T')
})
it('should correctly format 1000000000000000', () => {
expect(formatUSDPrice(1_000_000_000_000_000)).toBe('>$999T')
})
})

describe('formatPriceImpact', () => {
it('should correctly format undefined', () => {
expect(formatPriceImpact(undefined)).toBe('-')
})

it('correctly formats a percent with 3 significant digits', () => {
expect(formatPriceImpact(new Percent(-1, 100000))).toBe('0.001%')
expect(formatPriceImpact(new Percent(-1, 1000))).toBe('0.100%')
expect(formatPriceImpact(new Percent(-1, 100))).toBe('1.000%')
expect(formatPriceImpact(new Percent(-1, 10))).toBe('10.000%')
expect(formatPriceImpact(new Percent(-1, 1))).toBe('100.000%')
})
})

describe('formatSlippage', () => {
it('should correctly format undefined', () => {
expect(formatSlippage(undefined)).toBe('-')
})

it('correctly formats a percent with 3 significant digits', () => {
expect(formatSlippage(new Percent(1, 100000))).toBe('0.001%')
expect(formatSlippage(new Percent(1, 1000))).toBe('0.100%')
expect(formatSlippage(new Percent(1, 100))).toBe('1.000%')
expect(formatSlippage(new Percent(1, 10))).toBe('10.000%')
expect(formatSlippage(new Percent(1, 1))).toBe('100.000%')
})
})