Files
bee-dashboard/src/components/CashoutModal.tsx
T
Cafe137 1249c0df71 feat: bee-js revamp (#690)
* chore: initial commit

* refactor: remove unnecessary wrappers

* style: add missing newline

* chore: bump bee-js

* chore: ignore any cast in fdp

* fix: remove cid import

* fix: make TextEncoder and TextDecoder available in jest

* refactor: dedupe stamp ttl second conversion

* refactor: use convenience methods from bee-js

* feat: update to bee-js for restored ens support

* fix: bump bee-js to get download fix

* fix: resolve feed before downloading reference

* fix: fix token displays

* fix: fix token input modal error message

* refactor: remove wallet balance provider

* chore: remove dead code

* refactor: upcoming bee js 0.15.0 (#692)

* chore: initial commit

* fix: do not break page when duration seconds is 0

* ci: remove cache

* chore: upgrade bee-js

* feat: bee-js and bee v2.6 compatibility

* chore: switch upcoming/bee-js to ethersphere/bee-js
2025-07-16 17:10:14 +02:00

94 lines
3.1 KiB
TypeScript

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'
interface Props {
peerId: string
uncashedAmount: string
}
export default function CheckoutModal({ peerId, uncashedAmount }: Props): ReactElement {
const [open, setOpen] = useState<boolean>(false)
const [loadingCashout, setLoadingCashout] = useState<boolean>(false)
const { beeApi } = useContext(SettingsContext)
const { enqueueSnackbar } = useSnackbar()
const handleClickOpen = () => {
setOpen(true)
}
const handleClose = () => {
setOpen(false)
}
const handleCashout = () => {
if (peerId && beeApi) {
setLoadingCashout(true)
beeApi
.cashoutLastCheque(peerId)
.then(res => {
setOpen(false)
enqueueSnackbar(<span>Successfully cashed out cheque. Transaction {res.toHex()}</span>, {
variant: 'success',
})
})
.catch((e: Error) => {
console.error(e) // eslint-disable-line
enqueueSnackbar(<span>Error: {e.message}</span>, { variant: 'error' })
})
.finally(() => {
setLoadingCashout(false)
})
} else {
enqueueSnackbar(<span>Peer Id invalid</span>, { variant: 'error' })
}
}
return (
<div>
<Button variant="contained" onClick={handleClickOpen} startIcon={<Zap size="1rem" />}>
Cash out peer {peerId.slice(0, 8)}[]
</Button>
<Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
<DialogTitle id="form-dialog-title">Cashout Cheque</DialogTitle>
<DialogContent>
<DialogContentText style={{ marginTop: '20px', overflowWrap: 'break-word' }}>
{loadingCashout && (
<>
<span>
Cashing out <strong>{uncashedAmount}</strong> from Peer <strong>{peerId}</strong>. Please wait...
</span>
<Container style={{ textAlign: 'center', padding: '50px' }}>
<CircularProgress />
</Container>
</>
)}
{!loadingCashout && (
<span>
Are you sure you want to cashout <strong>{uncashedAmount} xBZZ</strong> from Peer{' '}
<strong>{peerId}</strong>?
</span>
)}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color="primary">
Cancel
</Button>
<Button onClick={handleCashout} color="primary" disabled={loadingCashout}>
Yes Cashout
</Button>
</DialogActions>
</Dialog>
</div>
)
}