support WETH and native coin payments for native bonds

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2026-11-12 19:30:45 +03:00
parent 62cd599250
commit 03400023f3
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
4 changed files with 56 additions and 23 deletions

View File

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

View File

@ -20,6 +20,7 @@ import BondSettingsModal from "./components/BondSettingsModal";
import NotFound from "../NotFound/NotFound";
import { DecimalBigNumber } from "../../helpers/DecimalBigNumber";
import { WETH_ADDRESSES } from "../../constants/addresses";
import { isNetworkLegacy } from "../../constants";
import { formatCurrency } from "../../helpers";
@ -102,6 +103,7 @@ export const BondModal = ({ bond, chainId, address, config, connect }) => {
chainNames: bond.quoteToken.chainNames,
icons: bond.quoteToken.icons,
name: bond.quoteToken.name,
isNative: bond.quoteToken.quoteTokenAddress.toLowerCase() === WETH_ADDRESSES[chainId]?.toLowerCase(),
}
}, [bond, chainSymbol, chainId]);

View File

@ -66,7 +66,6 @@ export const BondConfirmModal = ({
spendAmount,
receiveAmount,
sender,
handleSettingsOpen,
isOpen,
isNative,
bondQuoteTokenName,
@ -77,10 +76,10 @@ export const BondConfirmModal = ({
}) => {
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 [acknowledgedNegativeDiscount, setAcknowledgedNegativeDiscount] = useState(!needsDiscountCheck);
const [acknowledgedNegativeDiscount, setAcknowledgedNegativeDiscount] = useState(needsNegativeRoiCheck);
const [acknowledgedWarmup, setAcknowledgedWarmup] = useState(false);
const [isPending, setIsPending] = useState(false);
@ -89,7 +88,7 @@ export const BondConfirmModal = ({
useEffect(() => setAcknowledgedWarmup(acknowledgedWarmup || !needsWarmup), [acknowledgedWarmup, needsWarmup]);
const AcknowledgeNegativeDiscountCheckbox = () => {
if (needsDiscountCheck) return <></>;
if (needsNegativeRoiCheck) return <></>;
return (
<Box sx={{ marginBottom: "1rem" }}>
<FormControlLabel
@ -188,14 +187,6 @@ export const BondConfirmModal = ({
open={isOpen}
headerContent={<Typography variant="h4">{bondQuoteTokenName} Bond</Typography>}
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">
@ -259,7 +250,7 @@ export const BondConfirmModal = ({
<DataRow title="ROI" balance={<BondDiscount discount={bond.discount} textOnly />} />
<DataRow title="Bond Slippage" balance={<BondSlippage slippage={slippage} textOnly />} />
<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>
{!acknowledgedWarmup && <NeedsWarmupDetails />}
{!acknowledgedNegativeDiscount && <AcknowledgeNegativeDiscountCheckbox />}

View File

@ -26,6 +26,7 @@ import { useBalance, useTokenSymbol } from "../../../hooks/tokens";
const BondInputArea = ({
bond,
config,
chainId,
slippage,
recipientAddress,
@ -40,8 +41,32 @@ const BondInputArea = ({
const isVerySmallScreen = useMediaQuery("(max-width: 379px)");
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 { balance, refetch } = useBalance(chainId, preparedQuoteToken.address, address);
const { balance, refetch } = useBalance(chainId, selectedQuoteToken, address);
const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO");
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
@ -91,7 +116,11 @@ const BondInputArea = ({
const incorrectInputAmount = useMemo(() => {
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]);
return (
@ -119,14 +148,14 @@ const BondInputArea = ({
spendAmountValue={parsedAmount}
spendAmount={formatNumber(parsedAmount, formatDecimals)}
receiveAmount={formatNumber(amountInBaseToken, formatDecimals)}
bondQuoteTokenName={preparedQuoteToken.name}
bondQuoteTokenName={selectedQuoteToken ? preparedQuoteToken.name : nativeSymbol}
bondQuoteTokenIcons={preparedQuoteToken.icons}
bondQuoteTokenChainNames={preparedQuoteToken.chainNames}
isNative={preparedQuoteToken.address === undefined}
isNative={selectedQuoteToken === undefined}
handleSettingsOpen={handleSettingsOpen}
isOpen={confirmOpen}
sender={address}
handleConfirmClose={() => handleConfirmClose()}
handleConfirmClose={handleConfirmClose}
/>
<Box maxWidth="390px" display="flex" flexDirection="column" justifyContent="center" gap="15px">
@ -142,8 +171,16 @@ const BondInputArea = ({
sx={{ fontSize: "25px", height: "30px" }}
/>
}
tokenName={preparedQuoteToken.name}
info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(balance, formatDecimals, preparedQuoteToken.name)}
tokenOnClick={preparedQuoteToken.isNative ? toggleQuoteToken : undefined}
tokenName={selectedQuoteToken ? preparedQuoteToken.name : nativeSymbol}
info={
(!isSemiSmallScreen ? "Balance: " : "") +
formatCurrency(
balance,
formatDecimals,
selectedQuoteToken ? preparedQuoteToken.name : nativeSymbol
)
}
endString="Max"
endStringOnClick={setMax}
value={amount}
@ -160,7 +197,10 @@ const BondInputArea = ({
sx={{ fontSize: "25px", height: "30px" }}
/>
}
info={(!isSemiSmallScreen ? "Balance: " : "") + formatCurrency(ftsoBalance, formatDecimals, ftsoSymbol)}
info={
(!isSemiSmallScreen ? "Balance: " : "") +
formatCurrency(ftsoBalance, formatDecimals, ftsoSymbol)
}
tokenName={bond.baseToken.name}
value={amountInBaseToken.toString({ decimals: 9 })}
inputProps={{ "data-testid": "toInput" }}
@ -237,7 +277,7 @@ const BondInputArea = ({
connect={connect}
width="100%"
height="60px"
isNative={preparedQuoteToken.address === undefined}
isNative={selectedQuoteToken === undefined}
isVertical
message={
<>