import React from 'react' import type { ChainId } from '@usedapp/core' import { useBlockMeta, useChainMeta, useChainState, useEtherBalance, useEthers } from '@usedapp/core' import { ContentBlock, ContentRow } from '../base/base' import { Label } from '../../typography/Label' import { TextInline } from '../../typography/Text' import { formatEther } from '@ethersproject/units' import styled from 'styled-components' interface ChainStateProps { chainId: ChainId } export function ChainState({ chainId }: ChainStateProps) { const { chainName } = useChainMeta(chainId) const { value } = useChainState({ chainId }) ?? {} const { difficulty, timestamp } = useBlockMeta({ chainId }) const { account } = useEthers() const balance = useEtherBalance(account, { chainId }) return ( {chainId} {value?.blockNumber} {difficulty && ( {difficulty.toString()} )} {timestamp && ( {timestamp.toLocaleString()} )} {balance && ( {formatEther(balance)} )} ) } const ChainBlock = styled(ContentBlock)` margin-right: 5px; margin-bottom: 5px; width: calc(50% - 5px); height: 260px; `