make quote token to be dynamic during the switching between bonds

Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
Uncle Fatso 2026-11-16 18:29:45 +03:00
parent 12f668130d
commit 2cc5695aae
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB
2 changed files with 21 additions and 15 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "ghost-dao-interface", "name": "ghost-dao-interface",
"private": true, "private": true,
"version": "0.8.20", "version": "0.8.21",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@ -1,6 +1,6 @@
import { CheckBoxOutlineBlank, CheckBoxOutlined } from "@mui/icons-material"; import { CheckBoxOutlineBlank, CheckBoxOutlined } from "@mui/icons-material";
import { Box, Container, Checkbox, FormControlLabel, Typography, useMediaQuery } from "@mui/material"; import { Box, Container, Checkbox, FormControlLabel, Typography, useMediaQuery } from "@mui/material";
import { useState, useMemo, useCallback } from "react"; import { useState, useMemo, useEffect, useCallback } from "react";
import { useLocation } from "react-router-dom"; import { useLocation } from "react-router-dom";
import SettingsIcon from '@mui/icons-material/Settings'; import SettingsIcon from '@mui/icons-material/Settings';
@ -39,7 +39,9 @@ const BondInputArea = ({
const isSmallScreen = useMediaQuery("(max-width: 650px)"); const isSmallScreen = useMediaQuery("(max-width: 650px)");
const isSemiSmallScreen = useMediaQuery("(max-width: 480px)"); const isSemiSmallScreen = useMediaQuery("(max-width: 480px)");
const isVerySmallScreen = useMediaQuery("(max-width: 379px)"); const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
const { pathname } = useLocation(); const { pathname } = useLocation();
const [previousPathname, setPreviousPathname] = useState(pathname);
const nativeSymbol = useMemo(() => { const nativeSymbol = useMemo(() => {
const client = config?.getClient(); const client = config?.getClient();
@ -47,9 +49,11 @@ const BondInputArea = ({
}, [config]); }, [config]);
const [wethOption, setWethOpen] = useState(false); const [wethOption, setWethOpen] = useState(false);
const [selectedQuoteToken, setSelectedQuoteToken] = useState( const [isWrappedToken, setIsWrappedToken] = useState(false);
preparedQuoteToken.isNative ? undefined : preparedQuoteToken.address
); const selectedQuoteToken = (preparedQuoteToken?.isNative && !isWrappedToken)
? undefined
: preparedQuoteToken?.address;
const toggleWethOpen = () => { const toggleWethOpen = () => {
if (!preparedQuoteToken.isNative) return; if (!preparedQuoteToken.isNative) return;
@ -58,11 +62,7 @@ const BondInputArea = ({
const toggleQuoteToken = () => { const toggleQuoteToken = () => {
if (!preparedQuoteToken.isNative) return; if (!preparedQuoteToken.isNative) return;
setIsWrappedToken((prev) => !prev);
setSelectedQuoteToken((selected) => {
if (!selected) return preparedQuoteToken.address
else return undefined
});
} }
const { currentIndex } = useCurrentIndex(chainId); const { currentIndex } = useCurrentIndex(chainId);
@ -70,12 +70,18 @@ const BondInputArea = ({
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO"); const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST"); const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
const { balance: ftsoBalance } = useBalance(chainId, "FTSO", address); const { balance: ftsoBalance } = useBalance(chainId, "FTSO", address);
const [amount, setAmount] = useState(""); const [amount, setAmount] = useState("");
const [confirmOpen, setConfirmOpen] = useState(false); const [confirmOpen, setConfirmOpen] = useState(false);
if (pathname !== previousPathname) {
setAmount("");
setWethOpen(false);
setIsWrappedToken(false);
setPreviousPathname(pathname);
}
const parsedAmount = useMemo(() => { const parsedAmount = useMemo(() => {
return new DecimalBigNumber(amount, bond.quoteToken.decimals); return new DecimalBigNumber(amount, bond.quoteToken.decimals);
}, [bond, amount]) }, [bond, amount])
@ -97,15 +103,15 @@ const BondInputArea = ({
if (bond.capacity.inQuoteToken.lt(bond.maxPayout.inQuoteToken)) { if (bond.capacity.inQuoteToken.lt(bond.maxPayout.inQuoteToken)) {
return setAmount( return setAmount(
bond.capacity.inQuoteToken.lt(balance) bond.capacity.inQuoteToken.lt(balance)
? bond.capacity.inQuoteToken.toString() // Capacity is the smallest ? bond.capacity.inQuoteToken.toString() // Capacity is the smallest
: balance.toString(), : balance.toString(),
); );
} }
setAmount( setAmount(
bond.maxPayout.inQuoteToken.lt(balance) bond.maxPayout.inQuoteToken.lt(balance)
? bond.maxPayout.inQuoteToken.toString() // Payout is the smallest ? bond.maxPayout.inQuoteToken.toString() // Payout is the smallest
: balance.toString(), : balance.toString(),
); );
}, [bond, balance]); }, [bond, balance]);