support WETH and native coin payments for native bonds
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
62cd599250
commit
03400023f3
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "ghost-dao-interface",
|
"name": "ghost-dao-interface",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.8.11",
|
"version": "0.8.12",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import BondSettingsModal from "./components/BondSettingsModal";
|
|||||||
import NotFound from "../NotFound/NotFound";
|
import NotFound from "../NotFound/NotFound";
|
||||||
|
|
||||||
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
|
||||||
|
import { WETH_ADDRESSES } from "../../constants/addresses";
|
||||||
import { isNetworkLegacy } from "../../constants";
|
import { isNetworkLegacy } from "../../constants";
|
||||||
import { formatCurrency } from "../../helpers";
|
import { formatCurrency } from "../../helpers";
|
||||||
|
|
||||||
@ -102,6 +103,7 @@ export const BondModal = ({ bond, chainId, address, config, connect }) => {
|
|||||||
chainNames: bond.quoteToken.chainNames,
|
chainNames: bond.quoteToken.chainNames,
|
||||||
icons: bond.quoteToken.icons,
|
icons: bond.quoteToken.icons,
|
||||||
name: bond.quoteToken.name,
|
name: bond.quoteToken.name,
|
||||||
|
isNative: bond.quoteToken.quoteTokenAddress.toLowerCase() === WETH_ADDRESSES[chainId]?.toLowerCase(),
|
||||||
}
|
}
|
||||||
}, [bond, chainSymbol, chainId]);
|
}, [bond, chainSymbol, chainId]);
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,6 @@ export const BondConfirmModal = ({
|
|||||||
spendAmount,
|
spendAmount,
|
||||||
receiveAmount,
|
receiveAmount,
|
||||||
sender,
|
sender,
|
||||||
handleSettingsOpen,
|
|
||||||
isOpen,
|
isOpen,
|
||||||
isNative,
|
isNative,
|
||||||
bondQuoteTokenName,
|
bondQuoteTokenName,
|
||||||
@ -77,10 +76,10 @@ export const BondConfirmModal = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const needsDiscountCheck = new DecimalBigNumber("0").lt(bond.discount);
|
const needsNegativeRoiCheck = new DecimalBigNumber("0").lt(bond.discount);
|
||||||
const { warmupLength, warmupExists: needsWarmup } = useWarmupLength(chainId);
|
const { warmupLength, warmupExists: needsWarmup } = useWarmupLength(chainId);
|
||||||
|
|
||||||
const [acknowledgedNegativeDiscount, setAcknowledgedNegativeDiscount] = useState(!needsDiscountCheck);
|
const [acknowledgedNegativeDiscount, setAcknowledgedNegativeDiscount] = useState(needsNegativeRoiCheck);
|
||||||
const [acknowledgedWarmup, setAcknowledgedWarmup] = useState(false);
|
const [acknowledgedWarmup, setAcknowledgedWarmup] = useState(false);
|
||||||
const [isPending, setIsPending] = useState(false);
|
const [isPending, setIsPending] = useState(false);
|
||||||
|
|
||||||
@ -89,7 +88,7 @@ export const BondConfirmModal = ({
|
|||||||
useEffect(() => setAcknowledgedWarmup(acknowledgedWarmup || !needsWarmup), [acknowledgedWarmup, needsWarmup]);
|
useEffect(() => setAcknowledgedWarmup(acknowledgedWarmup || !needsWarmup), [acknowledgedWarmup, needsWarmup]);
|
||||||
|
|
||||||
const AcknowledgeNegativeDiscountCheckbox = () => {
|
const AcknowledgeNegativeDiscountCheckbox = () => {
|
||||||
if (needsDiscountCheck) return <></>;
|
if (needsNegativeRoiCheck) return <></>;
|
||||||
return (
|
return (
|
||||||
<Box sx={{ marginBottom: "1rem" }}>
|
<Box sx={{ marginBottom: "1rem" }}>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
@ -188,14 +187,6 @@ export const BondConfirmModal = ({
|
|||||||
open={isOpen}
|
open={isOpen}
|
||||||
headerContent={<Typography variant="h4">{bondQuoteTokenName} Bond</Typography>}
|
headerContent={<Typography variant="h4">{bondQuoteTokenName} Bond</Typography>}
|
||||||
onClose={!isPending && handleConfirmCloseMaster}
|
onClose={!isPending && handleConfirmCloseMaster}
|
||||||
topRight={
|
|
||||||
<GhostStyledIcon
|
|
||||||
viewBox="0 0 23 23"
|
|
||||||
component={SettingsIcon}
|
|
||||||
style={{ cursor: "pointer" }}
|
|
||||||
onClick={handleSettingsOpen}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<Box display="flex" flexDirection="row" justifyContent="space-between" alignItems="center">
|
<Box display="flex" flexDirection="row" justifyContent="space-between" alignItems="center">
|
||||||
@ -259,7 +250,7 @@ export const BondConfirmModal = ({
|
|||||||
<DataRow title="ROI" balance={<BondDiscount discount={bond.discount} textOnly />} />
|
<DataRow title="ROI" balance={<BondDiscount discount={bond.discount} textOnly />} />
|
||||||
<DataRow title="Bond Slippage" balance={<BondSlippage slippage={slippage} textOnly />} />
|
<DataRow title="Bond Slippage" balance={<BondSlippage slippage={slippage} textOnly />} />
|
||||||
<DataRow title="Vesting Term" balance={<BondVesting vesting={bond.vesting} />} />
|
<DataRow title="Vesting Term" balance={<BondVesting vesting={bond.vesting} />} />
|
||||||
{!acknowledgedWarmup || !acknowledgedNegativeDiscount && <Box>
|
{(!acknowledgedWarmup || !acknowledgedNegativeDiscount) && <Box>
|
||||||
<Box mt="21px" mb="21px" borderTop={`1px solid ${theme.colors.gray[500]}`}></Box>
|
<Box mt="21px" mb="21px" borderTop={`1px solid ${theme.colors.gray[500]}`}></Box>
|
||||||
{!acknowledgedWarmup && <NeedsWarmupDetails />}
|
{!acknowledgedWarmup && <NeedsWarmupDetails />}
|
||||||
{!acknowledgedNegativeDiscount && <AcknowledgeNegativeDiscountCheckbox />}
|
{!acknowledgedNegativeDiscount && <AcknowledgeNegativeDiscountCheckbox />}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import { useBalance, useTokenSymbol } from "../../../hooks/tokens";
|
|||||||
|
|
||||||
const BondInputArea = ({
|
const BondInputArea = ({
|
||||||
bond,
|
bond,
|
||||||
|
config,
|
||||||
chainId,
|
chainId,
|
||||||
slippage,
|
slippage,
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
@ -40,8 +41,32 @@ const BondInputArea = ({
|
|||||||
const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
|
const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
|
|
||||||
|
const nativeSymbol = useMemo(() => {
|
||||||
|
const client = config?.getClient();
|
||||||
|
return client?.chain?.nativeCurrency?.symbol;
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
|
const [wethOption, setWethOpen] = useState(false);
|
||||||
|
const [selectedQuoteToken, setSelectedQuoteToken] = useState(
|
||||||
|
preparedQuoteToken.isNative ? undefined : preparedQuoteToken.address
|
||||||
|
);
|
||||||
|
|
||||||
|
const toggleWethOpen = () => {
|
||||||
|
if (!preparedQuoteToken.isNative) return;
|
||||||
|
setWethOpen((opened) => !opened)
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleQuoteToken = () => {
|
||||||
|
if (!preparedQuoteToken.isNative) return;
|
||||||
|
|
||||||
|
setSelectedQuoteToken((selected) => {
|
||||||
|
if (!selected) return preparedQuoteToken.address
|
||||||
|
else return undefined
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const { currentIndex } = useCurrentIndex(chainId);
|
const { currentIndex } = useCurrentIndex(chainId);
|
||||||
const { balance, refetch } = useBalance(chainId, preparedQuoteToken.address, address);
|
const { balance, refetch } = useBalance(chainId, selectedQuoteToken, address);
|
||||||
|
|
||||||
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
|
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
|
||||||
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
|
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
|
||||||
@ -91,7 +116,11 @@ const BondInputArea = ({
|
|||||||
|
|
||||||
const incorrectInputAmount = useMemo(() => {
|
const incorrectInputAmount = useMemo(() => {
|
||||||
if (!balance) return false;
|
if (!balance) return false;
|
||||||
return balance.lt(parsedAmount) || baseTokenString.lt(amountInBaseToken);
|
const zero = new DecimalBigNumber(0n, 0);
|
||||||
|
return parsedAmount.eq(zero)
|
||||||
|
|| amountInBaseToken.eq(zero)
|
||||||
|
|| balance.lt(parsedAmount)
|
||||||
|
|| baseTokenString.lt(amountInBaseToken);
|
||||||
}, [amountInBaseToken, baseTokenString, balance, parsedAmount]);
|
}, [amountInBaseToken, baseTokenString, balance, parsedAmount]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -119,14 +148,14 @@ const BondInputArea = ({
|
|||||||
spendAmountValue={parsedAmount}
|
spendAmountValue={parsedAmount}
|
||||||
spendAmount={formatNumber(parsedAmount, formatDecimals)}
|
spendAmount={formatNumber(parsedAmount, formatDecimals)}
|
||||||
receiveAmount={formatNumber(amountInBaseToken, formatDecimals)}
|
receiveAmount={formatNumber(amountInBaseToken, formatDecimals)}
|
||||||
bondQuoteTokenName={preparedQuoteToken.name}
|
bondQuoteTokenName={selectedQuoteToken ? preparedQuoteToken.name : nativeSymbol}
|
||||||
bondQuoteTokenIcons={preparedQuoteToken.icons}
|
bondQuoteTokenIcons={preparedQuoteToken.icons}
|
||||||
bondQuoteTokenChainNames={preparedQuoteToken.chainNames}
|
bondQuoteTokenChainNames={preparedQuoteToken.chainNames}
|
||||||
isNative={preparedQuoteToken.address === undefined}
|
isNative={selectedQuoteToken === undefined}
|
||||||
handleSettingsOpen={handleSettingsOpen}
|
handleSettingsOpen={handleSettingsOpen}
|
||||||
isOpen={confirmOpen}
|
isOpen={confirmOpen}
|
||||||
sender={address}
|
sender={address}
|
||||||
handleConfirmClose={() => handleConfirmClose()}
|
handleConfirmClose={handleConfirmClose}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Box maxWidth="390px" display="flex" flexDirection="column" justifyContent="center" gap="15px">
|
<Box maxWidth="390px" display="flex" flexDirection="column" justifyContent="center" gap="15px">
|
||||||
@ -142,8 +171,16 @@ const BondInputArea = ({
|
|||||||
sx={{ fontSize: "25px", height: "30px" }}
|
sx={{ fontSize: "25px", height: "30px" }}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
tokenName={preparedQuoteToken.name}
|
tokenOnClick={preparedQuoteToken.isNative ? toggleQuoteToken : undefined}
|
||||||
info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(balance, formatDecimals, preparedQuoteToken.name)}
|
tokenName={selectedQuoteToken ? preparedQuoteToken.name : nativeSymbol}
|
||||||
|
info={
|
||||||
|
(!isSemiSmallScreen ? "Balance: " : "") +
|
||||||
|
formatCurrency(
|
||||||
|
balance,
|
||||||
|
formatDecimals,
|
||||||
|
selectedQuoteToken ? preparedQuoteToken.name : nativeSymbol
|
||||||
|
)
|
||||||
|
}
|
||||||
endString="Max"
|
endString="Max"
|
||||||
endStringOnClick={setMax}
|
endStringOnClick={setMax}
|
||||||
value={amount}
|
value={amount}
|
||||||
@ -160,7 +197,10 @@ const BondInputArea = ({
|
|||||||
sx={{ fontSize: "25px", height: "30px" }}
|
sx={{ fontSize: "25px", height: "30px" }}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(ftsoBalance, formatDecimals, ftsoSymbol)}
|
info={
|
||||||
|
(!isSemiSmallScreen ? "Balance: " : "") +
|
||||||
|
formatCurrency(ftsoBalance, formatDecimals, ftsoSymbol)
|
||||||
|
}
|
||||||
tokenName={bond.baseToken.name}
|
tokenName={bond.baseToken.name}
|
||||||
value={amountInBaseToken.toString({ decimals: 9 })}
|
value={amountInBaseToken.toString({ decimals: 9 })}
|
||||||
inputProps={{ "data-testid": "toInput" }}
|
inputProps={{ "data-testid": "toInput" }}
|
||||||
@ -237,7 +277,7 @@ const BondInputArea = ({
|
|||||||
connect={connect}
|
connect={connect}
|
||||||
width="100%"
|
width="100%"
|
||||||
height="60px"
|
height="60px"
|
||||||
isNative={preparedQuoteToken.address === undefined}
|
isNative={selectedQuoteToken === undefined}
|
||||||
isVertical
|
isVertical
|
||||||
message={
|
message={
|
||||||
<>
|
<>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user