diff --git a/components/ContributionModal.tsx b/components/ContributionModal.tsx index 41f1d1f..d0fe906 100644 --- a/components/ContributionModal.tsx +++ b/components/ContributionModal.tsx @@ -9,13 +9,13 @@ import useWalletStore from '../stores/useWalletStore' import Input from './Input' import Button from './Button' import { ConnectWalletButtonSmall } from './ConnectWalletButton' +import PoolCountdown from './PoolCountdown' import Slider from './Slider' import Loading from './Loading' import WalletIcon from './WalletIcon' import useLargestAccounts from '../hooks/useLargestAccounts' import useVaults from '../hooks/useVaults' -import moment from 'moment' -import Countdown from 'react-countdown' +import usePool from '../hooks/usePool' const ContributionModal = () => { const actions = useWalletStore((s) => s.actions) @@ -23,13 +23,7 @@ const ContributionModal = () => { const wallet = useWalletStore((s) => s.current) const largestAccounts = useLargestAccounts() const vaults = useVaults() - - const pool = useWalletStore((s) => s.pool) - // const startIdo = pool ? moment.unix(pool.startIdoTs.toNumber()) : undefined - const endIdo = pool ? moment.unix(pool.endIdoTs.toNumber()) : undefined - const endDeposits = pool - ? moment.unix(pool.endDepositsTs.toNumber()) - : undefined + const { endIdo, endDeposits } = usePool() const usdcBalance = largestAccounts.usdc?.balance || 0 const redeemableBalance = largestAccounts.redeemable?.balance || 0 @@ -79,7 +73,7 @@ const ContributionModal = () => { const onChangeAmountInput = (amount) => { setWalletAmount(totalBalance - amount) setContributionAmount(amount) - if (endDeposits.isBefore() && amount > redeemableBalance) { + if (endDeposits?.isBefore() && amount > redeemableBalance) { setErrorMessage('Deposits ended, contribution can not increase') setTimeout(() => setErrorMessage(null), 4000) } @@ -87,7 +81,7 @@ const ContributionModal = () => { const onChangeSlider = (percentage) => { let newContribution = Math.round(percentage * totalBalance) / 100 - if (endDeposits.isBefore() && newContribution > redeemableBalance) { + if (endDeposits?.isBefore() && newContribution > redeemableBalance) { newContribution = redeemableBalance setErrorMessage('Deposits ended, contribution can not increase') setTimeout(() => setErrorMessage(null), 4000) @@ -98,7 +92,7 @@ const ContributionModal = () => { } const handleMax = () => { - if (endDeposits.isAfter()) { + if (endDeposits?.isAfter()) { setWalletAmount(0) setContributionAmount(totalBalance) } else { @@ -136,36 +130,9 @@ const ContributionModal = () => { const disableFormInputs = submitted || !connected || loading const dontAddMore = - endDeposits.isBefore() && contributionAmount > redeemableBalance + endDeposits?.isBefore() && contributionAmount > redeemableBalance const disableSubmit = disableFormInputs || walletAmount < 0 || dontAddMore - const renderCountdown = ({ hours, minutes, seconds, completed }) => { - const now = new Date().getTime() / 1000 - const message = - now > pool.endDepositsTs.toNumber() && now < pool.endIdoTs.toNumber() - ? 'Deposits are closed' - : 'The IDO has ended' - if (completed) { - return

{message}

- } else { - return ( -
- - {hours < 10 ? `0${hours}` : hours} - - : - - {minutes < 10 ? `0${minutes}` : minutes} - - : - - {seconds < 10 ? `0${seconds}` : seconds} - -
- ) - } - } - return ( <>
@@ -341,9 +308,7 @@ const ContributionModal = () => { className={`mr-2`} />
- {vaults.usdc && vaults.mango - ? `$${vaults.usdc.balance / vaults.mango.balance}` - : 'N/A'} + {vaults.estimatedPrice}
@@ -351,7 +316,7 @@ const ContributionModal = () => {

Total USDC Deposited

- {`$${vaults.usdc?.balance.toLocaleString()}` || 'N/A'} + {vaults.usdcBalance}
@@ -360,24 +325,17 @@ const ContributionModal = () => {
mango
- {vaults.mango?.balance.toLocaleString() || 'N/A'} + {vaults.mangoBalance}

Deposits Close

- {pool ? ( - - ) : null} +

Withdrawals Close

- {pool ? ( - - ) : null} +
{/*

Start: {startIdo?.fromNow()} ({startIdo?.format()}) diff --git a/components/PoolCountdown.tsx b/components/PoolCountdown.tsx new file mode 100644 index 0000000..f0050b4 --- /dev/null +++ b/components/PoolCountdown.tsx @@ -0,0 +1,40 @@ +import usePool from '../hooks/usePool' +import Countdown from 'react-countdown' +import moment from 'moment' + +const PoolCountdown = (props: { date: moment.Moment }) => { + const { endIdo, endDeposits } = usePool() + const renderCountdown = ({ hours, minutes, seconds, completed }) => { + const message = + endDeposits?.isBefore() && endIdo?.isAfter() + ? 'Deposits are closed' + : 'The IDO has ended' + if (completed) { + return

{message}

+ } else { + return ( +
+ + {hours < 10 ? `0${hours}` : hours} + + : + + {minutes < 10 ? `0${minutes}` : minutes} + + : + + {seconds < 10 ? `0${seconds}` : seconds} + +
+ ) + } + } + + if (props.date) { + return + } else { + return null + } +} + +export default PoolCountdown diff --git a/components/PoolInfoCards.tsx b/components/PoolInfoCards.tsx new file mode 100644 index 0000000..9d98f46 --- /dev/null +++ b/components/PoolInfoCards.tsx @@ -0,0 +1,73 @@ +import usePool from '../hooks/usePool' +import useVaults from '../hooks/useVaults' +import PoolCountdown from './PoolCountdown' + +const Card = (props: any) => { + return ( +
+

{props.title}

+ {props.children} +
+ ) +} + +const PoolInfoCards = () => { + const { endIdo, endDeposits } = usePool() + const vaults = useVaults() + + return ( +
+ + + + + + + + + +
+ MNGO +
+ {vaults.mangoBalance} +
+
+
+ + +
+ USDC{' '} +
+ {vaults.usdcBalance} +
+
+
+ + +
+ USDC{' '} +
+ {vaults.estimatedPrice.substring(0, 9)} +
+
+
+
+ ) +} + +export default PoolInfoCards diff --git a/hooks/usePool.tsx b/hooks/usePool.tsx new file mode 100644 index 0000000..666f8fe --- /dev/null +++ b/hooks/usePool.tsx @@ -0,0 +1,13 @@ +import moment from 'moment' +import useWalletStore from '../stores/useWalletStore' + +export default function usePool() { + const pool = useWalletStore((s) => s.pool) + const startIdo = pool ? moment.unix(pool.startIdoTs.toNumber()) : undefined + const endIdo = pool ? moment.unix(pool.endIdoTs.toNumber()) : undefined + const endDeposits = pool + ? moment.unix(pool.endDepositsTs.toNumber()) + : undefined + + return { pool, startIdo, endIdo, endDeposits } +} diff --git a/hooks/useVaults.tsx b/hooks/useVaults.tsx index f9eb01d..5d99c1d 100644 --- a/hooks/useVaults.tsx +++ b/hooks/useVaults.tsx @@ -22,5 +22,19 @@ export default function useVaults() { [mangoVault, mints] ) - return { usdc, mango } + const usdcBalance = useMemo( + () => (usdc ? `${Math.round(usdc.balance).toLocaleString()}` : 'N/A'), + [usdc] + ) + const mangoBalance = useMemo( + () => `${mango?.balance.toLocaleString()}` || 'N/A', + [mango] + ) + + const estimatedPrice = useMemo( + () => (usdc && mango ? `$${usdc.balance / mango.balance}` : 'N/A'), + [usdc, mango] + ) + + return { usdc, mango, usdcBalance, mangoBalance, estimatedPrice } } diff --git a/pages/index.tsx b/pages/index.tsx index f1edf6d..1cd7c6b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,12 +1,15 @@ import Notifications from '../components/Notification' import TopBar from '../components/TopBar' import ContributionModal from '../components/ContributionModal' +import PoolInfoCards from '../components/PoolInfoCards' const Index = () => { return (
+ +