Skip to content

Commit

Permalink
fix swap price
Browse files Browse the repository at this point in the history
  • Loading branch information
wow-sven committed Jan 29, 2025
1 parent 02e1310 commit c8bbe11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);
Expand Down
11 changes: 7 additions & 4 deletions infra/rooch-portal-v2/src/sections/trade/swap/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 (
<>
Expand All @@ -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);
}}
/>
<span className="text-gray-400 text-sm mt-4">
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}` : '-'}
</span>
<span className="mt-4">Slippage</span>
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: 2 }}>
Expand Down

0 comments on commit c8bbe11

Please sign in to comment.