From d9bb26c699071a3152357a6e53749083f0b44329 Mon Sep 17 00:00:00 2001 From: shanejonas Date: Tue, 14 Jan 2020 23:30:00 -0800 Subject: [PATCH] fix: add miner stats pagination by block range fixes #223 --- src/App.tsx | 5 ++ src/components/BlockList/BlockList.tsx | 36 +++++--- .../BlockPagination/BlockPagination.tsx | 35 ++++++++ src/components/BlockPagination/index.ts | 2 + src/components/MinerStats.tsx | 4 +- src/components/StatCharts/StatCharts.tsx | 86 +++++++++++++++++++ src/components/StatCharts/index.ts | 2 + src/containers/Dashboard.tsx | 64 +------------- src/containers/MinerStatsPage.tsx | 65 ++++++++++++-- src/translations/cn.ts | 19 ++-- src/translations/en.ts | 19 ++-- src/translations/kr.ts | 19 ++-- 12 files changed, 236 insertions(+), 120 deletions(-) create mode 100644 src/components/BlockPagination/BlockPagination.tsx create mode 100644 src/components/BlockPagination/index.ts create mode 100644 src/components/StatCharts/StatCharts.tsx create mode 100644 src/components/StatCharts/index.ts diff --git a/src/App.tsx b/src/App.tsx index 5e77a5b5..21c402da 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -88,6 +88,10 @@ function App(props: any) { useEffect(() => { if (selectedNetwork && selectedNetwork.name !== query.network) { setQuery({ network: selectedNetwork.name }); + history.push({ + pathname: history.location.pathname, + search: `?network=${selectedNetwork.name}`, + }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedNetwork, setQuery]); @@ -255,6 +259,7 @@ function App(props: any) { + diff --git a/src/components/BlockList/BlockList.tsx b/src/components/BlockList/BlockList.tsx index fa93cb49..963e5762 100644 --- a/src/components/BlockList/BlockList.tsx +++ b/src/components/BlockList/BlockList.tsx @@ -1,4 +1,4 @@ -import { Table, TableBody, TableCell, TableHead, TableRow, Typography, LinearProgress } from "@material-ui/core"; +import { Table, TableBody, TableCell, TableHead, TableRow, Typography, LinearProgress, Tooltip } from "@material-ui/core"; import * as React from "react"; import Link from "@material-ui/core/Link"; import { hexToDate, hexToNumber, hexToString } from "@etclabscore/eserialize"; @@ -60,29 +60,41 @@ function BlockList({ blocks }: any) { } // Calculate difference of block timestamp from that of parent. - const timeDifferenceFromParent = (index === sortedBlocks.length-1) ? 0 : hexToNumber(b.timestamp) - hexToNumber(sortedBlocks[index+1].timestamp); + const timeDifferenceFromParent = (index === sortedBlocks.length - 1) ? 0 : hexToNumber(b.timestamp) - hexToNumber(sortedBlocks[index + 1].timestamp); return ( - - + ( + + {children} + + )}> + {authorHashShort} + +  {hexToString(b.extraData).substring(0, 20)} + + + + ( - + {children} )}> - {authorHashShort} + {parseInt(b.number, 16)} -  {hexToString(b.extraData).substring(0,20)} - - {parseInt(b.number, 16)} - {t("Timestamp Date", { date: hexToDate(b.timestamp) })} ({+timeDifferenceFromParent > 0 ? `+${timeDifferenceFromParent}` : `-${timeDifferenceFromParent}`}s) + {t("Timestamp Date", { date: hexToDate(b.timestamp) })} ({timeDifferenceFromParent > 0 ? `+${timeDifferenceFromParent}` : `-${timeDifferenceFromParent}`}s) - {txTypes.transact}{txTypes.create === 0 ? "" : txTypes.create} + + {txTypes.create === 0 ? "" : txTypes.create} + + {txTypes.transact} @@ -91,7 +103,7 @@ function BlockList({ blocks }: any) { {hexToNumber(b.gasLimit)} - {b.uncles.length === 0 ? '' : b.uncles.length} + {b.uncles.length === 0 ? "" : b.uncles.length} void; + onPrev?: () => void; + style?: any; +} + +const BlockPagination: React.FC = (props) => { + + return ( + + + + + + + + + + + Showing {(props.to - props.from) + 1} Block Range: {props.to} - {props.from} + + + ); +}; + +export default BlockPagination; diff --git a/src/components/BlockPagination/index.ts b/src/components/BlockPagination/index.ts new file mode 100644 index 00000000..dc114b33 --- /dev/null +++ b/src/components/BlockPagination/index.ts @@ -0,0 +1,2 @@ +import BlockPagination from "./BlockPagination"; +export default BlockPagination; diff --git a/src/components/MinerStats.tsx b/src/components/MinerStats.tsx index 5b56a897..22b14967 100644 --- a/src/components/MinerStats.tsx +++ b/src/components/MinerStats.tsx @@ -54,7 +54,7 @@ const MinerStats: React.FC = ({blocks}) => { return ( - + = ({blocks}) => { - + } diff --git a/src/components/StatCharts/StatCharts.tsx b/src/components/StatCharts/StatCharts.tsx new file mode 100644 index 00000000..7b2fd2d2 --- /dev/null +++ b/src/components/StatCharts/StatCharts.tsx @@ -0,0 +1,86 @@ +import React from "react"; +import BigNumber from "bignumber.js"; +import { hashesToGH } from "../formatters"; +import { hexToNumber } from "@etclabscore/eserialize"; +import { Grid } from "@material-ui/core"; +import ChartCard from "../ChartCard"; +import { VictoryLine, VictoryBar, VictoryChart } from "victory"; +import { useTranslation } from "react-i18next"; + +const config = { + blockTime: 15, // seconds + blockHistoryLength: 100, + chartHeight: 200, + chartWidth: 400, +}; + +const blockMapGasUsed = (block: any) => { + return { + x: hexToNumber(block.number), + y: new BigNumber(block.gasUsed).dividedBy(1000000), + }; +}; + +const blockMapUncles = (block: any) => { + return { + x: hexToNumber(block.number), + y: block.uncles.length, + }; +}; + +const blockMapHashRate = (block: any) => { + return { + x: hexToNumber(block.number), + y: hashesToGH(new BigNumber(block.difficulty, 16).dividedBy(config.blockTime)), + }; +}; + +const blockMapTransactionCount = (block: any) => { + return { + x: hexToNumber(block.number), + y: block.transactions.length, + }; +}; + +interface IProps { + blocks: any[]; + victoryTheme?: any; +} + +const StatCharts: React.FC = ({ blocks, victoryTheme }) => { + const { t } = useTranslation(); + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +export default StatCharts; diff --git a/src/components/StatCharts/index.ts b/src/components/StatCharts/index.ts new file mode 100644 index 00000000..422e8c41 --- /dev/null +++ b/src/components/StatCharts/index.ts @@ -0,0 +1,2 @@ +import StatCharts from "./StatCharts"; +export default StatCharts; diff --git a/src/containers/Dashboard.tsx b/src/containers/Dashboard.tsx index 7faa1c59..e1df9e9e 100644 --- a/src/containers/Dashboard.tsx +++ b/src/containers/Dashboard.tsx @@ -1,9 +1,7 @@ import { Grid, Typography, CircularProgress, Theme, Button } from "@material-ui/core"; import useMultiGethStore from "../stores/useMultiGethStore"; -import BigNumber from "bignumber.js"; import * as React from "react"; -import { VictoryBar, VictoryChart, VictoryLine } from "victory"; -import { hashesToGH, weiToGwei } from "../components/formatters"; +import { weiToGwei } from "../components/formatters"; import HashRate from "../components/HashRate"; import getBlocks, { useBlockNumber } from "../helpers"; import useInterval from "use-interval"; @@ -15,6 +13,7 @@ import { hexToNumber } from "@etclabscore/eserialize"; import EthereumJSONRPC from "@etclabscore/ethereum-json-rpc"; import { useTranslation } from "react-i18next"; import { ArrowForwardIos } from "@material-ui/icons"; +import StatCharts from "../components/StatCharts"; const useState = React.useState; @@ -25,34 +24,6 @@ const config = { chartWidth: 400, }; -const blockMapGasUsed = (block: any) => { - return { - x: hexToNumber(block.number), - y: new BigNumber(block.gasUsed).dividedBy(1000000), - }; -}; - -const blockMapUncles = (block: any) => { - return { - x: hexToNumber(block.number), - y: block.uncles.length, - }; -}; - -const blockMapHashRate = (block: any) => { - return { - x: hexToNumber(block.number), - y: hashesToGH(new BigNumber(block.difficulty, 16).dividedBy(config.blockTime)), - }; -}; - -const blockMapTransactionCount = (block: any) => { - return { - x: hexToNumber(block.number), - y: block.transactions.length, - }; -}; - export default (props: any) => { const [erpc]: [EthereumJSONRPC] = useMultiGethStore(); const theme = useTheme(); @@ -166,37 +137,8 @@ export default (props: any) => { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +