style: add eslint configuration and fixed linter issues (#35)

* style: add eslint configuration as per bee-js

* chore: add `plugin:react/reocommended` in `.eslintrc`

Co-authored-by: nugaon <50576770+nugaon@users.noreply.github.com>

* chore: add `consistent` to `array-bracket-newline` as per review

* style: after automatic fixes with `npm run lint`

* style: fixed all linter errors

* refactor: fixed all linter warnings

* chore: added missing new line at end of `.prettierrc` file

Co-authored-by: nugaon <50576770+nugaon@users.noreply.github.com>
This commit is contained in:
Vojtech Simetka
2021-04-03 14:04:37 +02:00
committed by GitHub
parent 9838aa70c8
commit bc01d60728
54 changed files with 3454 additions and 2782 deletions
+100 -86
View File
@@ -1,17 +1,17 @@
import React from 'react'
import { ReactElement } from 'react'
import { Theme, createStyles, makeStyles } from '@material-ui/core/styles';
import { Card, CardContent, Typography, Grid } from '@material-ui/core/';
import { Skeleton } from '@material-ui/lab';
import WithdrawlModal from '../../components/WithdrawlModal';
import DepositModal from '../../components/DepositModal';
import CashoutModal from '../../components/CashoutModal';
import { createStyles, makeStyles } from '@material-ui/core/styles'
import { Card, CardContent, Typography, Grid } from '@material-ui/core/'
import { Skeleton } from '@material-ui/lab'
import WithdrawlModal from '../../components/WithdrawlModal'
import DepositModal from '../../components/DepositModal'
import CashoutModal from '../../components/CashoutModal'
import { ConvertBalanceToBZZ } from '../../utils/common';
import { ConvertBalanceToBZZ } from '../../utils/common'
import type { ChequebookAddressResponse } from '@ethersphere/bee-js';
import type { AllSettlements, ChequebookAddressResponse } from '@ethersphere/bee-js'
const useStyles = makeStyles((theme: Theme) =>
const useStyles = makeStyles(() =>
createStyles({
root: {
display: 'flex',
@@ -20,93 +20,107 @@ const useStyles = makeStyles((theme: Theme) =>
display: 'flex',
},
address: {
color: 'grey',
fontWeight: 400,
},
color: 'grey',
fontWeight: 400,
},
content: {
flexGrow: 1,
flexGrow: 1,
},
status: {
color: '#fff',
backgroundColor: '#76a9fa',
}
color: '#fff',
backgroundColor: '#76a9fa',
},
}),
);
)
interface ChequebookBalance {
totalBalance: number,
availableBalance: number
totalBalance: number
availableBalance: number
}
interface IProps{
chequebookAddress: ChequebookAddressResponse | null,
isLoadingChequebookAddress: boolean,
chequebookBalance: ChequebookBalance | null,
isLoadingChequebookBalance: boolean,
settlements: any,
isLoadingSettlements: boolean,
interface Props {
chequebookAddress: ChequebookAddressResponse | null
isLoadingChequebookAddress: boolean
chequebookBalance: ChequebookBalance | null
isLoadingChequebookBalance: boolean
settlements: AllSettlements | null
isLoadingSettlements: boolean
}
function AccountCard(props: Props): ReactElement {
const classes = useStyles()
function AccountCard(props: IProps) {
const classes = useStyles();
return (
<div>
<div style={{justifyContent: 'space-between', display: 'flex'}}>
<h2 style={{ marginTop: '0px' }}>Accounting</h2>
<div style={{display:'flex'}}>
<WithdrawlModal />
<DepositModal />
<CashoutModal />
</div>
</div>
<Card className={classes.root}>
{ !props.isLoadingChequebookBalance && !props.isLoadingSettlements && props.chequebookBalance ?
<div className={classes.details}>
<CardContent className={classes.content}>
<Grid container spacing={5}>
<Grid item>
<Typography component="h2" variant="h6" color="primary" gutterBottom>
Total Balance
</Typography>
<Typography component="p" variant="h5">
{ConvertBalanceToBZZ(props.chequebookBalance.totalBalance)}
</Typography>
</Grid>
<Grid item>
<Typography component="h2" variant="h6" color="primary" gutterBottom>
Available Balance
</Typography>
<Typography component="p" variant="h5">
{ConvertBalanceToBZZ(props.chequebookBalance.availableBalance)}
</Typography>
</Grid>
<Grid item>
<Typography component="h2" variant="h6" color="primary" gutterBottom>
Total Sent / Received
</Typography>
<Typography component="div" variant="h5" >
<span style={{marginRight:'7px'}}>{ConvertBalanceToBZZ(props.settlements.totalsent)} / {ConvertBalanceToBZZ(props.settlements.totalreceived)}</span>
<span style={{ color: props.settlements.totalsent > props.settlements.totalreceived ? '#c9201f' : '#32c48d' }}>({ConvertBalanceToBZZ(props.settlements.totalsent - props.settlements.totalreceived)})</span>
</Typography>
</Grid>
</Grid>
</CardContent>
</div>
:
<div className={classes.details}>
<Skeleton width={180} height={110} animation="wave" style={{ marginLeft: '12px', marginRight: '12px'}} />
<Skeleton width={180} height={110} animation="wave" style={{ marginLeft: '12px', marginRight: '12px'}} />
<Skeleton width={180} height={110} animation="wave" style={{ marginLeft: '12px', marginRight: '12px'}} />
<Skeleton width={180} height={110} animation="wave" />
</div>
}
</Card>
return (
<div>
<div style={{ justifyContent: 'space-between', display: 'flex' }}>
<h2 style={{ marginTop: '0px' }}>Accounting</h2>
<div style={{ display: 'flex' }}>
<WithdrawlModal />
<DepositModal />
<CashoutModal />
</div>
)
</div>
<Card className={classes.root}>
{!props.isLoadingChequebookBalance && !props.isLoadingSettlements && props.chequebookBalance ? (
<div className={classes.details}>
<CardContent className={classes.content}>
<Grid container spacing={5}>
<Grid item>
<Typography component="h2" variant="h6" color="primary" gutterBottom>
Total Balance
</Typography>
<Typography component="p" variant="h5">
{ConvertBalanceToBZZ(props.chequebookBalance.totalBalance)}
</Typography>
</Grid>
<Grid item>
<Typography component="h2" variant="h6" color="primary" gutterBottom>
Available Balance
</Typography>
<Typography component="p" variant="h5">
{ConvertBalanceToBZZ(props.chequebookBalance.availableBalance)}
</Typography>
</Grid>
<Grid item>
<Typography component="h2" variant="h6" color="primary" gutterBottom>
Total Sent / Received
</Typography>
<Typography component="div" variant="h5">
<span style={{ marginRight: '7px' }}>
{ConvertBalanceToBZZ(props.settlements?.totalsent || 0)} /{' '}
{ConvertBalanceToBZZ(props.settlements?.totalreceived || 0)}
</span>
<span
style={{
color:
props.settlements && props.settlements?.totalsent > props.settlements?.totalreceived
? '#c9201f'
: '#32c48d',
}}
>
(
{ConvertBalanceToBZZ(
(props.settlements && props.settlements?.totalsent - props.settlements?.totalreceived) || 0,
)}
)
</span>
</Typography>
</Grid>
</Grid>
</CardContent>
</div>
) : (
<div className={classes.details}>
<Skeleton width={180} height={110} animation="wave" style={{ marginLeft: '12px', marginRight: '12px' }} />
<Skeleton width={180} height={110} animation="wave" style={{ marginLeft: '12px', marginRight: '12px' }} />
<Skeleton width={180} height={110} animation="wave" style={{ marginLeft: '12px', marginRight: '12px' }} />
<Skeleton width={180} height={110} animation="wave" />
</div>
)}
</Card>
</div>
)
}
export default AccountCard;
export default AccountCard
+68 -52
View File
@@ -1,64 +1,80 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Table, TableBody, TableCell, TableContainer, TableRow, TableHead, Paper, Container, CircularProgress } from '@material-ui/core';
import type { ReactElement } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import {
Table,
TableBody,
TableCell,
TableContainer,
TableRow,
TableHead,
Paper,
Container,
CircularProgress,
} from '@material-ui/core'
import { ConvertBalanceToBZZ } from '../../utils/common';
import { ConvertBalanceToBZZ } from '../../utils/common'
const useStyles = makeStyles({
table: {
minWidth: 650,
},
});
table: {
minWidth: 650,
},
})
interface PeerBalance {
balance: number,
peer: string,
balance: number
peer: string
}
interface PeerBalances {
balances: Array<PeerBalance>
balances: Array<PeerBalance>
}
interface IProps {
peerBalances: PeerBalances | null,
loading?: boolean,
}
function BalancesTable(props: IProps) {
const classes = useStyles();
return (
<div>
{props.loading ?
<Container style={{textAlign:'center', padding:'50px'}}>
<CircularProgress />
</Container>
:
<TableContainer component={Paper}>
<Table className={classes.table} size="small" aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Peer</TableCell>
<TableCell style={{textAlign:'right'}}>Balance (BZZ)</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
</TableHead>
<TableBody>
{props.peerBalances?.balances.map((peerBalance: PeerBalance, idx: number) => (
<TableRow key={peerBalance.peer}>
<TableCell>{peerBalance.peer}</TableCell>
<TableCell style={{ color: ConvertBalanceToBZZ(peerBalance.balance) > 0 ? '#32c48d' : '#c9201f', textAlign:'right', fontFamily: 'monospace, monospace' }}>
{ConvertBalanceToBZZ(peerBalance.balance).toFixed(7).toLocaleString() }
</TableCell>
<TableCell align="right">
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>}
</div>
)
interface Props {
peerBalances: PeerBalances | null
loading?: boolean
}
export default BalancesTable;
function BalancesTable(props: Props): ReactElement {
const classes = useStyles()
return (
<div>
{props.loading ? (
<Container style={{ textAlign: 'center', padding: '50px' }}>
<CircularProgress />
</Container>
) : (
<TableContainer component={Paper}>
<Table className={classes.table} size="small" aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Peer</TableCell>
<TableCell style={{ textAlign: 'right' }}>Balance (BZZ)</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
</TableHead>
<TableBody>
{props.peerBalances?.balances.map((peerBalance: PeerBalance) => (
<TableRow key={peerBalance.peer}>
<TableCell>{peerBalance.peer}</TableCell>
<TableCell
style={{
color: ConvertBalanceToBZZ(peerBalance.balance) > 0 ? '#32c48d' : '#c9201f',
textAlign: 'right',
fontFamily: 'monospace, monospace',
}}
>
{ConvertBalanceToBZZ(peerBalance.balance).toFixed(7).toLocaleString()}
</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)}
</div>
)
}
export default BalancesTable
+106 -94
View File
@@ -1,113 +1,125 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Table, TableBody, TableCell, TableContainer, TableRow, TableHead, Paper, Container, CircularProgress } from '@material-ui/core';
import React, { ReactElement } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import {
Table,
TableBody,
TableCell,
TableContainer,
TableRow,
TableHead,
Paper,
Container,
CircularProgress,
} from '@material-ui/core'
import { ConvertBalanceToBZZ } from '../../utils/common';
import EthereumAddress from '../../components/EthereumAddress';
import ClipboardCopy from '../../components/ClipboardCopy';
import PeerDetailDrawer from './PeerDetailDrawer';
import { ConvertBalanceToBZZ } from '../../utils/common'
import EthereumAddress from '../../components/EthereumAddress'
import ClipboardCopy from '../../components/ClipboardCopy'
import PeerDetailDrawer from './PeerDetailDrawer'
const useStyles = makeStyles({
table: {
minWidth: 650,
},
});
table: {
minWidth: 650,
},
})
interface ChequeEvent {
beneficiary: string,
chequebook: string,
payout: number,
beneficiary: string
chequebook: string
payout: number
}
interface PeerCheque {
lastreceived?: ChequeEvent,
lastsent?: ChequeEvent,
peer: string,
lastreceived?: ChequeEvent
lastsent?: ChequeEvent
peer: string
}
interface PeerCheques {
lastcheques: Array<PeerCheque>
lastcheques: Array<PeerCheque>
}
interface IProps {
peerCheques: PeerCheques | null,
loading?: boolean,
interface Props {
peerCheques: PeerCheques | null
loading?: boolean
}
function ChequebookTable(props: IProps) {
const classes = useStyles();
return (
function ChequebookTable(props: Props): ReactElement {
const classes = useStyles()
return (
<div>
{props.loading ? (
<Container style={{ textAlign: 'center', padding: '50px' }}>
<CircularProgress />
</Container>
) : (
<div>
{props.loading ?
<Container style={{textAlign:'center', padding:'50px'}}>
<CircularProgress />
</Container>
:
<div>
<TableContainer component={Paper}>
<Table className={classes.table} size="small" aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Peer</TableCell>
<TableCell>Last Received</TableCell>
<TableCell>Last Sent</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
</TableHead>
<TableBody>
{props.peerCheques?.lastcheques.map((peerCheque: PeerCheque, idx: number) => (
<TableRow key={peerCheque.peer}>
<TableCell>
<div style={{display:'flex'}}>
<small>
<PeerDetailDrawer
peerId={peerCheque.peer}
/>
</small>
<ClipboardCopy value={peerCheque.peer} />
</div>
</TableCell>
<TableCell style={{maxWidth:'320px'}}>
<p style={{marginBottom: '0px', fontFamily: 'monospace, monospace', display:'flex'}}>
<span style={{whiteSpace: 'nowrap', marginRight:'12px', paddingTop:'3px'}}>
{peerCheque.lastreceived?.payout ?
`${ConvertBalanceToBZZ(peerCheque.lastreceived?.payout).toFixed(7).toLocaleString()} from`
: '-'}
</span>
{peerCheque.lastreceived ?
<EthereumAddress
hideBlockie
truncate
network='goerli'
address={peerCheque.lastreceived.beneficiary}
/> : null}
</p>
</TableCell>
<TableCell style={{maxWidth:'320px'}}>
<p style={{marginBottom: '0px', fontFamily: 'monospace, monospace', display:'flex'}}>
<span style={{whiteSpace: 'nowrap', marginRight:'12px', paddingTop:'3px'}}>
{peerCheque.lastsent?.payout ? `${ConvertBalanceToBZZ(peerCheque.lastsent?.payout).toFixed(7).toLocaleString()} to` : '-'}
</span>
{peerCheque.lastsent ?
<EthereumAddress
hideBlockie
truncate
network='goerli'
address={peerCheque.lastsent.beneficiary}
/> : null}
</p>
</TableCell>
<TableCell align="right">
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div>}
<TableContainer component={Paper}>
<Table className={classes.table} size="small" aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Peer</TableCell>
<TableCell>Last Received</TableCell>
<TableCell>Last Sent</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
</TableHead>
<TableBody>
{props.peerCheques?.lastcheques.map((peerCheque: PeerCheque) => (
<TableRow key={peerCheque.peer}>
<TableCell>
<div style={{ display: 'flex' }}>
<small>
<PeerDetailDrawer peerId={peerCheque.peer} />
</small>
<ClipboardCopy value={peerCheque.peer} />
</div>
</TableCell>
<TableCell style={{ maxWidth: '320px' }}>
<p style={{ marginBottom: '0px', fontFamily: 'monospace, monospace', display: 'flex' }}>
<span style={{ whiteSpace: 'nowrap', marginRight: '12px', paddingTop: '3px' }}>
{peerCheque.lastreceived?.payout
? `${ConvertBalanceToBZZ(peerCheque.lastreceived?.payout).toFixed(7).toLocaleString()} from`
: '-'}
</span>
{peerCheque.lastreceived ? (
<EthereumAddress
hideBlockie
truncate
network="goerli"
address={peerCheque.lastreceived.beneficiary}
/>
) : null}
</p>
</TableCell>
<TableCell style={{ maxWidth: '320px' }}>
<p style={{ marginBottom: '0px', fontFamily: 'monospace, monospace', display: 'flex' }}>
<span style={{ whiteSpace: 'nowrap', marginRight: '12px', paddingTop: '3px' }}>
{peerCheque.lastsent?.payout
? `${ConvertBalanceToBZZ(peerCheque.lastsent?.payout).toFixed(7).toLocaleString()} to`
: '-'}
</span>
{peerCheque.lastsent ? (
<EthereumAddress
hideBlockie
truncate
network="goerli"
address={peerCheque.lastsent.beneficiary}
/>
) : null}
</p>
</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</div>
)
)}
</div>
)
}
export default ChequebookTable;
export default ChequebookTable
+158 -176
View File
@@ -1,188 +1,170 @@
import React, { 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 { ConvertBalanceToBZZ } from '../../utils/common';
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 { ConvertBalanceToBZZ } from '../../utils/common'
import { LastCashoutActionResponse, LastChequesForPeerResponse } from '@ethersphere/bee-js'
function truncStringPortion(str: string, firstCharCount=10, endCharCount=10) {
var convertedStr="";
convertedStr+=str.substring(0, firstCharCount);
convertedStr += ".".repeat(3);
convertedStr+=str.substring(str.length-endCharCount, str.length);
return convertedStr;
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
}
export default function Index(props: any) {
const [open, setOpen] = useState(false);
const [peerCashout, setPeerCashout] = useState({ "peer": "",
"chequebook": "",
"cumulativePayout": 0,
"beneficiary": "",
"transactionHash": "",
"result": {
"recipient": "",
"lastPayout": 0,
"bounced": false
}});
interface Props {
peerId: string
}
const [peerCheque, setPeerCheque] = useState({
lastreceived: { beneficiary: "", payout: 0, chequebook: "" },
lastsent: { beneficiary: "", payout: 0, chequebook: "" },
peer: ""
})
export default function Index(props: Props): ReactElement {
const [open, setOpen] = useState(false)
const [peerCashout, setPeerCashout] = useState<LastCashoutActionResponse | null>(null)
const [peerCheque, setPeerCheque] = useState<LastChequesForPeerResponse | null>(null)
const [isLoadingPeerCheque, setIsLoadingPeerCheque] = useState<boolean>(false)
const [isLoadingPeerCashout, setIsLoadingPeerCashout] = useState<boolean>(false);
const [isLoadingPeerCheque, setIsLoadingPeerCheque] = useState<boolean>(false)
const [isLoadingPeerCashout, setIsLoadingPeerCashout] = useState<boolean>(false)
const handleClickOpen = (peerId: string) => {
setIsLoadingPeerCashout(true)
beeDebugApi.chequebook
.getPeerLastCashout(peerId)
.then(res => {
setPeerCashout(res)
})
.catch(() => {
// FIXME: handle the error
})
.finally(() => {
setIsLoadingPeerCashout(false)
})
const handleClickOpen = (peerId: string) => {
setIsLoadingPeerCashout(true)
beeDebugApi.chequebook.getPeerLastCashout(peerId)
.then(res => {
setPeerCashout(res)
})
.catch(error => {
})
.finally(() => {
setIsLoadingPeerCashout(false)
})
setIsLoadingPeerCheque(true)
beeDebugApi.chequebook
.getPeerLastCheques(peerId)
.then(res => {
setPeerCheque(res)
})
.catch(() => {
// FIXME: handle the error
})
.finally(() => {
setIsLoadingPeerCheque(false)
})
setIsLoadingPeerCheque(true)
beeDebugApi.chequebook.getPeerLastCheques(peerId)
.then(res => {
setPeerCheque(res)
})
.catch(error => {
})
.finally(() => {
setIsLoadingPeerCheque(false)
})
setOpen(true)
}
setOpen(true);
}
const handleClose = () => {
setOpen(false);
};
const handleClose = () => {
setOpen(false)
}
return (
<div>
<Button color="primary" onClick={() => handleClickOpen(props.peerId)}>{truncStringPortion(props.peerId)}</Button>
<Drawer anchor={'right'} open={open} onClose={handleClose}>
<div style={{padding:'20px'}}>
<Typography variant="h5" gutterBottom style={{display:'flex'}}>
<span>Peer: { truncStringPortion(props.peerId) }</span>
<ClipboardCopy value={props.peerId} />
</Typography>
<Paper>
{ isLoadingPeerCashout || isLoadingPeerCheque ?
<Container style={{textAlign:'center', padding:'50px'}}>
<CircularProgress />
</Container>
:
<div style={{textAlign:'left', padding:'10px'}}>
<h3>Last Cheque</h3>
<Grid container spacing={1}>
<Grid key={1} item xs={12} sm={12} xl={6}>
<h5>Last Sent</h5>
<p>
Payout:
<span style={{marginBottom: '0px', fontFamily: 'monospace, monospace'}}> {
peerCheque.lastsent?.payout ? ConvertBalanceToBZZ(peerCheque.lastsent?.payout) : '-'
}</span>
</p>
<p>Beneficiary:
<EthereumAddress
network={'goerli'}
hideBlockie
address={peerCheque.lastsent?.beneficiary}
/>
</p>
<p>Chequebook:
<EthereumAddress
network={'goerli'}
hideBlockie
address={peerCheque.lastsent?.chequebook}
/>
</p>
</Grid>
<Grid key={1} item xs={12} sm={12} xl={6}>
<h5>Last Received</h5>
<p>
Payout:
<span style={{marginBottom: '0px', fontFamily: 'monospace, monospace'}}> {
peerCheque.lastreceived?.payout ? ConvertBalanceToBZZ(peerCheque.lastreceived?.payout) : '-'}</span>
</p>
<p>Beneficiary:
<EthereumAddress
network={'goerli'}
hideBlockie
address={peerCheque.lastreceived?.beneficiary}
/>
</p>
<p>Chequebook:
<EthereumAddress
network={'goerli'}
hideBlockie
address={peerCheque.lastreceived?.chequebook}
/>
</p>
</Grid>
</Grid>
<h3>Last Cashout</h3>
{peerCashout.cumulativePayout > 0 ?
<div>
<p>
Cumulative Payout:
<span style={{marginBottom: '0px', fontFamily: 'monospace, monospace'}}>
{peerCashout.cumulativePayout ? ConvertBalanceToBZZ(peerCashout.cumulativePayout) : '-'}
</span>
</p>
<p>
Last Payout:
<span style={{marginBottom: '0px', fontFamily: 'monospace, monospace'}}> {
peerCashout.result.lastPayout ? ConvertBalanceToBZZ(peerCashout.result.lastPayout) : '-'
}</span>
<span> {peerCashout.result.bounced ? 'Bounced' : ''}</span>
</p>
<p>Beneficiary:
<EthereumAddress
network={'goerli'}
hideBlockie
address={peerCashout.beneficiary}
/>
</p>
<p>Chequebook:
<EthereumAddress
network={'goerli'}
hideBlockie
address={peerCashout.chequebook}
/>
</p>
<p>Recipient:
<EthereumAddress
network={'goerli'}
hideBlockie
address={peerCashout.result.recipient}
/>
</p>
<p>Transaction:
<EthereumAddress
transaction
network={'goerli'}
hideBlockie
address={peerCashout.transactionHash}
/>
</p>
</div>
: 'None'}
</div>
}
</Paper>
</div>
</Drawer>
return (
<div>
<Button color="primary" onClick={() => handleClickOpen(props.peerId)}>
{truncStringPortion(props.peerId)}
</Button>
<Drawer anchor={'right'} open={open} onClose={handleClose}>
<div style={{ padding: '20px' }}>
<Typography variant="h5" gutterBottom style={{ display: 'flex' }}>
<span>Peer: {truncStringPortion(props.peerId)}</span>
<ClipboardCopy value={props.peerId} />
</Typography>
<Paper>
{isLoadingPeerCashout || isLoadingPeerCheque ? (
<Container style={{ textAlign: 'center', padding: '50px' }}>
<CircularProgress />
</Container>
) : (
<div style={{ textAlign: 'left', padding: '10px' }}>
<h3>Last Cheque</h3>
<Grid container spacing={1}>
<Grid key={1} item xs={12} sm={12} xl={6}>
<h5>Last Sent</h5>
<p>
Payout:
<span style={{ marginBottom: '0px', fontFamily: 'monospace, monospace' }}>
{' '}
{peerCheque?.lastsent?.payout ? ConvertBalanceToBZZ(peerCheque?.lastsent?.payout) : '-'}
</span>
</p>
<p>
Beneficiary:
<EthereumAddress network={'goerli'} hideBlockie address={peerCheque?.lastsent?.beneficiary} />
</p>
<p>
Chequebook:
<EthereumAddress network={'goerli'} hideBlockie address={peerCheque?.lastsent?.chequebook} />
</p>
</Grid>
<Grid key={1} item xs={12} sm={12} xl={6}>
<h5>Last Received</h5>
<p>
Payout:
<span style={{ marginBottom: '0px', fontFamily: 'monospace, monospace' }}>
{' '}
{peerCheque?.lastreceived?.payout ? ConvertBalanceToBZZ(peerCheque?.lastreceived?.payout) : '-'}
</span>
</p>
<p>
Beneficiary:
<EthereumAddress network={'goerli'} hideBlockie address={peerCheque?.lastreceived?.beneficiary} />
</p>
<p>
Chequebook:
<EthereumAddress network={'goerli'} hideBlockie address={peerCheque?.lastreceived?.chequebook} />
</p>
</Grid>
</Grid>
<h3>Last Cashout</h3>
{peerCashout && peerCashout?.cumulativePayout > 0 ? (
<div>
<p>
Cumulative Payout:
<span style={{ marginBottom: '0px', fontFamily: 'monospace, monospace' }}>
{peerCashout?.cumulativePayout ? ConvertBalanceToBZZ(peerCashout?.cumulativePayout) : '-'}
</span>
</p>
<p>
Last Payout:
<span style={{ marginBottom: '0px', fontFamily: 'monospace, monospace' }}>
{' '}
{peerCashout?.result.lastPayout ? ConvertBalanceToBZZ(peerCashout?.result.lastPayout) : '-'}
</span>
<span> {peerCashout?.result.bounced ? 'Bounced' : ''}</span>
</p>
<p>
Beneficiary:
<EthereumAddress network={'goerli'} hideBlockie address={peerCashout?.beneficiary} />
</p>
<p>
Chequebook:
<EthereumAddress network={'goerli'} hideBlockie address={peerCashout?.chequebook} />
</p>
<p>
Recipient:
<EthereumAddress network={'goerli'} hideBlockie address={peerCashout?.result.recipient} />
</p>
<p>
Transaction:
<EthereumAddress
transaction
network={'goerli'}
hideBlockie
address={peerCashout?.transactionHash}
/>
</p>
</div>
) : (
'None'
)}
</div>
)}
</Paper>
</div>
)
</Drawer>
</div>
)
}
+61 -51
View File
@@ -1,59 +1,69 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Table, TableBody, TableCell, TableContainer, TableRow, TableHead, Paper, Container, CircularProgress } from '@material-ui/core';
import { ReactElement } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import {
Table,
TableBody,
TableCell,
TableContainer,
TableRow,
TableHead,
Paper,
Container,
CircularProgress,
} from '@material-ui/core'
import { ConvertBalanceToBZZ } from '../../utils/common';
import { ConvertBalanceToBZZ } from '../../utils/common'
import type { AllSettlements, Settlements } from '@ethersphere/bee-js'
const useStyles = makeStyles({
table: {
minWidth: 650,
},
});
table: {
minWidth: 650,
},
})
interface IProps {
nodeSettlements: AllSettlements | null,
loading?: boolean,
}
function SettlementsTable(props: IProps) {
const classes = useStyles();
return (
<div>
{props.loading ?
<Container style={{textAlign:'center', padding:'50px'}}>
<CircularProgress />
</Container>
:
<TableContainer component={Paper}>
<Table className={classes.table} size="small" aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Peer</TableCell>
<TableCell>Received (BZZ)</TableCell>
<TableCell>Sent (BZZ)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{props.nodeSettlements?.settlements.map((item: Settlements, idx: number) => (
<TableRow key={item.peer}>
<TableCell>{item.peer}</TableCell>
<TableCell style={{ fontFamily: 'monospace, monospace'}}>
{item.received > 0 ? ConvertBalanceToBZZ(item.received).toFixed(7).toLocaleString() : item.received}
</TableCell>
<TableCell style={{ fontFamily: 'monospace, monospace'}}>
{item.sent > 0 ? ConvertBalanceToBZZ(item.sent).toFixed(7).toLocaleString() : item.sent}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>}
</div>
)
interface Props {
nodeSettlements: AllSettlements | null
loading?: boolean
}
export default SettlementsTable;
function SettlementsTable(props: Props): ReactElement {
const classes = useStyles()
return (
<div>
{props.loading ? (
<Container style={{ textAlign: 'center', padding: '50px' }}>
<CircularProgress />
</Container>
) : (
<TableContainer component={Paper}>
<Table className={classes.table} size="small" aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>Peer</TableCell>
<TableCell>Received (BZZ)</TableCell>
<TableCell>Sent (BZZ)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{props.nodeSettlements?.settlements.map((item: Settlements) => (
<TableRow key={item.peer}>
<TableCell>{item.peer}</TableCell>
<TableCell style={{ fontFamily: 'monospace, monospace' }}>
{item.received > 0 ? ConvertBalanceToBZZ(item.received).toFixed(7).toLocaleString() : item.received}
</TableCell>
<TableCell style={{ fontFamily: 'monospace, monospace' }}>
{item.sent > 0 ? ConvertBalanceToBZZ(item.sent).toFixed(7).toLocaleString() : item.sent}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)}
</div>
)
}
export default SettlementsTable
+141 -139
View File
@@ -1,166 +1,168 @@
import React from 'react';
import { withStyles, Theme, createStyles } from '@material-ui/core/styles';
import { Tabs, Tab, Box, Typography, Container, CircularProgress } from '@material-ui/core';
import { ReactElement, useState, ChangeEvent, ReactChild } from 'react'
import { withStyles, Theme, createStyles } from '@material-ui/core/styles'
import { Tabs, Tab, Box, Typography, Container, CircularProgress } from '@material-ui/core'
import AccountCard from '../accounting/AccountCard';
import BalancesTable from './BalancesTable';
import ChequebookTable from './ChequebookTable';
import SettlementsTable from './SettlementsTable';
import EthereumAddressCard from '../../components/EthereumAddressCard';
import TroubleshootConnectionCard from '../../components/TroubleshootConnectionCard';
import AccountCard from '../accounting/AccountCard'
import BalancesTable from './BalancesTable'
import ChequebookTable from './ChequebookTable'
import SettlementsTable from './SettlementsTable'
import EthereumAddressCard from '../../components/EthereumAddressCard'
import TroubleshootConnectionCard from '../../components/TroubleshootConnectionCard'
import { useApiNodeAddresses, useApiChequebookAddress, useApiChequebookBalance, useApiPeerBalances, useApiPeerCheques, useApiSettlements } from '../../hooks/apiHooks';
import {
useApiNodeAddresses,
useApiChequebookAddress,
useApiChequebookBalance,
useApiPeerBalances,
useApiPeerCheques,
useApiSettlements,
useApiHealth,
useDebugApiHealth,
} from '../../hooks/apiHooks'
interface TabPanelProps {
children?: React.ReactNode;
index: any;
value: any;
children?: ReactChild
index: number
value: number
}
function a11yProps(index: any) {
return {
id: `simple-tab-${index}`,
'aria-controls': `simple-tabpanel-${index}`,
};
function a11yProps(index: number) {
return {
id: `simple-tab-${index}`,
'aria-controls': `simple-tabpanel-${index}`,
}
}
export default function Accounting(props: any) {
const [value, setValue] = React.useState(0);
export default function Accounting(): ReactElement {
const [value, setValue] = useState(0)
const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => {
setValue(newValue);
};
const handleChange = (event: ChangeEvent<unknown>, newValue: number) => {
setValue(newValue)
}
const { chequebookAddress, isLoadingChequebookAddress } = useApiChequebookAddress()
const { chequebookBalance, isLoadingChequebookBalance } = useApiChequebookBalance()
const { peerBalances, isLoadingPeerBalances } = useApiPeerBalances()
const { nodeAddresses, isLoadingNodeAddresses } = useApiNodeAddresses()
const { chequebookAddress, isLoadingChequebookAddress } = useApiChequebookAddress()
const { chequebookBalance, isLoadingChequebookBalance } = useApiChequebookBalance()
const { peerBalances, isLoadingPeerBalances } = useApiPeerBalances()
const { nodeAddresses, isLoadingNodeAddresses } = useApiNodeAddresses()
const { health, isLoadingHealth } = useApiHealth()
const { nodeHealth, isLoadingNodeHealth } = useDebugApiHealth()
const { peerCheques, isLoadingPeerCheques } = useApiPeerCheques()
const { settlements, isLoadingSettlements } = useApiSettlements()
const { peerCheques, isLoadingPeerCheques } = useApiPeerCheques()
const { settlements, isLoadingSettlements } = useApiSettlements()
function TabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props
function TabPanel(props: TabPanelProps) {
const { children, value, index, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`simple-tabpanel-${index}`}
aria-labelledby={`simple-tab-${index}`}
{...other}
>
{value === index && (
<Box style={{ marginTop: '20px' }}>
<Typography component="div">{children}</Typography>
</Box>
)}
</div>
);
}
const AntTabs = withStyles({
root: {
borderBottom: '1px solid #e8e8e8',
},
indicator: {
backgroundColor: '#3f51b5',
},
})(Tabs);
interface StyledTabProps {
label: string;
}
const AntTab = withStyles((theme: Theme) =>
createStyles({
root: {
textTransform: 'none',
minWidth: 72,
backgroundColor: 'transparent',
fontWeight: theme.typography.fontWeightRegular,
marginRight: theme.spacing(4),
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:hover': {
color: '#3f51b5',
opacity: 1,
},
'&$selected': {
color: '#3f51b5',
fontWeight: theme.typography.fontWeightMedium,
},
'&:focus': {
color: '#3f51b5',
},
},
selected: {},
}),
)((props: StyledTabProps) => <Tab disableRipple {...props} />);
return (
<div>
{props.nodeHealth?.status === 'ok' && props.health ?
<div
role="tabpanel"
hidden={value !== index}
id={`simple-tabpanel-${index}`}
aria-labelledby={`simple-tab-${index}`}
{...other}
>
{value === index && (
<Box style={{ marginTop: '20px' }}>
<Typography component="div">{children}</Typography>
</Box>
)}
</div>
)
}
const AntTabs = withStyles({
root: {
borderBottom: '1px solid #e8e8e8',
},
indicator: {
backgroundColor: '#3f51b5',
},
})(Tabs)
interface StyledTabProps {
label: string
}
const AntTab = withStyles((theme: Theme) =>
createStyles({
root: {
textTransform: 'none',
minWidth: 72,
backgroundColor: 'transparent',
fontWeight: theme.typography.fontWeightRegular,
marginRight: theme.spacing(4),
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
'"Segoe UI"',
'Roboto',
'"Helvetica Neue"',
'Arial',
'sans-serif',
'"Apple Color Emoji"',
'"Segoe UI Emoji"',
'"Segoe UI Symbol"',
].join(','),
'&:hover': {
color: '#3f51b5',
opacity: 1,
},
'&$selected': {
color: '#3f51b5',
fontWeight: theme.typography.fontWeightMedium,
},
'&:focus': {
color: '#3f51b5',
},
},
selected: {},
}),
)((props: StyledTabProps) => <Tab disableRipple {...props} />)
return (
<div>
{
// FIXME: this should be broken up
/* eslint-disable no-nested-ternary */
nodeHealth?.status === 'ok' && health ? (
<div>
<AccountCard
chequebookAddress={chequebookAddress}
isLoadingChequebookAddress={isLoadingChequebookAddress}
chequebookBalance={chequebookBalance}
isLoadingChequebookBalance={isLoadingChequebookBalance}
settlements={settlements}
isLoadingSettlements={isLoadingSettlements}
chequebookAddress={chequebookAddress}
isLoadingChequebookAddress={isLoadingChequebookAddress}
chequebookBalance={chequebookBalance}
isLoadingChequebookBalance={isLoadingChequebookBalance}
settlements={settlements}
isLoadingSettlements={isLoadingSettlements}
/>
<EthereumAddressCard
nodeAddresses={nodeAddresses}
isLoadingNodeAddresses={isLoadingNodeAddresses}
chequebookAddress={chequebookAddress}
isLoadingChequebookAddress={isLoadingChequebookAddress}
<EthereumAddressCard
nodeAddresses={nodeAddresses}
isLoadingNodeAddresses={isLoadingNodeAddresses}
chequebookAddress={chequebookAddress}
isLoadingChequebookAddress={isLoadingChequebookAddress}
/>
<AntTabs style={{ marginTop: '12px' }} value={value} onChange={handleChange} aria-label="ant example">
<AntTab label="Balances" {...a11yProps(0)} />
<AntTab label="Chequebook" {...a11yProps(1)} />
<AntTab label="Settlements" {...a11yProps(2)} />
<AntTab label="Balances" {...a11yProps(0)} />
<AntTab label="Chequebook" {...a11yProps(1)} />
<AntTab label="Settlements" {...a11yProps(2)} />
</AntTabs>
<TabPanel value={value} index={0}>
<BalancesTable
peerBalances={peerBalances}
loading={isLoadingPeerBalances}
/>
<BalancesTable peerBalances={peerBalances} loading={isLoadingPeerBalances} />
</TabPanel>
<TabPanel value={value} index={1}>
<ChequebookTable
peerCheques={peerCheques}
loading={isLoadingPeerCheques}
/>
<ChequebookTable peerCheques={peerCheques} loading={isLoadingPeerCheques} />
</TabPanel>
<TabPanel value={value} index={2}>
<SettlementsTable
nodeSettlements={settlements}
loading={isLoadingSettlements}
/>
<SettlementsTable nodeSettlements={settlements} loading={isLoadingSettlements} />
</TabPanel>
</div>
:
props.isLoadingHealth || props.isLoadingNodeHealth ?
<Container style={{textAlign:'center', padding:'50px'}}>
<CircularProgress />
</Container>
:
<TroubleshootConnectionCard />
}
</div>
)
</div>
) : isLoadingHealth || isLoadingNodeHealth ? (
<Container style={{ textAlign: 'center', padding: '50px' }}>
<CircularProgress />
</Container>
) : (
<TroubleshootConnectionCard />
) /* eslint-enable no-nested-ternary */
}
</div>
)
}