mango-v4-ui/components/swap/SwapForm.tsx

595 lines
20 KiB
TypeScript
Raw Normal View History

2022-08-17 18:26:38 -07:00
import { useState, useCallback, useEffect, useMemo } from 'react'
2022-08-19 21:03:26 -07:00
import { PublicKey } from '@solana/web3.js'
2022-08-25 17:27:05 -07:00
import {
ArrowDownIcon,
2023-01-03 19:12:30 -08:00
Cog8ToothIcon,
2022-08-25 17:27:05 -07:00
ExclamationCircleIcon,
2022-10-22 05:14:25 -07:00
LinkIcon,
2022-09-06 21:36:35 -07:00
} from '@heroicons/react/20/solid'
import NumberFormat, {
NumberFormatValues,
SourceInfo,
} from 'react-number-format'
2022-08-17 18:26:38 -07:00
import Decimal from 'decimal.js'
2022-09-12 08:53:57 -07:00
import mangoStore from '@store/mangoStore'
2022-07-05 20:37:49 -07:00
import ContentBox from '../shared/ContentBox'
import SwapReviewRouteInfo from './SwapReviewRouteInfo'
2022-09-01 10:33:29 -07:00
import TokenSelect from './TokenSelect'
2022-07-05 20:37:49 -07:00
import useDebounce from '../shared/useDebounce'
2022-07-15 05:50:29 -07:00
import { useTranslation } from 'next-i18next'
import SwapFormTokenList from './SwapFormTokenList'
2022-07-16 04:22:59 -07:00
import { Transition } from '@headlessui/react'
import Button, { IconButton, LinkButton } from '../shared/Button'
2022-07-18 03:02:43 -07:00
import Loading from '../shared/Loading'
2022-07-23 19:48:26 -07:00
import { EnterBottomExitBottom } from '../shared/Transitions'
import useQuoteRoutes from './useQuoteRoutes'
2022-08-25 06:00:42 -07:00
import { HealthType } from '@blockworks-foundation/mango-v4'
2022-08-20 11:17:57 -07:00
import {
INPUT_TOKEN_DEFAULT,
2022-11-18 11:11:06 -08:00
MANGO_MINT,
2022-08-20 11:17:57 -07:00
OUTPUT_TOKEN_DEFAULT,
SIZE_INPUT_UI_KEY,
2022-11-18 11:11:06 -08:00
USDC_MINT,
2022-08-20 11:17:57 -07:00
} from '../../utils/constants'
import { useTokenMax } from './useTokenMax'
2022-11-04 11:55:21 -07:00
import HealthImpact from '@components/shared/HealthImpact'
2022-11-15 20:12:51 -08:00
import { useWallet } from '@solana/wallet-adapter-react'
2022-11-18 09:09:39 -08:00
import useMangoAccount from 'hooks/useMangoAccount'
2022-11-18 11:11:06 -08:00
import { RouteInfo } from 'types/jupiter'
2022-11-21 20:20:05 -08:00
import useMangoGroup from 'hooks/useMangoGroup'
import useLocalStorageState from 'hooks/useLocalStorageState'
import SwapSlider from './SwapSlider'
2022-11-27 04:36:12 -08:00
import TokenVaultWarnings from '@components/shared/TokenVaultWarnings'
import MaxSwapAmount from './MaxSwapAmount'
import PercentageSelectButtons from './PercentageSelectButtons'
2022-12-19 13:58:22 -08:00
import useIpAddress from 'hooks/useIpAddress'
2023-01-03 03:06:37 -08:00
import { useEnhancedWallet } from '@components/wallet/EnhancedWalletProvider'
2023-01-03 19:12:30 -08:00
import SwapSettings from './SwapSettings'
2023-02-04 13:55:42 -08:00
import InlineNotification from '@components/shared/InlineNotification'
import useUnownedAccount from 'hooks/useUnownedAccount'
import Tooltip from '@components/shared/Tooltip'
2022-07-18 03:02:43 -07:00
2022-08-17 18:26:38 -07:00
const MAX_DIGITS = 11
export const withValueLimit = (values: NumberFormatValues): boolean => {
2022-08-17 18:26:38 -07:00
return values.floatValue
? values.floatValue.toFixed(0).length <= MAX_DIGITS
: true
}
const NUMBER_FORMAT_CLASSNAMES =
2023-04-19 18:12:45 -07:00
'w-full rounded-lg rounded-l-none border border-th-input-border bg-th-input-bkg p-3 text-right font-mono text-xl text-th-fgd-1 focus:border-th-fgd-4 focus:outline-none md:hover:border-th-input-border-hover md:hover:focus-visible:border-th-fgd-4'
2022-12-08 10:44:19 -08:00
const set = mangoStore.getState().set
2022-08-19 21:03:26 -07:00
const SwapForm = () => {
2022-12-08 03:15:16 -08:00
const { t } = useTranslation(['common', 'swap', 'trade'])
2023-02-04 13:55:42 -08:00
//initial state is undefined null is returned on error
const [selectedRoute, setSelectedRoute] = useState<RouteInfo | null>()
2022-07-22 08:40:53 -07:00
const [animateSwitchArrow, setAnimateSwitchArrow] = useState(0)
2023-02-27 23:20:11 -08:00
const [showTokenSelect, setShowTokenSelect] = useState<'input' | 'output'>()
2022-08-08 10:42:18 -07:00
const [showSettings, setShowSettings] = useState(false)
2022-07-17 19:49:14 -07:00
const [showConfirm, setShowConfirm] = useState(false)
2022-11-21 20:20:05 -08:00
const { group } = useMangoGroup()
2023-01-19 12:41:11 -08:00
const [swapFormSizeUi] = useLocalStorageState(SIZE_INPUT_UI_KEY, 'slider')
2022-12-19 13:58:22 -08:00
const { ipAllowed, ipCountry } = useIpAddress()
const { isUnownedAccount } = useUnownedAccount()
2022-11-18 11:11:06 -08:00
const {
margin: useMargin,
slippage,
inputBank,
outputBank,
amountIn: amountInFormValue,
amountOut: amountOutFormValue,
swapMode,
2022-11-18 11:11:06 -08:00
} = mangoStore((s) => s.swap)
const [debouncedAmountIn] = useDebounce(amountInFormValue, 300)
const [debouncedAmountOut] = useDebounce(amountOutFormValue, 300)
const { mangoAccount } = useMangoAccount()
const { isDelegatedAccount } = useUnownedAccount()
const { connected, publicKey } = useWallet()
2022-09-14 17:02:16 -07:00
const amountInAsDecimal: Decimal | null = useMemo(() => {
2022-09-01 10:33:29 -07:00
return Number(debouncedAmountIn)
? new Decimal(debouncedAmountIn)
: new Decimal(0)
}, [debouncedAmountIn])
const amountOutAsDecimal: Decimal | null = useMemo(() => {
return Number(debouncedAmountOut)
? new Decimal(debouncedAmountOut)
: new Decimal(0)
}, [debouncedAmountOut])
const { bestRoute, routes } = useQuoteRoutes({
2022-11-18 11:11:06 -08:00
inputMint: inputBank?.mint.toString() || USDC_MINT,
outputMint: outputBank?.mint.toString() || MANGO_MINT,
amount: swapMode === 'ExactIn' ? debouncedAmountIn : debouncedAmountOut,
2022-08-03 14:46:37 -07:00
slippage,
swapMode,
wallet: publicKey?.toBase58(),
2022-08-03 14:46:37 -07:00
})
2022-07-18 03:02:43 -07:00
const setAmountInFormValue = useCallback(
(amountIn: string, setSwapMode?: boolean) => {
set((s) => {
s.swap.amountIn = amountIn
if (!parseFloat(amountIn)) {
s.swap.amountOut = ''
}
if (setSwapMode) {
s.swap.swapMode = 'ExactIn'
}
})
},
[]
)
const setAmountOutFormValue = useCallback((amountOut: string) => {
set((s) => {
s.swap.amountOut = amountOut
2022-12-07 17:04:48 -08:00
if (!parseFloat(amountOut)) {
s.swap.amountIn = ''
}
})
}, [])
2022-11-18 11:11:06 -08:00
/*
Once a route is returned from the Jupiter API, use the inAmount or outAmount
depending on the swapMode and set those values in state
*/
2022-07-18 03:02:43 -07:00
useEffect(() => {
2023-02-04 13:55:42 -08:00
if (typeof bestRoute !== 'undefined') {
2022-11-18 11:11:06 -08:00
setSelectedRoute(bestRoute)
2023-02-04 13:55:42 -08:00
if (inputBank && swapMode === 'ExactOut' && bestRoute) {
const inAmount = new Decimal(bestRoute!.inAmount)
.div(10 ** inputBank.mintDecimals)
.toString()
setAmountInFormValue(inAmount)
2023-02-04 13:55:42 -08:00
} else if (outputBank && swapMode === 'ExactIn' && bestRoute) {
const outAmount = new Decimal(bestRoute!.outAmount)
.div(10 ** outputBank.mintDecimals)
.toString()
setAmountOutFormValue(outAmount)
}
2022-11-18 11:11:06 -08:00
}
}, [bestRoute, swapMode, inputBank, outputBank])
2022-07-18 03:02:43 -07:00
/*
If the use margin setting is toggled, clear the form values
*/
useEffect(() => {
setAmountInFormValue('')
setAmountOutFormValue('')
2022-12-08 10:44:19 -08:00
}, [useMargin, setAmountInFormValue, setAmountOutFormValue])
const handleAmountInChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
if (swapMode === 'ExactOut') {
2022-08-17 18:26:38 -07:00
set((s) => {
s.swap.swapMode = 'ExactIn'
2022-08-17 18:26:38 -07:00
})
}
setAmountInFormValue(e.value)
2022-08-17 18:26:38 -07:00
},
2022-12-08 10:44:19 -08:00
[swapMode, setAmountInFormValue]
2022-08-17 18:26:38 -07:00
)
2022-08-10 13:23:19 -07:00
const handleAmountOutChange = useCallback(
(e: NumberFormatValues, info: SourceInfo) => {
if (info.source !== 'event') return
if (swapMode === 'ExactIn') {
2022-08-17 18:26:38 -07:00
set((s) => {
s.swap.swapMode = 'ExactOut'
2022-08-17 18:26:38 -07:00
})
}
setAmountOutFormValue(e.value)
2022-08-17 18:26:38 -07:00
},
2022-12-08 10:44:19 -08:00
[swapMode, setAmountOutFormValue]
2022-08-17 18:26:38 -07:00
)
2022-07-05 20:37:49 -07:00
const handleTokenInSelect = useCallback((mintAddress: string) => {
const group = mangoStore.getState().group
if (group) {
const bank = group.getFirstBankByMint(new PublicKey(mintAddress))
set((s) => {
s.swap.inputBank = bank
})
}
2023-02-08 16:31:53 -08:00
setShowTokenSelect(undefined)
}, [])
const handleTokenOutSelect = useCallback((mintAddress: string) => {
const group = mangoStore.getState().group
if (group) {
const bank = group.getFirstBankByMint(new PublicKey(mintAddress))
set((s) => {
s.swap.outputBank = bank
})
}
2023-02-08 16:31:53 -08:00
setShowTokenSelect(undefined)
}, [])
2022-08-17 18:26:38 -07:00
const handleSwitchTokens = useCallback(() => {
if (amountInAsDecimal?.gt(0) && amountOutAsDecimal.gte(0)) {
setAmountInFormValue(amountOutAsDecimal.toString())
}
const inputBank = mangoStore.getState().swap.inputBank
const outputBank = mangoStore.getState().swap.outputBank
set((s) => {
s.swap.inputBank = outputBank
s.swap.outputBank = inputBank
})
2022-08-17 18:26:38 -07:00
setAnimateSwitchArrow(
(prevanimateSwitchArrow) => prevanimateSwitchArrow + 1
)
2022-12-08 10:44:19 -08:00
}, [setAmountInFormValue, amountOutAsDecimal, amountInAsDecimal])
2022-08-25 06:00:42 -07:00
const maintProjectedHealth = useMemo(() => {
const group = mangoStore.getState().group
if (
!inputBank ||
!mangoAccount ||
!outputBank ||
!amountOutAsDecimal ||
!group
)
2022-08-25 06:00:42 -07:00
return 0
const simulatedHealthRatio =
mangoAccount.simHealthRatioWithTokenPositionUiChanges(
group,
[
{
2022-11-18 11:11:06 -08:00
mintPk: inputBank.mint,
uiTokenAmount: amountInAsDecimal.toNumber() * -1,
2022-08-25 06:00:42 -07:00
},
{
2022-11-18 11:11:06 -08:00
mintPk: outputBank.mint,
2022-12-07 15:09:15 -08:00
uiTokenAmount: amountOutAsDecimal.toNumber(),
2022-08-25 06:00:42 -07:00
},
],
HealthType.maint
)
return simulatedHealthRatio > 100
2022-08-25 06:00:42 -07:00
? 100
: simulatedHealthRatio < 0
2022-08-25 06:00:42 -07:00
? 0
: Math.trunc(simulatedHealthRatio)
}, [
mangoAccount,
inputBank,
outputBank,
amountInAsDecimal,
amountOutAsDecimal,
])
2022-08-25 06:00:42 -07:00
const loadingSwapDetails: boolean = useMemo(() => {
2023-01-09 02:01:21 -08:00
return (
!!(amountInAsDecimal.toNumber() || amountOutAsDecimal.toNumber()) &&
connected &&
2023-02-04 13:55:42 -08:00
typeof selectedRoute === 'undefined'
2023-01-09 02:01:21 -08:00
)
}, [amountInAsDecimal, amountOutAsDecimal, connected, selectedRoute])
2022-08-25 12:44:02 -07:00
2022-07-05 20:37:49 -07:00
return (
<ContentBox
hidePadding
2022-10-30 22:02:55 -07:00
className="relative overflow-hidden border-x-0 md:border-l md:border-r-0 md:border-t-0 md:border-b-0"
>
2023-01-03 19:12:30 -08:00
<div>
2022-08-25 06:00:42 -07:00
<Transition
2023-04-20 23:10:09 -07:00
className="absolute top-0 right-0 z-10 h-full w-full bg-th-bkg-1 pb-0"
2022-08-25 06:00:42 -07:00
show={showConfirm}
enter="transition ease-in duration-300"
2023-04-20 23:10:09 -07:00
enterFrom="-translate-x-full"
2022-08-25 06:00:42 -07:00
enterTo="translate-x-0"
leave="transition ease-out duration-300"
leaveFrom="translate-x-0"
2023-04-20 23:10:09 -07:00
leaveTo="-translate-x-full"
2022-07-17 04:48:33 -07:00
>
<SwapReviewRouteInfo
2022-08-25 06:00:42 -07:00
onClose={() => setShowConfirm(false)}
amountIn={amountInAsDecimal}
2022-08-25 06:00:42 -07:00
slippage={slippage}
routes={routes}
selectedRoute={selectedRoute}
setSelectedRoute={setSelectedRoute}
2022-07-16 04:22:59 -07:00
/>
2022-08-25 06:00:42 -07:00
</Transition>
<EnterBottomExitBottom
2022-10-08 03:15:03 -07:00
className="thin-scroll absolute bottom-0 left-0 z-10 h-full w-full overflow-auto bg-th-bkg-1 p-6 pb-0"
2022-08-25 06:00:42 -07:00
show={!!showTokenSelect}
>
<SwapFormTokenList
2023-02-08 16:31:53 -08:00
onClose={() => setShowTokenSelect(undefined)}
2022-08-25 06:00:42 -07:00
onTokenSelect={
showTokenSelect === 'input'
? handleTokenInSelect
: handleTokenOutSelect
}
type={showTokenSelect}
2022-09-14 03:37:45 -07:00
useMargin={useMargin}
2022-07-15 05:50:29 -07:00
/>
2022-08-25 06:00:42 -07:00
</EnterBottomExitBottom>
2022-08-25 12:44:02 -07:00
<EnterBottomExitBottom
2022-10-08 03:15:03 -07:00
className="thin-scroll absolute bottom-0 left-0 z-10 h-full w-full overflow-auto bg-th-bkg-1 p-6 pb-0"
2022-08-25 12:44:02 -07:00
show={showSettings}
>
2023-01-03 19:12:30 -08:00
<SwapSettings onClose={() => setShowSettings(false)} />
2022-08-25 12:44:02 -07:00
</EnterBottomExitBottom>
2023-01-03 19:12:30 -08:00
<div className="relative p-6 pt-10">
<div className="absolute right-4 top-4">
2023-01-03 19:12:30 -08:00
<IconButton
className="text-th-fgd-3"
hideBg
onClick={() => setShowSettings(true)}
>
<Cog8ToothIcon className="h-5 w-5" />
</IconButton>
</div>
2022-12-29 02:59:56 -08:00
<div className="mb-2 flex items-end justify-between">
<p className="text-th-fgd-2 lg:text-base">{t('swap:pay')}</p>
{!isUnownedAccount ? (
<MaxSwapAmount
useMargin={useMargin}
setAmountIn={(v) => setAmountInFormValue(v, true)}
/>
) : null}
2022-08-25 06:00:42 -07:00
</div>
2022-12-29 02:59:56 -08:00
<div className="mb-3 grid grid-cols-2" id="swap-step-two">
<div className="col-span-1">
2022-12-29 02:59:56 -08:00
<TokenSelect
bank={
inputBank ||
group?.banksMapByName.get(INPUT_TOKEN_DEFAULT)?.[0]
}
showTokenList={setShowTokenSelect}
type="input"
/>
</div>
<div className="col-span-1 flex h-[54px]">
<NumberFormat
inputMode="decimal"
thousandSeparator=","
allowNegative={false}
isNumericString={true}
2022-12-29 02:59:56 -08:00
decimalScale={inputBank?.mintDecimals || 6}
name="amountIn"
id="amountIn"
className={NUMBER_FORMAT_CLASSNAMES}
placeholder="0.00"
2022-12-29 02:59:56 -08:00
value={amountInFormValue}
onValueChange={handleAmountInChange}
isAllowed={withValueLimit}
/>
2022-12-19 13:58:22 -08:00
</div>
</div>
2022-12-29 02:59:56 -08:00
<div className="-mb-2 flex justify-center">
<button
className="rounded-full border border-th-bkg-4 p-1.5 text-th-fgd-3 focus-visible:border-th-fgd-4 md:hover:text-th-active"
2022-12-29 02:59:56 -08:00
onClick={handleSwitchTokens}
>
<ArrowDownIcon
className="h-5 w-5"
style={
animateSwitchArrow % 2 == 0
? { transform: 'rotate(0deg)' }
: { transform: 'rotate(360deg)' }
}
/>
</button>
2022-12-07 14:44:39 -08:00
</div>
2022-12-29 02:59:56 -08:00
<p className="mb-2 text-th-fgd-2 lg:text-base">{t('swap:receive')}</p>
<div id="swap-step-three" className="mb-3 grid grid-cols-2">
<div className="col-span-1">
2022-12-29 02:59:56 -08:00
<TokenSelect
bank={
outputBank ||
group?.banksMapByName.get(OUTPUT_TOKEN_DEFAULT)?.[0]
}
showTokenList={setShowTokenSelect}
type="output"
/>
</div>
<div className="col-span-1 flex h-[54px]">
2022-12-29 02:59:56 -08:00
{loadingSwapDetails ? (
<div className="flex w-full items-center justify-center rounded-l-none rounded-r-lg border border-th-input-border bg-th-bkg-2">
<Loading />
2022-12-29 02:59:56 -08:00
</div>
) : (
<NumberFormat
inputMode="decimal"
thousandSeparator=","
allowNegative={false}
isNumericString={true}
decimalScale={outputBank?.mintDecimals || 6}
name="amountOut"
id="amountOut"
className={NUMBER_FORMAT_CLASSNAMES}
2022-12-29 02:59:56 -08:00
placeholder="0.00"
value={amountOutFormValue}
onValueChange={handleAmountOutChange}
/>
)}
</div>
</div>
{swapFormSizeUi === 'slider' ? (
<SwapSlider
useMargin={useMargin}
amount={amountInAsDecimal.toNumber()}
onChange={(v) => setAmountInFormValue(v, true)}
step={1 / 10 ** (inputBank?.mintDecimals || 6)}
/>
) : (
<PercentageSelectButtons
amountIn={amountInAsDecimal.toString()}
setAmountIn={(v) => setAmountInFormValue(v, true)}
useMargin={useMargin}
/>
)}
{ipAllowed ? (
<SwapFormSubmitButton
loadingSwapDetails={loadingSwapDetails}
useMargin={useMargin}
2023-01-10 16:33:03 -08:00
selectedRoute={selectedRoute}
2022-12-29 02:59:56 -08:00
setShowConfirm={setShowConfirm}
amountIn={amountInAsDecimal}
inputSymbol={inputBank?.name}
amountOut={
selectedRoute ? amountOutAsDecimal.toNumber() : undefined
}
isDelegatedAccount={isDelegatedAccount}
2022-12-29 02:59:56 -08:00
/>
) : (
2023-01-06 02:55:51 -08:00
<Button
disabled
className="mt-6 mb-4 w-full leading-tight"
size="large"
>
{t('country-not-allowed', {
country: ipCountry ? `(${ipCountry})` : '',
})}
</Button>
2022-12-29 02:59:56 -08:00
)}
2023-01-09 15:47:18 -08:00
{group && inputBank ? (
<TokenVaultWarnings bank={inputBank} type="swap" />
) : null}
2023-05-11 19:25:16 -07:00
{inputBank &&
inputBank.areBorrowsReduceOnly() &&
inputBank.areDepositsReduceOnly() ? (
2023-02-08 16:31:53 -08:00
<div className="pb-4">
<InlineNotification
type="warning"
desc={t('swap:input-reduce-only-warning', {
symbol: inputBank.name,
})}
/>
</div>
) : null}
2023-05-11 19:25:16 -07:00
{outputBank &&
outputBank.areBorrowsReduceOnly() &&
outputBank.areDepositsReduceOnly() ? (
2023-02-08 16:31:53 -08:00
<div className="pb-4">
<InlineNotification
type="warning"
desc={t('swap:output-reduce-only-warning', {
symbol: outputBank.name,
})}
/>
</div>
) : null}
2022-12-29 02:59:56 -08:00
<div className="space-y-2">
<div id="swap-step-four">
<HealthImpact maintProjectedHealth={maintProjectedHealth} />
</div>
<div className="flex items-center justify-between">
<Tooltip content={t('swap:tooltip-margin')}>
<p className="tooltip-underline text-sm text-th-fgd-3">
{t('swap:margin')}
2023-01-03 19:12:30 -08:00
</p>
</Tooltip>
<LinkButton
className="text-right text-sm font-normal text-th-fgd-2 underline underline-offset-2 md:hover:no-underline"
onClick={() => setShowSettings(true)}
>
{useMargin ? t('swap:enabled') : t('swap:disabled')}
</LinkButton>
</div>
<div className="flex items-center justify-between">
<p className="text-sm text-th-fgd-3">{t('swap:max-slippage')}</p>
<LinkButton
className="text-right font-mono text-sm font-normal text-th-fgd-2 underline underline-offset-2 md:hover:no-underline"
onClick={() => setShowSettings(true)}
>
{slippage}%
</LinkButton>
2022-12-28 20:17:38 -08:00
</div>
</div>
</div>
2022-09-11 17:22:37 -07:00
</div>
2022-07-05 20:37:49 -07:00
</ContentBox>
)
}
2022-08-19 21:03:26 -07:00
export default SwapForm
2022-08-15 09:02:46 -07:00
const SwapFormSubmitButton = ({
amountIn,
amountOut,
inputSymbol,
loadingSwapDetails,
2023-01-10 16:33:03 -08:00
selectedRoute,
setShowConfirm,
useMargin,
isDelegatedAccount,
}: {
amountIn: Decimal
amountOut: number | undefined
inputSymbol: string | undefined
loadingSwapDetails: boolean
2023-02-04 13:55:42 -08:00
selectedRoute: RouteInfo | undefined | null
setShowConfirm: (x: boolean) => void
useMargin: boolean
isDelegatedAccount: boolean
}) => {
const { t } = useTranslation('common')
2022-11-15 20:12:51 -08:00
const { connected } = useWallet()
const { amount: tokenMax, amountWithBorrow } = useTokenMax(useMargin)
2023-01-03 03:06:37 -08:00
const { handleConnect } = useEnhancedWallet()
const showInsufficientBalance = useMargin
? amountWithBorrow.lt(amountIn)
: tokenMax.lt(amountIn)
const disabled =
connected &&
(!amountIn.toNumber() ||
showInsufficientBalance ||
!amountOut ||
!selectedRoute ||
isDelegatedAccount)
2023-01-03 03:06:37 -08:00
const onClick = connected ? () => setShowConfirm(true) : handleConnect
return (
2023-02-04 13:55:42 -08:00
<>
<Button
onClick={onClick}
className="mt-6 mb-4 flex w-full items-center justify-center text-base"
disabled={disabled}
2023-02-04 13:55:42 -08:00
size="large"
>
{isDelegatedAccount ? (
<div>Swap Unavailable for Delegates</div>
) : connected ? (
2023-02-04 13:55:42 -08:00
showInsufficientBalance ? (
<div className="flex items-center">
<ExclamationCircleIcon className="mr-2 h-5 w-5 flex-shrink-0" />
{t('swap:insufficient-balance', {
symbol: inputSymbol,
})}
</div>
) : loadingSwapDetails ? (
<Loading />
) : (
<span>{t('swap:review-swap')}</span>
)
) : (
<div className="flex items-center">
2023-02-04 13:55:42 -08:00
<LinkIcon className="mr-2 h-5 w-5" />
{t('connect')}
</div>
2023-02-04 13:55:42 -08:00
)}
</Button>
{selectedRoute === null && amountIn.gt(0) ? (
2023-02-04 13:55:42 -08:00
<div className="mb-4">
<InlineNotification type="error" desc={t('swap:no-swap-found')} />
</div>
) : null}
2023-02-04 13:55:42 -08:00
</>
)
}