-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7075972
commit bea3425
Showing
2 changed files
with
33 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,54 @@ | ||
import { ChainId } from '@kyberswap/ks-sdk-core' | ||
import { Trans, t } from '@lingui/macro' | ||
import { Trans } from '@lingui/macro' | ||
import { FC } from 'react' | ||
import { Text } from 'rebass' | ||
|
||
import PriceImpactNote from 'components/SwapForm/PriceImpactNote' | ||
import WarningNote from 'components/WarningNote' | ||
import { useActiveWeb3React } from 'hooks' | ||
import useTheme from 'hooks/useTheme' | ||
import { useSwitchPairToLimitOrder } from 'state/swap/hooks' | ||
import { checkPriceImpact } from 'utils/prices' | ||
|
||
type Props = { | ||
gasUsd?: string | ||
priceImpact?: number | ||
isDegenMode: boolean | ||
} | ||
|
||
const GAS_USD_THRESHOLD = 20 | ||
const GasPriceNote: FC<Props> = ({ gasUsd = 0 }) => { | ||
const GasFeeAndPriceImpactNote: FC<Props> = ({ gasUsd = 0, priceImpact, isDegenMode }) => { | ||
const theme = useTheme() | ||
|
||
const { chainId } = useActiveWeb3React() | ||
const switchToLimitOrder = useSwitchPairToLimitOrder() | ||
if (+gasUsd < GAS_USD_THRESHOLD || chainId !== ChainId.MAINNET) return null | ||
const { isHigh, isVeryHigh } = checkPriceImpact(priceImpact) | ||
|
||
if (+gasUsd < GAS_USD_THRESHOLD || chainId !== ChainId.MAINNET) | ||
return <PriceImpactNote priceImpact={priceImpact} isDegenMode={isDegenMode} showLimitOrderLink /> | ||
|
||
const limitOrderLink = ( | ||
<Trans> | ||
Do you want to make a{' '} | ||
<Text as="span" sx={{ cursor: 'pointer', fontWeight: 'bold' }} color={theme.primary} onClick={switchToLimitOrder}> | ||
Limit Order | ||
</Text>{' '} | ||
instead? | ||
</Trans> | ||
) | ||
return ( | ||
<WarningNote | ||
shortText={t`Gas fee is higher than $${GAS_USD_THRESHOLD}.`} | ||
longText={ | ||
shortText={ | ||
<Text> | ||
<Trans> | ||
Do you want to make a{' '} | ||
<Text as="b" sx={{ cursor: 'pointer' }} color={theme.primary} onClick={switchToLimitOrder}> | ||
Limit Order | ||
</Text>{' '} | ||
instead? | ||
</Trans> | ||
{isHigh || isVeryHigh ? ( | ||
<Trans>Gas fees and Price Impact are very high. You will lose your funds.</Trans> | ||
) : ( | ||
<Trans>Gas fees is very high. You will lose your funds.</Trans> | ||
)}{' '} | ||
{limitOrderLink} | ||
</Text> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
export default GasPriceNote | ||
export default GasFeeAndPriceImpactNote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters