import { ReactElement, useState } from 'react' import Button from '@material-ui/core/Button' import Input from '@material-ui/core/Input' import Dialog from '@material-ui/core/Dialog' import DialogActions from '@material-ui/core/DialogActions' import DialogContent from '@material-ui/core/DialogContent' import DialogContentText from '@material-ui/core/DialogContentText' import DialogTitle from '@material-ui/core/DialogTitle' import { Snackbar, Container, CircularProgress } from '@material-ui/core' import { beeDebugApi } from '../services/bee' import EthereumAddress from './EthereumAddress' export default function DepositModal(): ReactElement { const [open, setOpen] = useState(false) const [peerId, setPeerId] = useState('') const [loadingCashout, setLoadingCashout] = useState(false) const [showToast, setToastVisibility] = useState(false) const [toastContent, setToastContent] = useState(null) const handleClickOpen = () => { setOpen(true) } const handleClose = () => { setOpen(false) } const handleCashout = () => { if (peerId) { setLoadingCashout(true) beeDebugApi.chequebook .peerCashout(peerId) .then(res => { setOpen(false) handleToast( Successfully cashed out cheque. Transaction , ) }) .catch(() => { // FIXME: handle errors more gracefully handleToast(Error with cashout) }) .finally(() => { setLoadingCashout(false) }) } else { handleToast(Peer Id invalid) } } const handleToast = (text: JSX.Element) => { setToastContent(text) setToastVisibility(true) setTimeout(() => setToastVisibility(false), 7000) } return (
Cashout Cheque {loadingCashout ? ( ) : ( Specify the peer Id of the peer you would like to cashout. setPeerId(e.target.value)} /> )}
) }