import * as React from 'react'; import { Connection } from '../Connection'; import { Icon } from './Icon'; import { Types, Maybe } from '@dotstats/common'; import stable from 'stable'; import githubIcon from '../icons/mark-github.svg'; import './Chains.css'; interface ChainData { label: Types.ChainLabel; nodeCount: Types.NodeCount; } export namespace Chains { export interface Props { chains: Map, subscribed: Maybe, connection: Promise } } export class Chains extends React.Component { public render() { return (
{ this.chains.map((chain) => this.renderChain(chain)) }
); } private renderChain(chain: ChainData): React.ReactNode { const { label, nodeCount } = chain; const className = label === this.props.subscribed ? 'Chains-chain Chains-chain-selected' : 'Chains-chain'; return ( {label} {nodeCount} ) } private get chains(): ChainData[] { return stable .inplace( Array.from(this.props.chains.entries()), (a, b) => b[1] - a[1] ) .map(([label, nodeCount]) => ({ label, nodeCount })); } private async subscribe(chain: Types.ChainLabel) { const connection = await this.props.connection; connection.subscribe(chain); } }