From 203e1797dc182504bcc070a2d95754fc132b5215 Mon Sep 17 00:00:00 2001 From: DMY <147dmy@gmail.com> Date: Fri, 3 Jan 2025 18:20:00 +0800 Subject: [PATCH] feat: rabby fee display (#2709) * feat: update rabby fee display * style tuning * style tuning --- _raw/locales/en/messages.json | 2 +- .../views/Bridge/Component/BridgeContent.tsx | 16 +++++++-- .../Bridge/Component/BridgeQuoteItem.tsx | 9 ----- .../views/Bridge/Component/BridgeShowMore.tsx | 34 ++++++++++++++----- src/ui/views/Bridge/Component/BridgeToken.tsx | 10 ------ src/ui/views/Swap/Component/Main.tsx | 30 ++++++++++++++-- src/ui/views/Swap/Component/QuoteItem.tsx | 29 ++-------------- src/ui/views/Swap/Component/Token.tsx | 30 +--------------- 8 files changed, 71 insertions(+), 89 deletions(-) diff --git a/_raw/locales/en/messages.json b/_raw/locales/en/messages.json index d4e1647eb09..a5a123efbf8 100644 --- a/_raw/locales/en/messages.json +++ b/_raw/locales/en/messages.json @@ -942,7 +942,7 @@ "process-with-two-step-approve": "Proceed with two step approve", "fetch-best-quote": "Fetching the Best quote", "usd-after-fees": "≈ {{usd}} ", - "no-fees-for-wrap": "No Rabby fees for Wrap", + "no-fees-for-wrap": "No Rabby fee for Wrap", "No-available-quote": "No available quote", "price-impact": "Price Impact", "loss-tips": "You're losing {{usd}}. Try a smaller amount in a small market.", diff --git a/src/ui/views/Bridge/Component/BridgeContent.tsx b/src/ui/views/Bridge/Component/BridgeContent.tsx index 29190b8d6e3..3001d82f4ff 100644 --- a/src/ui/views/Bridge/Component/BridgeContent.tsx +++ b/src/ui/views/Bridge/Component/BridgeContent.tsx @@ -6,7 +6,12 @@ import BigNumber from 'bignumber.js'; import { useWallet } from '@/ui/utils'; import clsx from 'clsx'; import { QuoteList } from './BridgeQuotes'; -import { useQuoteVisible, useSetQuoteVisible, useSetRefreshId } from '../hooks'; +import { + useQuoteVisible, + useSetQuoteVisible, + useSetRefreshId, + useSetSettingVisible, +} from '../hooks'; import { useRbiSource } from '@/ui/utils/ga-event'; import { useCss } from 'react-use'; import { findChainByEnum } from '@/utils/chain'; @@ -366,6 +371,12 @@ export const BridgeContent = () => { const [showMoreOpen, setShowMoreOpen] = useState(false); + const switchFeePopup = useSetSettingVisible(); + + const openFeePopup = useCallback(() => { + switchFeePopup(true); + }, [switchFeePopup]); + return (
{ /> ) : null} -
+
{selectedBridgeQuote && ( { const openSwapQuote = useSetQuoteVisible(); - const openFeePopup = useSetSettingVisible(); - const aggregatorsList = useRabbySelector( (s) => s.bridge.aggregatorsList || [] ); @@ -208,13 +206,6 @@ export const BridgeQuoteItem = (props: QuoteItemProps) => { ), })} - { - e.stopPropagation(); - openFeePopup(true); - }} - />
diff --git a/src/ui/views/Bridge/Component/BridgeShowMore.tsx b/src/ui/views/Bridge/Component/BridgeShowMore.tsx index 04bbbd8f45a..feccb1aabf0 100644 --- a/src/ui/views/Bridge/Component/BridgeShowMore.tsx +++ b/src/ui/views/Bridge/Component/BridgeShowMore.tsx @@ -7,7 +7,6 @@ import React, { Dispatch, PropsWithChildren, SetStateAction, - useEffect, useMemo, } from 'react'; import { Trans, useTranslation } from 'react-i18next'; @@ -19,9 +18,6 @@ import imgBestQuoteSharpBg from '@/ui/assets/swap/best-quote-sharp-bg.svg'; import styled from 'styled-components'; import { useDebounce } from 'react-use'; -const dottedClassName = - 'h-0 flex-1 border-b-[1px] border-solid border-rabby-neutral-line opacity-50'; - const PreferMEVGuardSwitch = styled(Switch)` min-width: 20px; height: 12px; @@ -67,6 +63,7 @@ export const BridgeShowMore = ({ originPreferMEVGuarded, switchPreferMEV, recommendValue, + openFeePopup, }: { open: boolean; setOpen: Dispatch>; @@ -97,9 +94,12 @@ export const BridgeShowMore = ({ originPreferMEVGuarded?: boolean; switchPreferMEV?: (b: boolean) => void; recommendValue?: number; + openFeePopup: () => void; }) => { const { t } = useTranslation(); + const RABBY_FEE = '0.25%'; + const data = useMemo(() => { if (quoteLoading || (!sourceLogo && !sourceName)) { return { @@ -147,8 +147,7 @@ export const BridgeShowMore = ({ return (
-
-
+
-
@@ -275,6 +276,23 @@ export const BridgeShowMore = ({ isWrapToken={isWrapToken} recommendValue={recommendValue} /> + + +
+ {isWrapToken && type === 'swap' + ? t('page.swap.no-fees-for-wrap') + : RABBY_FEE} +
+
+ {showMEVGuardedSwitch && type === 'swap' ? ( (); @@ -335,13 +332,6 @@ export const BridgeToken = ({ ) : ( {useValue} )} - {!valueLoading && isToToken && !!value && ( - openFeePopup(true)} - viewBox="0 0 14 14" - className="w-14 h-14 text-r-neutral-foot cursor-pointer" - /> - )}
diff --git a/src/ui/views/Swap/Component/Main.tsx b/src/ui/views/Swap/Component/Main.tsx index 44a35f9c898..4f05eea919b 100644 --- a/src/ui/views/Swap/Component/Main.tsx +++ b/src/ui/views/Swap/Component/Main.tsx @@ -14,7 +14,12 @@ import BigNumber from 'bignumber.js'; import { useWallet } from '@/ui/utils'; import clsx from 'clsx'; import { QuoteList } from './Quotes'; -import { useQuoteVisible, useSetQuoteVisible, useSetRefreshId } from '../hooks'; +import { + useQuoteVisible, + useSetQuoteVisible, + useSetRabbyFee, + useSetRefreshId, +} from '../hooks'; import { DEX_ENUM, DEX_SPENDER_WHITELIST } from '@rabby-wallet/rabby-swap'; import { useDispatch } from 'react-redux'; import { useRbiSource } from '@/ui/utils/ga-event'; @@ -431,11 +436,29 @@ export const Main = () => { ] ); + const setRabbyFeeVisible = useSetRabbyFee(); + + const openFeePopup = useCallback(() => { + if (isWrapToken) { + return; + } + setRabbyFeeVisible({ + visible: true, + dexName: activeProvider?.name || undefined, + feeDexDesc: activeProvider?.quote?.dexFeeDesc || undefined, + }); + }, [ + isWrapToken, + setRabbyFeeVisible, + activeProvider?.name, + activeProvider?.quote, + ]); + return (
-
+
{ !!amountAvailable && !!payToken && !!receiveToken && ( -
+
{ - e.stopPropagation(); - setRabbyFeeVisible({ - visible: true, - dexName: dexId, - feeDexDesc: quote?.dexFeeDesc || undefined, - }); - } - } > {disabled ? ( {bestQuotePercent} @@ -522,14 +505,6 @@ export const DexQuoteItem = ( usd: receivedTokenUsd, })} - - - )}
diff --git a/src/ui/views/Swap/Component/Token.tsx b/src/ui/views/Swap/Component/Token.tsx index c055986538f..55f56d66ec5 100644 --- a/src/ui/views/Swap/Component/Token.tsx +++ b/src/ui/views/Swap/Component/Token.tsx @@ -14,9 +14,7 @@ import { ReactComponent as RcIconWalletCC } from '@/ui/assets/swap/wallet-cc.svg import { tokenAmountBn } from '@/ui/utils/token'; import clsx from 'clsx'; import SkeletonInput from 'antd/lib/skeleton/Input'; -import { ReactComponent as RcIconInfoCC } from 'ui/assets/info-cc.svg'; -import { QuoteProvider, useSetRabbyFee } from '../hooks'; -import { TooltipWithMagnetArrow } from '@/ui/component/Tooltip/TooltipWithMagnetArrow'; +import { QuoteProvider } from '../hooks'; const StyledInput = styled(Input)` &, @@ -143,23 +141,10 @@ export const SwapTokenItem = (props: SwapTokenItemProps) => { openTokenModal: () => void; }) => React.ReactNode = useCallback((p) => , []); - const setRabbyFeeVisible = useSetRabbyFee(); - const isWrapQuote = useMemo(() => { return currentQuote?.name === 'WrapToken'; }, [currentQuote?.name]); - const openFeePopup = useCallback(() => { - if (isWrapQuote) { - return; - } - setRabbyFeeVisible({ - visible: true, - dexName: currentQuote?.name || undefined, - feeDexDesc: currentQuote?.quote?.dexFeeDesc || undefined, - }); - }, [isWrapQuote, currentQuote?.name, currentQuote?.quote]); - const onInputChange: React.ChangeEventHandler = useCallback( (e) => { onValueChange?.(e.target.value); @@ -281,19 +266,6 @@ export const SwapTokenItem = (props: SwapTokenItemProps) => { ) : ( {usdValue} )} - {!isFrom && !valueLoading && !!value && ( - - - - )}