import React, { useState } from 'react' import mangoStore from '../../store/state' import { notify } from '../../utils/notifications' import Button from '../shared/Button' import Loading from '../shared/Loading' import Modal from '../shared/Modal' type DepositModalProps = { isOpen: boolean onClose: () => void } function DepositModal({ isOpen, onClose }: DepositModalProps) { const [inputAmount, setInputAmount] = useState('') const [submitting, setSubmitting] = useState(false) const [selectedToken, setSelectedToken] = useState('USDC') const handleDeposit = async () => { const client = mangoStore.getState().client const group = mangoStore.getState().group const actions = mangoStore.getState().actions const mangoAccount = mangoStore.getState().mangoAccount console.log('hi', mangoAccount, group) if (!mangoAccount || !group) return try { setSubmitting(true) const tx = await client.tokenDeposit( group, mangoAccount, selectedToken, parseFloat(inputAmount) ) notify({ title: 'Transaction confirmed', type: 'success', txid: tx, }) await actions.reloadAccount() setSubmitting(false) } catch (e: any) { notify({ title: 'Transaction failed', description: e.message, txid: e?.txid, type: 'error', }) console.log('Error depositing:', e) } onClose() } const handleTokenSelect = (e: React.ChangeEvent) => { setSelectedToken(e.target.value) } return (
setInputAmount(e.target.value)} />
) } export default DepositModal