import { ReactElement, useState, ChangeEvent, ReactChild } from 'react' import { withStyles, Theme, createStyles, makeStyles } 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 { useApiNodeAddresses, useApiChequebookAddress, useApiChequebookBalance, useApiPeerBalances, useApiPeerCheques, useApiSettlements, useApiHealth, useDebugApiHealth, } from '../../hooks/apiHooks' interface TabPanelProps { children?: ReactChild index: number value: number } function a11yProps(index: number) { return { id: `simple-tab-${index}`, 'aria-controls': `simple-tabpanel-${index}`, } } const useStyles = makeStyles((theme: Theme) => createStyles({ root: { width: '100%', display: 'grid', rowGap: theme.spacing(3), }, }), ) export default function Accounting(): ReactElement { const [value, setValue] = useState(0) const classes = useStyles() const handleChange = (event: ChangeEvent, newValue: number) => { setValue(newValue) } 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() function TabPanel(props: TabPanelProps) { const { children, value, index, ...other } = props return ( ) } 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', }, }, }), )((props: StyledTabProps) => ) return (
{ // FIXME: this should be broken up /* eslint-disable no-nested-ternary */ nodeHealth?.status === 'ok' && health ? (
) : isLoadingHealth || isLoadingNodeHealth ? ( ) : ( ) /* eslint-enable no-nested-ternary */ }
) }