import { useState, useEffect } from "react";
import { Box, Typography, Checkbox, FormControlLabel } from "@mui/material";
import { CheckBoxOutlineBlank, CheckBoxOutlined } from "@mui/icons-material";
import { styled, useTheme } from "@mui/material/styles";
import SettingsIcon from '@mui/icons-material/Settings';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import toast from "react-hot-toast";
import GhostStyledIcon from "../../../components/Icon/GhostIcon";
import Metric from "../../../components/Metric/Metric";
import Modal from "../../../components/Modal/Modal";
import TokenStack from "../../../components/TokenStack/TokenStack";
import DataRow from "../../../components/DataRow/DataRow";
import { PrimaryButton, SecondaryButton } from "../../../components/Button";
import BondDiscount from "./BondDiscount";
import BondVesting from "./BondVesting";
import BondSlippage from "./BondSlippage";
import { purchaseBond } from "../../../hooks/bonds";
import { useWarmupLength } from "../../../hooks/staking";
const StyledBox = styled(Box, {
shouldForwardProp: prop => prop !== "template",
})(({ theme }) => {
return {
root: {},
};
});
const BondConfirmModal = ({
chainId,
bond,
slippage,
recipientAddress,
spendAmountValue,
spendAmount,
receiveAmount,
sender,
handleSettingsOpen,
isOpen,
isNative,
bondQuoteTokenName,
bondQuoteTokenIcons,
handleConfirmClose
}) => {
const theme = useTheme();
const { warmupLength, warmupExists: needsWarmup } = useWarmupLength(chainId);
const [acknowledgedWarmup, setAcknowledgedWarmup] = useState(false);
const [isPending, setIsPending] = useState(false);
useEffect(() => setAcknowledgedWarmup(acknowledgedWarmup || !needsWarmup), [acknowledgedWarmup, needsWarmup]);
const AcknowledgeWarmupCheckbox = () => {
if (!needsWarmup) return <>>;
return (
setAcknowledgedWarmup(event.target.checked)}
icon={}
checkedIcon={}
/>
}
label={
{`I understand the ${bondQuoteTokenName} I’m bonding will only be available to claim ${warmupLength.toString()} epochs after my transaction is confirmed, and the warm-up extends with each bond purchase`}
}
/>
);
};
const NeedsWarmupDetails = () => {
if (!needsWarmup) return <>>;
return (
<>
Why is there a warm-up?
>
);
};
const handleConfirmCloseMaster = () => {
setAcknowledgedWarmup(false);
handleConfirmClose()
}
const onSubmit = async () => {
setIsPending(true);
const shares = 100000;
const one = BigInt(shares * 100);
const floatSlippage = slippage === "" ? 0 : parseFloat(slippage);
const bigIntSlippage = one + BigInt(Math.round(floatSlippage * shares));
const maxPrice = bond.price.inBaseToken._value * bigIntSlippage / one;
const referral = import.meta.env.VITE_APP_REFERRAL_ADDRESS;
await purchaseBond({
chainId,
bondId: bond.id,
amount: spendAmountValue._value.toBigInt(),
maxPrice,
user: recipientAddress,
sender,
referral,
isNative
});
setIsPending(false);
handleConfirmCloseMaster();
}
return (
{bondQuoteTokenName}
}
onClose={!isPending && handleConfirmCloseMaster}
topLeft={}
>
<>
{bondQuoteTokenName}
{bond.baseToken.name}
} />
} />
} />
{!acknowledgedWarmup &&
}
{acknowledgedWarmup &&
{isPending ? "Bonding..." : "Confirm Bond Purchase"}
}
>
);
};
export default BondConfirmModal;