import React, { ReactElement, useState } from 'react' import { Paper, Container, Drawer, Button, Typography, CircularProgress, Grid } from '@material-ui/core' import ClipboardCopy from '../../components/ClipboardCopy' import { beeDebugApi } from '../../services/bee' import EthereumAddress from '../../components/EthereumAddress' import { fromBZZbaseUnit } from '../../utils' import { LastCashoutActionResponse, LastChequesForPeerResponse } from '@ethersphere/bee-js' function truncStringPortion(str: string, firstCharCount = 10, endCharCount = 10) { let convertedStr = '' convertedStr += str.substring(0, firstCharCount) convertedStr += '.'.repeat(3) convertedStr += str.substring(str.length - endCharCount, str.length) return convertedStr } interface Props { peerId: string } export default function Index(props: Props): ReactElement { const [open, setOpen] = useState(false) const [peerCashout, setPeerCashout] = useState(null) const [peerCheque, setPeerCheque] = useState(null) const [isLoadingPeerCheque, setIsLoadingPeerCheque] = useState(false) const [isLoadingPeerCashout, setIsLoadingPeerCashout] = useState(false) const handleClickOpen = (peerId: string) => { setIsLoadingPeerCashout(true) beeDebugApi.chequebook .getPeerLastCashout(peerId) .then(res => { setPeerCashout(res) }) .catch(() => { // FIXME: handle the error }) .finally(() => { setIsLoadingPeerCashout(false) }) setIsLoadingPeerCheque(true) beeDebugApi.chequebook .getPeerLastCheques(peerId) .then(res => { setPeerCheque(res) }) .catch(() => { // FIXME: handle the error }) .finally(() => { setIsLoadingPeerCheque(false) }) setOpen(true) } const handleClose = () => { setOpen(false) } return (
Peer: {truncStringPortion(props.peerId)} {isLoadingPeerCashout || isLoadingPeerCheque ? ( ) : (

Last Cheque

Last Sent

Payout: {' '} {peerCheque?.lastsent?.payout ? fromBZZbaseUnit(peerCheque?.lastsent?.payout) : '-'}

Beneficiary:

Chequebook:

Last Received

Payout: {' '} {peerCheque?.lastreceived?.payout ? fromBZZbaseUnit(peerCheque?.lastreceived?.payout) : '-'}

Beneficiary:

Chequebook:

Last Cashout

{peerCashout && peerCashout?.cumulativePayout > 0 ? (

Cumulative Payout: {peerCashout?.cumulativePayout ? fromBZZbaseUnit(peerCashout?.cumulativePayout) : '-'}

Last Payout: {' '} {peerCashout?.result.lastPayout ? fromBZZbaseUnit(peerCashout?.result.lastPayout) : '-'} {peerCashout?.result.bounced ? 'Bounced' : ''}

Beneficiary:

Chequebook:

Recipient:

Transaction:

) : ( 'None' )}
)}
) }