Skip to content

Commit

Permalink
fix(twap): display "Minimum sell size" banner only when there is a bu…
Browse files Browse the repository at this point in the history
…y amount (#3064)
  • Loading branch information
shoom3301 authored Aug 19, 2023
1 parent f29ed79 commit 60c7e36
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function TwapFormWarnings({ localFormValidation, isConfirmationModal }: T
return <UnsupportedWalletWarning isSafeViaWc={isSafeViaWc} />
}

if (chainId && localFormValidation === TwapFormState.SELL_AMOUNT_TOO_SMALL) {
if (localFormValidation === TwapFormState.SELL_AMOUNT_TOO_SMALL) {
return <SmallPartVolumeWarning chainId={chainId} />
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { CurrencyAmount } from '@uniswap/sdk-core'

import { COW } from 'legacy/constants/tokens'
import { WETH_GOERLI } from 'legacy/utils/goerli/constants'

import { getTwapFormState, TwapFormState } from './getTwapFormState'

import { ExtensibleFallbackVerification } from '../../services/verifyExtensibleFallback'
import { TWAPOrder } from '../../types'

const COW_GOERLI = COW[5]

const twapOrder: TWAPOrder = {
sellAmount: CurrencyAmount.fromRawAmount(WETH_GOERLI, 10000000),
buyAmount: CurrencyAmount.fromRawAmount(COW_GOERLI, 10000000),
receiver: '0x00000000000000001',
numOfParts: 1,
startTime: 1000000,
timeInterval: 200,
span: 0,
appData: '0x000000',
}

describe('getTwapFormState()', () => {
describe('When sell fiat amount is under threshold', () => {
it('And order has buy amount, then should return SELL_AMOUNT_TOO_SMALL', () => {
const result = getTwapFormState({
isSafeApp: true,
verification: ExtensibleFallbackVerification.HAS_DOMAIN_VERIFIER,
twapOrder: { ...twapOrder },
sellAmountPartFiat: CurrencyAmount.fromRawAmount(WETH_GOERLI, 10000000),
chainId: 1,
partTime: 1000000,
})

expect(result).toEqual(TwapFormState.SELL_AMOUNT_TOO_SMALL)
})

it('And order does NOT have buy amount, then should return null', () => {
const result = getTwapFormState({
isSafeApp: true,
verification: ExtensibleFallbackVerification.HAS_DOMAIN_VERIFIER,
twapOrder: { ...twapOrder, buyAmount: CurrencyAmount.fromRawAmount(COW_GOERLI, 0) },
sellAmountPartFiat: CurrencyAmount.fromRawAmount(WETH_GOERLI, 10000000),
chainId: 1,
partTime: 1000000,
})

expect(result).toEqual(null)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Currency, CurrencyAmount } from '@uniswap/sdk-core'

import { Nullish } from 'types'

import { isFractionFalsy } from 'utils/isFractionFalsy'

import { ExtensibleFallbackVerification } from '../../services/verifyExtensibleFallback'
import { TWAPOrder } from '../../types'
import { isPartTimeIntervalTooShort } from '../../utils/isPartTimeIntervalTooShort'
Expand All @@ -25,13 +27,13 @@ export enum TwapFormState {
}

export function getTwapFormState(props: TwapFormStateParams): TwapFormState | null {
const { isSafeApp, verification, sellAmountPartFiat, chainId, partTime } = props
const { twapOrder, isSafeApp, verification, sellAmountPartFiat, chainId, partTime } = props

if (!isSafeApp) return TwapFormState.NOT_SAFE

if (verification === null) return TwapFormState.LOADING_SAFE_INFO

if (isSellAmountTooSmall(sellAmountPartFiat, chainId)) {
if (!isFractionFalsy(twapOrder?.buyAmount) && isSellAmountTooSmall(sellAmountPartFiat, chainId)) {
return TwapFormState.SELL_AMOUNT_TOO_SMALL
}

Expand Down

0 comments on commit 60c7e36

Please sign in to comment.