diff --git a/src/components/BlockView/BlockGasPrice.tsx b/src/components/BlockView/BlockGasPrice.tsx index 9eaf8951..806bf02a 100644 --- a/src/components/BlockView/BlockGasPrice.tsx +++ b/src/components/BlockView/BlockGasPrice.tsx @@ -1,36 +1,57 @@ import * as React from "react"; import { hexToNumber } from "@etclabscore/eserialize"; import { useTranslation } from "react-i18next"; -import {meanBy, minBy, maxBy} from "lodash"; - import { TableCell, TableRow } from "@material-ui/core"; +const BigIntMinBy = (list: [], func: (item: any) => BigInt): any => { + let min: any; + for (const item of list) { + if (min === undefined) { + min = item; + continue; + } + const r = func(item); + if (r < func(min)) { + min = item; + } + } + return min; +}; + +const BigIntMaxBy = (list: [], func: (item: any) => BigInt): any => { + let max: any; + for (const item of list) { + if (max === undefined) { + max = item; + continue; + } + const r = func(item); + if (r > func(max)) { + max = item; + } + } + return max; +}; + function BlockGasPrice(props: any) { const { t } = useTranslation(); - const {transactions} = props.block; + const { transactions } = props.block; - if (transactions.length === 0) {return <>;} + if (transactions.length === 0) { return null; } return ( <> - - {t("Average Gas Price")} - - { meanBy(transactions, (t: any) => BigInt(t.gasPrice)) } - - - {t("Min Gas Price")} - { hexToNumber(minBy(transactions, (t: any) => BigInt(t.gasPrice)).gasPrice) } + {hexToNumber(BigIntMinBy(transactions, (tx: any) => BigInt(tx.gasPrice))?.gasPrice || "")} {t("Max Gas Price")} - { hexToNumber(maxBy(transactions, (t: any) => BigInt(t.gasPrice)).gasPrice) } + {hexToNumber(BigIntMaxBy(transactions, (tx: any) => BigInt(tx.gasPrice))?.gasPrice) || ""}