From c8bbe11f7de82af1708ac5965601434bea10eea9 Mon Sep 17 00:00:00 2001 From: sven Date: Thu, 30 Jan 2025 06:18:55 +0800 Subject: [PATCH] fix swap price --- .../sections/trade/components/select-token-pair.tsx | 2 +- .../rooch-portal-v2/src/sections/trade/swap/view.tsx | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/infra/rooch-portal-v2/src/sections/trade/components/select-token-pair.tsx b/infra/rooch-portal-v2/src/sections/trade/components/select-token-pair.tsx index 362d6c04d7..fd2235d6d8 100644 --- a/infra/rooch-portal-v2/src/sections/trade/components/select-token-pair.tsx +++ b/infra/rooch-portal-v2/src/sections/trade/components/select-token-pair.tsx @@ -170,7 +170,7 @@ export default function SelectTokenPair({ onLoading, onCallback }: SelectTokenPa type: yCoin.coin_type, icon: yCoin.icon_url || undefined, symbol: yCoin.symbol, - amount: yCount, + amount: fixdYCount.toString(), decimal: yCoin.decimals, } ); diff --git a/infra/rooch-portal-v2/src/sections/trade/swap/view.tsx b/infra/rooch-portal-v2/src/sections/trade/swap/view.tsx index 1b68765370..5cc136f73d 100644 --- a/infra/rooch-portal-v2/src/sections/trade/swap/view.tsx +++ b/infra/rooch-portal-v2/src/sections/trade/swap/view.tsx @@ -14,6 +14,7 @@ import SwapConfirmModal from './confirm-modal'; import SelectTokenPair from '../components/select-token-pair'; import type { TradeCoinType } from '../components/types'; +import { toDust } from 'src/utils/number'; export default function SwapView() { const dex = useNetworkVariable('dex'); @@ -25,6 +26,7 @@ export default function SwapView() { const [slippage, setSlippage] = useState(0.005); const [customSlippage, setCustomSlippage] = useState(''); const [openSwapModal, setOpenSwapModal] = useState(false); + const [price, setPrice] = useState(''); return ( <> @@ -41,13 +43,14 @@ export default function SwapView() { onCallback={(x, y) => { setX(x); setY(y); + const ratio = BigNumber(y!.amount).div(x!.amount); + const fixedRatio = ratio.toFixed(8, 1); + const finalRatio = ratio.isInteger() ? ratio.toFixed(0) : fixedRatio; + setPrice(finalRatio); }} /> - Price{' '} - {x && y - ? `1 ${x?.symbol} ≈ ${BigNumber(y?.amount).div(x?.amount).toFixed(0, 1)} ${y?.symbol}` - : '-'} + Price {x && y ? `1 ${x?.symbol} ≈ ${price} ${y?.symbol}` : '-'} Slippage