import { CircularProgress, Container } from '@material-ui/core' import Button from '@material-ui/core/Button' 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 { useSnackbar } from 'notistack' import { ReactElement, useContext, useState } from 'react' import Zap from 'remixicon-react/FlashlightLineIcon' import { Context as SettingsContext } from '../providers/Settings' import EthereumAddress from './EthereumAddress' interface Props { peerId: string uncashedAmount: string } export default function CheckoutModal({ peerId, uncashedAmount }: Props): ReactElement { const [open, setOpen] = useState(false) const [loadingCashout, setLoadingCashout] = useState(false) const { enqueueSnackbar } = useSnackbar() const { beeDebugApi } = useContext(SettingsContext) const handleClickOpen = () => { setOpen(true) } const handleClose = () => { setOpen(false) } const handleCashout = () => { if (!beeDebugApi) return if (peerId) { setLoadingCashout(true) beeDebugApi .cashoutLastCheque(peerId) .then(res => { setOpen(false) enqueueSnackbar( Successfully cashed out cheque. Transaction , { variant: 'success' }, ) }) .catch((e: Error) => { console.error(e) // eslint-disable-line enqueueSnackbar(Error: {e.message}, { variant: 'error' }) }) .finally(() => { setLoadingCashout(false) }) } else { enqueueSnackbar(Peer Id invalid, { variant: 'error' }) } } return (
Cashout Cheque {loadingCashout && ( <> Cashing out {uncashedAmount} from Peer {peerId}. Please wait... )} {!loadingCashout && ( Are you sure you want to cashout {uncashedAmount} xBZZ from Peer{' '} {peerId}? )}
) }