import { useEffect, useState } from 'react' import useWalletStore from '../stores/useWalletStore' import Button from './Button' import Input from './Input' import ConnectWalletButton from './ConnectWalletButton' import Loading from './Loading' import useLargestAccounts from '../hooks/useLargestAccounts' import useVaults from '../hooks/useVaults' import { calculateSupply } from '../utils/balance' const RedeemModal = () => { const actions = useWalletStore((s) => s.actions) const wallet = useWalletStore((s) => s.current) const connected = useWalletStore((s) => s.connected) const redeemableMint = useWalletStore((s) => s.pool?.redeemableMint) const mints = useWalletStore((s) => s.mints) const largestAccounts = useLargestAccounts() const vaults = useVaults() const numberFormat = new Intl.NumberFormat('en-US', { maximumFractionDigits: 2, }) const totalRaised = vaults.usdc?.balance const redeemableBalance = largestAccounts.redeemable?.balance || 0 const redeemableSupply = redeemableMint && calculateSupply(mints, redeemableMint) const mangoAvailable = vaults.mango && redeemableSupply ? (redeemableBalance * vaults.mango.balance) / redeemableSupply : 0 const [submitting, setSubmitting] = useState(false) const [loading, setLoading] = useState(true) const handleConnectDisconnect = () => { if (connected) { wallet.disconnect() } else { wallet.connect() } } const handleRedeem = () => { setSubmitting(true) } // useEffect(() => { // actions.fetchMints() // }, []) useEffect(() => { setLoading(true) if (largestAccounts.redeemable) { setLoading(false) } }, [largestAccounts]) useEffect(() => { if (submitting) { const handleSubmit = async () => { await actions.redeem() setSubmitting(false) } handleSubmit() } }, [submitting]) const disableFormInputs = !connected || loading const disableSubmit = disableFormInputs || redeemableBalance < 0 return ( <>
{!submitting ? ( <>

Redeem your MNGO.

Welcome to the DAO, let's build together.

) : null} {submitting ? ( <>

Approve the transaction.

Almost there...

) : null}
{submitting ? (
) : ( <>
Total raised } />
Your contribution } />
Redeemable amount } />
)}
) } export default RedeemModal