import { Box, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography } from "@mui/material"; import { useState, useEffect } from "react"; import toast from "react-hot-toast"; import BondVesting from "./BondVesting"; import BondDuration from "./BondDuration"; import WarmupConfirmModal from "./WarmupConfirmModal"; import Paper from "../../../components/Paper/Paper"; import TokenStack from "../../../components/TokenStack/TokenStack"; import { Tab, Tabs } from "../../../components/Tabs/Tabs"; import { PrimaryButton, TertiaryButton } from "../../../components/Button"; import { useScreenSize } from "../../../hooks/useScreenSize"; import { BOND_DEPOSITORY_ADDRESSES } from "../../../constants/addresses"; import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber"; import { formatCurrency } from "../../../helpers"; import { useCurrentIndex, useEpoch, useWarmupLength, useWarmupInfo } from "../../../hooks/staking"; import { useNotes, redeem } from "../../../hooks/bonds"; import { useTokenSymbol } from "../../../hooks/tokens"; export const ClaimBonds = ({ chainId, address, secondsTo }) => { const isSmallScreen = useScreenSize("md"); const [isPending, setIsPending] = useState(false); const [isWarmup, setIsWapmup] = useState(false); const [isPreClaimConfirmed, setPreClaimConfirmed] = useState(false); const [isPayoutGhst, setIsPayoutGhst] = useState(localStorage.getItem("bond-isGhstPayout") ? localStorage.getItem("bond-isGhstPayout") === "true" : true ); const { epoch } = useEpoch(chainId); const { warmupExists } = useWarmupLength(chainId); const { warmupInfo } = useWarmupInfo(chainId, BOND_DEPOSITORY_ADDRESSES[chainId]); const { currentIndex, refetch: currentIndexRefetch } = useCurrentIndex(chainId); const { notes, refetch: notesRefetch } = useNotes(chainId, address); const { symbol: ftsoSymbol } = useTokenSymbol(chainId, "FTSO"); const { symbol: stnkSymbol } = useTokenSymbol(chainId, "STNK"); const { symbol: ghstSymbol } = useTokenSymbol(chainId, "GHST"); if (!notes || notes.length === 0) return null; const totalClaimableBalance = new DecimalBigNumber( notes.reduce((res, note) => { if (secondsTo < note.matured) return res + 0n; return res + note.payout._value }, 0n), 18 ); const setIsPayoutGhstInner = (value) => { setIsPayoutGhst(value); localStorage.setItem("bond-isGhstPayout", value); } const onSubmit = async (indexes) => { const isFundsInWarmup = warmupInfo.deposit._value > 0n; if (warmupExists && isFundsInWarmup && !isPreClaimConfirmed) { setIsWapmup(true); } else { setIsPending(true); await redeem( chainId, address, isPayoutGhst, indexes ); await notesRefetch(); setIsPending(false); } } return ( <> setIsWapmup(false)} address={address} warmupLength={warmupInfo.expiry - epoch.number} setPreClaimConfirmed={() => setPreClaimConfirmed(true)} /> Your Bonds } > Payout Options setIsPayoutGhstInner(view === 1)} TabIndicatorProps={{ style: { display: "none" } }} > Claimable Balance {isPayoutGhst ? formatCurrency(totalClaimableBalance, 5, ghstSymbol) : formatCurrency(currentIndex.mul(totalClaimableBalance), 5, stnkSymbol) } onSubmit(notes.filter((note) => secondsTo > note.matured).map(note => note.id))} > Claim All {isSmallScreen ? ( <> {notes.map((note, index) => ( {note.quoteToken.name} Duration Remaining Payout {isPayoutGhst ? formatCurrency(note.payout, 5, ghstSymbol) : formatCurrency(currentIndex.mul(note.payout), 5, stnkSymbol) } onSubmit([note.id])} > Claim ))} ) : ( Bond Duration Remaining Payout {notes.map((note, index) => ( {note.quoteToken.name} {isPayoutGhst ? formatCurrency(note.payout, 5, ghstSymbol) : formatCurrency(currentIndex.mul(note.payout), 5, stnkSymbol) } onSubmit([note.id])} > Claim ))}
)}
); };