Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Nov 8, 2024
1 parent 5e42f8b commit fc2aa73
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 30 deletions.
16 changes: 7 additions & 9 deletions src/ui/views/Bridge/Component/BridgeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ const StyledInput = styled(Input)`
}
`;

const getDisabledTips: SelectChainItemProps['disabledTips'] = (ctx) => {
const chainItem = findChainByServerID(ctx.chain.serverId);

if (chainItem?.isTestnet) return i18n.t('page.swap.testnet-is-not-supported');

return i18n.t('page.swap.not-supported');
};

export const BridgeContent = () => {
const { userAddress } = useRabbySelector((state) => ({
userAddress: state.account.currentAccount?.address || '',
Expand All @@ -97,6 +89,7 @@ export const BridgeContent = () => {
handleAmountChange,

recommendFromToken,
fillRecommendFromToken,

inSufficient,

Expand Down Expand Up @@ -444,10 +437,15 @@ export const BridgeContent = () => {
amount={amount || 0}
toAmount={selectedBridgeQuote?.to_token_amount}
openQuotesList={openQuotesList}
quoteLoading={quoteLoading}
/>
)}
{noQuote && recommendFromToken && (
<RecommendFromToken token={recommendFromToken} className="mt-16" />
<RecommendFromToken
token={recommendFromToken}
className="mt-16"
onOk={fillRecommendFromToken}
/>
)}
</div>

Expand Down
67 changes: 49 additions & 18 deletions src/ui/views/Bridge/Component/BridgeShowMore.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { TokenWithChain } from '@/ui/component';
import { getTokenSymbol } from '@/ui/utils/token';
import { TokenItem } from '@rabby-wallet/rabby-api/dist/types';
import { Button, Tooltip } from 'antd';
import { Button, Skeleton, Tooltip } from 'antd';
import clsx from 'clsx';
import React, { PropsWithChildren, ReactNode, useMemo, useState } from 'react';
import React, {
PropsWithChildren,
ReactNode,
useEffect,
useMemo,
useState,
} from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { ReactComponent as IconArrowDownCC } from 'ui/assets/bridge/tiny-down-arrow-cc.svg';
import { ReactComponent as RcIconInfo } from 'ui/assets/info-cc.svg';
Expand All @@ -24,6 +30,7 @@ export const BridgeShowMore = ({
toToken,
amount,
toAmount,
quoteLoading,
}: {
openQuotesList: () => void;
sourceName: string;
Expand All @@ -36,6 +43,7 @@ export const BridgeShowMore = ({
toToken?: TokenItem;
amount?: string | number;
toAmount?: string | number;
quoteLoading?: boolean;
}) => {
const { t } = useTranslation();
const [show, setShow] = useState(false);
Expand All @@ -45,6 +53,12 @@ export const BridgeShowMore = ({
[fromToken, toToken, amount, toAmount]
);

useEffect(() => {
if (!quoteLoading && data?.showLoss) {
setShow(true);
}
}, [quoteLoading, data?.showLoss]);

return (
<div>
<div className="flex items-center gap-8 mt-28 mb-8 op">
Expand All @@ -69,7 +83,7 @@ export const BridgeShowMore = ({
</div>

<div className={clsx('px-16', 'overflow-hidden', !show && 'h-0')}>
{data?.showLoss && (
{data?.showLoss && !quoteLoading && (
<div className="leading-4 mb-12 text-12 text-r-neutral-foot">
<div className="flex justify-between">
<span>{t('page.bridge.price-impact')}</span>
Expand Down Expand Up @@ -108,26 +122,37 @@ export const BridgeShowMore = ({
</div>
<div className="mt-[8px] rounded-[4px] border-[0.5px] border-rabby-red-default bg-r-red-light p-8 text-13 font-normal text-r-red-default">
{t('page.bridge.loss-tips', {
usd: data?.diff,
usd: data?.lossUsd,
})}
</div>
</div>
)}

<ListItem name={t('page.bridge.showMore.source')} className="mb-8">
<div
className="flex items-center gap-4 cursor-pointer"
onClick={openQuotesList}
>
{sourceLogo && (
<img
className="w-12 h-12 rounded-full"
src={sourceLogo}
alt={sourceName}
/>
)}
<span className="text-rabby-blue-default">{sourceName}</span>
</div>
{quoteLoading ? (
<Skeleton.Input
active
className="rounded"
style={{
width: 52,
height: 12,
}}
/>
) : (
<div
className="flex items-center gap-4 cursor-pointer"
onClick={openQuotesList}
>
{sourceLogo && (
<img
className="w-12 h-12 rounded-full"
src={sourceLogo}
alt={sourceName}
/>
)}
<span className="text-rabby-blue-default">{sourceName}</span>
</div>
)}
</ListItem>

<BridgeSlippage
Expand Down Expand Up @@ -162,9 +187,11 @@ function ListItem({
export const RecommendFromToken = ({
token,
className,
onOk,
}: {
token: TokenItem;
className?: string;
onOk: () => void;
}) => {
const { t } = useTranslation();
return (
Expand Down Expand Up @@ -196,7 +223,11 @@ export const RecommendFromToken = ({
for an available quote
</Trans>
</div>
<Button type="primary" className="h-24 text-13 font-medium px-10 py-0">
<Button
type="primary"
className="h-24 text-13 font-medium px-10 py-0"
onClick={onOk}
>
{t('global.ok')}
</Button>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/ui/views/Bridge/Component/BridgeToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ export const BridgeToken = ({

useLayoutEffect(() => {
if (type === 'from') {
inputRef.current?.focus();
if (document?.activeElement !== inputRef.current?.input) {
inputRef.current?.focus();
}
}
}, []);
}, [value]);

const showNoQuote = useMemo(() => type === 'to' && !!noQuote, [
type,
Expand Down
17 changes: 16 additions & 1 deletion src/ui/views/Bridge/hooks/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ const useToken = (type: 'from' | 'to') => {

const [token, setToken] = useState<TokenItem>();

const switchChain = useCallback(
const switchChain: (
changeChain?: CHAINS_ENUM,
resetToken?: boolean
) => void = useCallback(
(changeChain?: CHAINS_ENUM, resetToken = true) => {
setChain(changeChain);
if (resetToken) {
Expand Down Expand Up @@ -125,6 +128,17 @@ export const useBridge = () => {

const [recommendFromToken, setRecommendFromToken] = useState<TokenItem>();

const fillRecommendFromToken = useCallback(() => {
if (recommendFromToken) {
const targetChain = findChainByServerID(recommendFromToken?.chain);
if (targetChain) {
switchFromChain(targetChain.enum, false);
setFromToken(recommendFromToken);
setAmount('');
}
}
}, [recommendFromToken, switchFromChain, setFromToken]);

const [selectedBridgeQuote, setOriSelectedBridgeQuote] = useState<
SelectedBridgeQuote | undefined
>();
Expand Down Expand Up @@ -596,6 +610,7 @@ export const useBridge = () => {
switchToken,

recommendFromToken,
fillRecommendFromToken,

inSufficient,
amount,
Expand Down

0 comments on commit fc2aa73

Please sign in to comment.