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:
parent
12f668130d
commit
2cc5695aae
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.8.20",
|
||||
"version": "0.8.21",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { CheckBoxOutlineBlank, CheckBoxOutlined } from "@mui/icons-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 SettingsIcon from '@mui/icons-material/Settings';
|
||||
|
||||
@ -39,7 +39,9 @@ const BondInputArea = ({
|
||||
const isSmallScreen = useMediaQuery("(max-width: 650px)");
|
||||
const isSemiSmallScreen = useMediaQuery("(max-width: 480px)");
|
||||
const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
|
||||
|
||||
const { pathname } = useLocation();
|
||||
const [previousPathname, setPreviousPathname] = useState(pathname);
|
||||
|
||||
const nativeSymbol = useMemo(() => {
|
||||
const client = config?.getClient();
|
||||
@ -47,9 +49,11 @@ const BondInputArea = ({
|
||||
}, [config]);
|
||||
|
||||
const [wethOption, setWethOpen] = useState(false);
|
||||
const [selectedQuoteToken, setSelectedQuoteToken] = useState(
|
||||
preparedQuoteToken.isNative ? undefined : preparedQuoteToken.address
|
||||
);
|
||||
const [isWrappedToken, setIsWrappedToken] = useState(false);
|
||||
|
||||
const selectedQuoteToken = (preparedQuoteToken?.isNative && !isWrappedToken)
|
||||
? undefined
|
||||
: preparedQuoteToken?.address;
|
||||
|
||||
const toggleWethOpen = () => {
|
||||
if (!preparedQuoteToken.isNative) return;
|
||||
@ -58,11 +62,7 @@ const BondInputArea = ({
|
||||
|
||||
const toggleQuoteToken = () => {
|
||||
if (!preparedQuoteToken.isNative) return;
|
||||
|
||||
setSelectedQuoteToken((selected) => {
|
||||
if (!selected) return preparedQuoteToken.address
|
||||
else return undefined
|
||||
});
|
||||
setIsWrappedToken((prev) => !prev);
|
||||
}
|
||||
|
||||
const { currentIndex } = useCurrentIndex(chainId);
|
||||
@ -70,12 +70,18 @@ const BondInputArea = ({
|
||||
|
||||
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
|
||||
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
|
||||
|
||||
const { balance: ftsoBalance } = useBalance(chainId, "FTSO", address);
|
||||
|
||||
const [amount, setAmount] = useState("");
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
|
||||
if (pathname !== previousPathname) {
|
||||
setAmount("");
|
||||
setWethOpen(false);
|
||||
setIsWrappedToken(false);
|
||||
setPreviousPathname(pathname);
|
||||
}
|
||||
|
||||
const parsedAmount = useMemo(() => {
|
||||
return new DecimalBigNumber(amount, bond.quoteToken.decimals);
|
||||
}, [bond, amount])
|
||||
@ -97,15 +103,15 @@ const BondInputArea = ({
|
||||
if (bond.capacity.inQuoteToken.lt(bond.maxPayout.inQuoteToken)) {
|
||||
return setAmount(
|
||||
bond.capacity.inQuoteToken.lt(balance)
|
||||
? bond.capacity.inQuoteToken.toString() // Capacity is the smallest
|
||||
: balance.toString(),
|
||||
? bond.capacity.inQuoteToken.toString() // Capacity is the smallest
|
||||
: balance.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
setAmount(
|
||||
bond.maxPayout.inQuoteToken.lt(balance)
|
||||
? bond.maxPayout.inQuoteToken.toString() // Payout is the smallest
|
||||
: balance.toString(),
|
||||
? bond.maxPayout.inQuoteToken.toString() // Payout is the smallest
|
||||
: balance.toString(),
|
||||
);
|
||||
}, [bond, balance]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user