Skip to content

Commit

Permalink
fix: cant open swap list after clearing chain (#2658)
Browse files Browse the repository at this point in the history
* fix: cant open swap list after clearing chain

* clear
  • Loading branch information
dmy147 authored Dec 6, 2024
1 parent fafec1f commit 9bdcc4d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/ui/component/TokenSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ReactComponent as SvgIconArrowDownTriangle } from '@/ui/assets/swap/arr
import { useTokens } from '@/ui/utils/portfolio/token';
import { useRabbySelector } from '@/ui/store';
import { uniqBy } from 'lodash';
import { SWAP_SUPPORT_CHAINS } from '@/constant';
import { CHAINS_ENUM } from '@/constant';
import useSearchToken from '@/ui/hooks/useSearchToken';
import useSortToken from '@/ui/hooks/useSortTokens';
import { useAsync } from 'react-use';
Expand Down Expand Up @@ -52,14 +52,12 @@ const Text = styled.span`
${ellipsis()}
`;

export interface TokenSelectProps {
interface CommonProps {
token?: TokenItem;
onChange?(amount: string): void;
onTokenChange(token: TokenItem): void;
chainId?: string;
useSwapTokenList?: boolean;
excludeTokens?: TokenItem['id'][];
type?: ComponentProps<typeof TokenSelector>['type'];
placeholder?: string;
hideChainIcon?: boolean;
value?: string;
Expand All @@ -75,8 +73,21 @@ export interface TokenSelectProps {
| React.ReactNode;
disabledTips?: React.ReactNode;
drawerHeight?: string | number;
supportChains?: CHAINS_ENUM[];
}

interface BridgeFromProps extends CommonProps {
type: 'bridgeFrom';
chainId?: string;
}

interface OtherProps extends CommonProps {
type: Exclude<ComponentProps<typeof TokenSelector>['type'], 'bridgeFrom'>;
chainId: string;
}

type TokenSelectProps = BridgeFromProps | OtherProps;

const defaultExcludeTokens = [];

const TokenSelect = ({
Expand All @@ -94,6 +105,7 @@ const TokenSelect = ({
useSwapTokenList = false,
disabledTips = 'Not supported',
drawerHeight,
supportChains,
}: TokenSelectProps) => {
const [queryConds, setQueryConds] = useState({
keyword: '',
Expand Down Expand Up @@ -229,7 +241,7 @@ const TokenSelect = ({
{typeof tokenRender === 'function'
? tokenRender?.({ token, openTokenModal: handleSelectToken })
: tokenRender}
{queryConds.chainServerId && (
{type === 'bridgeFrom' && !queryConds.chainServerId ? null : (
<TokenSelector
drawerHeight={drawerHeight}
visible={tokenSelectorVisible}
Expand All @@ -240,9 +252,9 @@ const TokenSelect = ({
isLoading={isListLoading}
type={type}
placeholder={placeholder}
chainId={queryConds.chainServerId}
chainId={queryConds.chainServerId!}
disabledTips={disabledTips}
supportChains={SWAP_SUPPORT_CHAINS}
supportChains={supportChains}
/>
)}
</>
Expand Down Expand Up @@ -293,7 +305,7 @@ const TokenSelect = ({
/>
)}
</Wrapper>
{queryConds.chainServerId && (
{type === 'bridgeFrom' && !queryConds.chainServerId ? null : (
<TokenSelector
visible={tokenSelectorVisible}
list={displayTokenList}
Expand All @@ -303,9 +315,9 @@ const TokenSelect = ({
isLoading={isListLoading}
type={type}
placeholder={placeholder}
chainId={queryConds.chainServerId}
chainId={queryConds.chainServerId!}
disabledTips={disabledTips}
supportChains={SWAP_SUPPORT_CHAINS}
supportChains={supportChains}
drawerHeight={drawerHeight}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Bridge/Component/BridgeToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const BridgeToken = ({
placeholder={t('page.swap.search-by-name-address')}
disabledTips={t('page.bridge.insufficient-balance')}
tokenRender={(p) => <TokenRender {...p} type="bridge" />}
supportChains={supportedChains}
/>
)}
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/ui/views/Swap/Component/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ export const Main = () => {
placeholder={t('page.swap.search-by-name-address')}
excludeTokens={receiveToken?.id ? [receiveToken?.id] : undefined}
tokenRender={(p) => <TokenRender {...p} />}
supportChains={SWAP_SUPPORT_CHAINS}
/>
<IconSwapArrow
className="text-r-neutral-foot opacity-60 hover:opacity-100 cursor-pointer"
Expand All @@ -550,6 +551,7 @@ export const Main = () => {
placeholder={t('page.swap.search-by-name-address')}
excludeTokens={payToken?.id ? [payToken?.id] : undefined}
tokenRender={(p) => <TokenRender {...p} />}
supportChains={SWAP_SUPPORT_CHAINS}
useSwapTokenList
/>
</div>
Expand Down

0 comments on commit 9bdcc4d

Please sign in to comment.