move negative discount check to confirmation modal; avoid multiple modals

Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
Uncle Fatso 2026-11-10 20:03:53 +03:00
parent 190933cc9c
commit d183478e6b
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB
4 changed files with 42 additions and 38 deletions

View File

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

View File

@ -17,6 +17,8 @@ import BondDiscount from "./BondDiscount";
import BondVesting from "./BondVesting";
import BondSlippage from "./BondSlippage";
import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber";
import { formatNumber } from "../../../helpers";
import { useLocalStorage } from "../../../hooks/localstorage";
import { purchaseBond } from "../../../hooks/bonds";
import { useWarmupLength } from "../../../hooks/staking";
@ -31,6 +33,7 @@ const StyledBox = styled(Box, {
export const DiscountConfirmModal = ({ isOpen, isPending, onSubmit, handleConfirmClose, discount }) => {
const theme = useTheme();
return (
<Modal
maxWidth="380px"
@ -69,11 +72,15 @@ export const BondConfirmModal = ({
bondQuoteTokenName,
bondQuoteTokenIcons,
bondQuoteTokenChainNames,
handleConfirmClose
handleConfirmClose,
discount,
}) => {
const theme = useTheme();
const needsDiscountCheck = new DecimalBigNumber("0").lt(bond.discount);
const { warmupLength, warmupExists: needsWarmup } = useWarmupLength(chainId);
const [acknowledgedNegativeDiscount, setAcknowledgedNegativeDiscount] = useState(!needsDiscountCheck);
const [acknowledgedWarmup, setAcknowledgedWarmup] = useState(false);
const [isPending, setIsPending] = useState(false);
@ -81,6 +88,30 @@ export const BondConfirmModal = ({
useEffect(() => setAcknowledgedWarmup(acknowledgedWarmup || !needsWarmup), [acknowledgedWarmup, needsWarmup]);
const AcknowledgeNegativeDiscountCheckbox = () => {
if (needsDiscountCheck) return <></>;
return (
<Box sx={{ marginBottom: "1rem" }}>
<FormControlLabel
control={
<Checkbox
data-testid="acknowledge-bond-negative-discount"
checked={acknowledgedNegativeDiscount}
onChange={event => setAcknowledgedNegativeDiscount(event.target.checked)}
icon={<CheckBoxOutlineBlank viewBox="0 0 24 24" />}
checkedIcon={<CheckBoxOutlined viewBox="0 0 24 24" />}
/>
}
label={
<Typography variant="body2">
I understand this bond has a negative ROI, meaning I will receive less than market value upon vesting.
</Typography>
}
/>
</Box>
);
};
const AcknowledgeWarmupCheckbox = () => {
if (!needsWarmup) return <></>;
return (
@ -228,11 +259,13 @@ 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 && <Box>
{!acknowledgedWarmup || !acknowledgedNegativeDiscount && <Box>
<Box mt="21px" mb="21px" borderTop={`1px solid ${theme.colors.gray[500]}`}></Box>
<NeedsWarmupDetails />
{!acknowledgedWarmup && <NeedsWarmupDetails />}
{!acknowledgedNegativeDiscount && <AcknowledgeNegativeDiscountCheckbox />}
</Box>}
{acknowledgedWarmup && <PrimaryButton fullWidth onClick={onSubmit} disabled={isPending} loading={isPending}>
{acknowledgedNegativeDiscount && acknowledgedWarmup && <PrimaryButton fullWidth onClick={onSubmit} disabled={isPending} loading={isPending}>
{isPending ? "Bonding..." : "Confirm Bond Purchase"}
</PrimaryButton>}
</>

View File

@ -47,10 +47,7 @@ const BondInputArea = ({
const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST");
const [amount, setAmount] = useState("");
const [checked, setChecked] = useState(false);
const [discountConfirmed, setDiscountConfirmed] = useState(false);
const [confirmOpen, setConfirmOpen] = useState(false);
const [discountConfirmOpen, setDiscountConfirmOpen] = useState(false);
const parsedAmount = useMemo(() => {
return new DecimalBigNumber(amount, bond.quoteToken.decimals);
@ -61,28 +58,12 @@ const BondInputArea = ({
return new DecimalBigNumber(0n, 0);
}, [parsedAmount]);
const showDisclaimer = useMemo(() => {
return new DecimalBigNumber("0").gt(bond.discount);
}, [bond]);
const setModalOpen = () => {
if (showDisclaimer && !discountConfirmOpen && !discountConfirmed) setDiscountConfirmOpen(true);
else setConfirmOpen(true);
}
const handleConfirmClose = () => {
setAmount("");
setConfirmOpen(false);
setDiscountConfirmOpen(false);
refetch();
}
const confirmDiscount = () => {
setConfirmOpen(false);
setDiscountConfirmOpen(false);
setDiscountConfirmed(true);
}
const setMax = useCallback(() => {
if (!balance) return;
@ -128,16 +109,6 @@ const BondInputArea = ({
<Typography variant="h6">Bond</Typography>
}
>
<DiscountConfirmModal
isOpen={discountConfirmOpen}
onSubmit={() => confirmDiscount()}
handleConfirmClose={() => handleConfirmClose()}
discount={bond
? formatNumber(Number(bond.discount.mul(new DecimalBigNumber("100"))).toString(), 2)
: "Unknown"
}
/>
<BondConfirmModal
chainId={chainId}
bond={bond}
@ -278,8 +249,8 @@ const BondInputArea = ({
>
<PrimaryButton
fullWidth
disabled={incorrectInputAmount || bond.isSoldOut || (showDisclaimer && !checked)}
onClick={() => setModalOpen(true)}
disabled={incorrectInputAmount || bond.isSoldOut}
onClick={() => setConfirmOpen(true)}
>
Bond
</PrimaryButton>

View File

@ -13,11 +13,11 @@ const BondSlippage = ({ slippage, textOnly }) => {
color: isSlippageBig ? theme.colors.feedback.error : theme.colors.feedback.pnlGain,
}}
>
{slippage}%
{formatNumber(slippage, 2)}%
</Box>
) : (
<Chip
label={`${slippage}%`}
label={`${formatNumber(slippage, 2)}%`}
template={isSlippageBig ? "error" : "success"}
/>
);