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

limit order: update gas fee note + add tracking event #2339

Merged
merged 3 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.15.0
v20.9.0
53 changes: 39 additions & 14 deletions src/components/SwapForm/GasPriceNote.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,66 @@
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 useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
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)
const { mixpanelHandler } = useMixpanel()

if (+gasUsd < GAS_USD_THRESHOLD || chainId !== ChainId.MAINNET)
return <PriceImpactNote priceImpact={priceImpact} isDegenMode={isDegenMode} showLimitOrderLink />

const limitOrderLink = (
<Text>
<Trans>
Do you want to make a{' '}
<Text
as="span"
sx={{ cursor: 'pointer', fontWeight: 'bold' }}
color={theme.primary}
onClick={() => {
mixpanelHandler(MIXPANEL_TYPE.LO_CLICK_WARNING_IN_SWAP)
switchToLimitOrder()
}}
>
Limit Order
</Text>{' '}
instead?
</Trans>
</Text>
)
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>
)}
</Text>
}
longText={limitOrderLink}
/>
)
}

export default GasPriceNote
export default GasFeeAndPriceImpactNote
14 changes: 12 additions & 2 deletions src/components/SwapForm/PriceImpactNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styled from 'styled-components'
import Column from 'components/Column'
import Row from 'components/Row'
import WarningNote from 'components/WarningNote'
import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel'
import useTheme from 'hooks/useTheme'
import { useSwitchPairToLimitOrder } from 'state/swap/hooks'
import { checkPriceImpact } from 'utils/prices'
Expand Down Expand Up @@ -38,6 +39,7 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
const priceImpactResult = checkPriceImpact(priceImpact)
const theme = useTheme()
const switchToLimitOrder = useSwitchPairToLimitOrder()
const { mixpanelHandler } = useMixpanel()

if (typeof priceImpact !== 'number') {
return null
Expand Down Expand Up @@ -81,7 +83,15 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
<Text>
<Trans>
Do you want to make a{' '}
<Text as="b" sx={{ cursor: 'pointer' }} color={theme.primary} onClick={switchToLimitOrder}>
<Text
as="b"
sx={{ cursor: 'pointer' }}
color={theme.primary}
onClick={() => {
mixpanelHandler(MIXPANEL_TYPE.LO_CLICK_WARNING_IN_SWAP)
switchToLimitOrder()
}}
>
Limit Order
</Text>{' '}
instead?
Expand All @@ -108,6 +118,7 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
}
longText={
<Column gap="4px">
{limitOrderNote}
<Text>
{isDegenMode ? (
<Trans>
Expand All @@ -120,7 +131,6 @@ const PriceImpactNote: FC<Props> = ({ isDegenMode, priceImpact, showLimitOrderLi
</Trans>
)}
</Text>
{limitOrderNote}
</Column>
}
/>
Expand Down
11 changes: 6 additions & 5 deletions src/components/SwapForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import AddressInputPanel from 'components/AddressInputPanel'
import { Clock } from 'components/Icons'
import { AutoRow } from 'components/Row'
import SlippageWarningNote from 'components/SlippageWarningNote'
import GasPriceNote from 'components/SwapForm/GasPriceNote'
import GasFeeAndPriceImpactNote from 'components/SwapForm/GasPriceNote'
import InputCurrencyPanel from 'components/SwapForm/InputCurrencyPanel'
import OutputCurrencyPanel from 'components/SwapForm/OutputCurrencyPanel'
import SlippageSettingGroup from 'components/SwapForm/SlippageSettingGroup'
Expand All @@ -37,7 +37,6 @@ import { MEDIA_WIDTHS } from 'theme'
import { DetailedRouteSummary } from 'types/route'
import { currencyId } from 'utils/currencyId'

import PriceImpactNote from './PriceImpactNote'
import RefreshButton from './RefreshButton'
import ReverseTokenSelectionButton from './ReverseTokenSelectionButton'
import SwapActionButton from './SwapActionButton'
Expand Down Expand Up @@ -260,9 +259,11 @@ const SwapForm: React.FC<SwapFormProps> = props => {

{!isWrapOrUnwrap && <SlippageWarningNote rawSlippage={slippage} isStablePairSwap={isStablePairSwap} />}

<PriceImpactNote priceImpact={routeSummary?.priceImpact} isDegenMode={isDegenMode} showLimitOrderLink />

<GasPriceNote gasUsd={routeSummary?.gasUsd} />
<GasFeeAndPriceImpactNote
gasUsd={routeSummary?.gasUsd}
priceImpact={routeSummary?.priceImpact}
isDegenMode={isDegenMode}
/>

<SwapActionButton
isGettingRoute={isGettingRoute}
Expand Down
5 changes: 5 additions & 0 deletions src/hooks/useMixpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export enum MIXPANEL_TYPE {
LO_CLICK_CANCEL_TYPE,
LO_CLICK_UPDATE_TYPE,
LO_CLICK_GET_STARTED,
LO_CLICK_WARNING_IN_SWAP,

// Wallet UI
WUI_WALLET_CLICK,
Expand Down Expand Up @@ -1138,6 +1139,10 @@ export default function useMixpanel(currencies?: { [field in Field]?: Currency }
mixpanel.track('Limit Order - Get Started Click', payload)
break
}
case MIXPANEL_TYPE.LO_CLICK_WARNING_IN_SWAP: {
mixpanel.track('Limit Order - Warning in Swap Click', payload)
break
}

case MIXPANEL_TYPE.WUI_WALLET_CLICK: {
mixpanel.track('Wallet UI - Wallet Click')
Expand Down
Loading