disable swapping between the same tokens while using direct routes
This commit is contained in:
parent
bea7dee84c
commit
52064b7627
|
@ -13,7 +13,7 @@ import useDebounce from '../shared/useDebounce'
|
|||
import { floorToDecimal, numberFormat } from '../../utils/numbers'
|
||||
import { SwapLeverageSlider } from './LeverageSlider'
|
||||
import { useTranslation } from 'next-i18next'
|
||||
import SelectToken from './SelectToken'
|
||||
import SwapFormTokenList from './SwapFormTokenList'
|
||||
import { Transition } from '@headlessui/react'
|
||||
import Button, { IconButton, LinkButton } from '../shared/Button'
|
||||
import ButtonGroup from '../forms/ButtonGroup'
|
||||
|
@ -159,7 +159,7 @@ const SwapForm = () => {
|
|||
className="thin-scroll absolute bottom-0 left-0 z-20 h-full w-full overflow-auto bg-th-bkg-2 p-6 pb-0"
|
||||
show={!!showTokenSelect}
|
||||
>
|
||||
<SelectToken
|
||||
<SwapFormTokenList
|
||||
onClose={() => setShowTokenSelect('')}
|
||||
onTokenSelect={
|
||||
showTokenSelect === 'input'
|
||||
|
|
|
@ -66,7 +66,7 @@ const TokenItem = ({
|
|||
|
||||
const popularTokenSymbols = ['USDC', 'SOL', 'USDT', 'MNGO', 'BTC', 'ETH']
|
||||
|
||||
const SelectToken = ({
|
||||
const SwapFormTokenList = ({
|
||||
onClose,
|
||||
onTokenSelect,
|
||||
type,
|
||||
|
@ -80,6 +80,8 @@ const SelectToken = ({
|
|||
const tokens = mangoStore.getState().jupiterTokens
|
||||
const walletTokens = mangoStore((s) => s.wallet.tokens)
|
||||
const jupiterTokens = mangoStore((s) => s.jupiterTokens)
|
||||
const inputBank = mangoStore((s) => s.swap.inputBank)
|
||||
const outputBank = mangoStore((s) => s.swap.outputBank)
|
||||
|
||||
const popularTokens = useMemo(() => {
|
||||
return walletTokens?.length
|
||||
|
@ -110,7 +112,11 @@ const SelectToken = ({
|
|||
const tokenInfos = useMemo(() => {
|
||||
if (tokens?.length) {
|
||||
const filteredTokens = tokens.filter((token) => {
|
||||
return !token?.name || !token?.symbol ? false : true
|
||||
if (type === 'input') {
|
||||
return token.symbol === outputBank?.name ? false : true
|
||||
} else {
|
||||
return token.symbol === inputBank?.name ? false : true
|
||||
}
|
||||
})
|
||||
if (walletTokens?.length) {
|
||||
const walletMints = walletTokens.map((tok) => tok.mint.toString())
|
||||
|
@ -124,7 +130,7 @@ const SelectToken = ({
|
|||
} else {
|
||||
return []
|
||||
}
|
||||
}, [tokens, walletTokens])
|
||||
}, [tokens, walletTokens, inputBank, outputBank])
|
||||
|
||||
const handleUpdateSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
setSearch(e.target.value)
|
||||
|
@ -157,10 +163,16 @@ const SelectToken = ({
|
|||
(t) => t.address === token.address
|
||||
)!.logoURI
|
||||
}
|
||||
const disabled =
|
||||
(type === 'input' && token.symbol === outputBank?.name) ||
|
||||
(type === 'output' && token.symbol === inputBank?.name)
|
||||
return (
|
||||
<button
|
||||
className="mx-1 mb-2 flex items-center rounded-md border border-th-bkg-4 py-1 px-3 hover:border-th-fgd-3 focus:border-th-fgd-2"
|
||||
className={`${
|
||||
disabled ? 'opacity-20' : 'hover:border-th-fgd-3'
|
||||
} mx-1 mb-2 flex items-center rounded-md border border-th-bkg-4 py-1 px-3 focus:border-th-fgd-2`}
|
||||
onClick={() => onTokenSelect(token.address)}
|
||||
disabled={disabled}
|
||||
key={token.address}
|
||||
>
|
||||
{logoURI ? (
|
||||
|
@ -188,4 +200,4 @@ const SelectToken = ({
|
|||
)
|
||||
}
|
||||
|
||||
export default memo(SelectToken)
|
||||
export default memo(SwapFormTokenList)
|
|
@ -53,7 +53,9 @@ DEFAULT_PROVIDER.opts.skipPreflight = true
|
|||
const DEFAULT_CLIENT = MangoClient.connect(
|
||||
DEFAULT_PROVIDER,
|
||||
CLUSTER,
|
||||
MANGO_V4_ID[CLUSTER]
|
||||
MANGO_V4_ID[CLUSTER],
|
||||
null,
|
||||
'get-program-accounts'
|
||||
)
|
||||
|
||||
interface TotalInterestDataItem {
|
||||
|
|
Loading…
Reference in New Issue