From 118238ac0c813417f2b25aafd6fa88205e42bbfd Mon Sep 17 00:00:00 2001 From: eaxeax Date: Thu, 28 Apr 2022 19:16:51 +0300 Subject: [PATCH] feat(gasTable): total gas and total cost columns added --- lib/gasTable.js | 59 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/lib/gasTable.js b/lib/gasTable.js index 79786e3..c872c7e 100644 --- a/lib/gasTable.js +++ b/lib/gasTable.js @@ -28,20 +28,32 @@ class GasTable { let stats = {}; if (data.gasData.length) { - const total = data.gasData.reduce((acc, datum) => acc + datum, 0); - stats.average = Math.round(total / data.gasData.length); + stats.total = data.gasData.reduce((acc, datum) => acc + datum, 0); + + stats.average = Math.round(stats.total / data.gasData.length); stats.cost = this.config.ethPrice && this.config.gasPrice ? utils.gasToCost( - stats.average, - this.config.ethPrice, - this.config.gasPrice - ) + stats.average, + this.config.ethPrice, + this.config.gasPrice + ) + : colors.grey("-"); + + stats.totalCost = + this.config.ethPrice && this.config.gasPrice + ? utils.gasToCost( + stats.total, + this.config.ethPrice, + this.config.gasPrice + ) : colors.grey("-"); } else { stats.average = colors.grey("-"); stats.cost = colors.grey("-"); + stats.total = colors.grey("-"); + stats.totalCost = colors.grey("-"); } const sortedData = data.gasData.sort((a, b) => a - b); @@ -68,6 +80,9 @@ class GasTable { hAlign: "right", content: colors.green(stats.cost.toString()) }); + section.push({ hAlign: "right", content: stats.total }); + section.push({ hAlign: "right", content: stats.totalCost }); + methodRows.push(section); } @@ -85,17 +100,26 @@ class GasTable { let stats = {}; if (!contract.gasData.length) return; - const total = contract.gasData.reduce((acc, datum) => acc + datum, 0); - stats.average = Math.round(total / contract.gasData.length); + stats.total = contract.gasData.reduce((acc, datum) => acc + datum, 0);; + stats.average = Math.round(stats.total / contract.gasData.length); stats.percent = utils.gasToPercentOfLimit(stats.average, info.blockLimit); stats.cost = this.config.ethPrice && this.config.gasPrice ? utils.gasToCost( - stats.average, - this.config.ethPrice, - this.config.gasPrice - ) + stats.average, + this.config.ethPrice, + this.config.gasPrice + ) + : colors.grey("-"); + + stats.totalCost = + this.config.ethPrice && this.config.gasPrice + ? utils.gasToCost( + stats.total, + this.config.ethPrice, + this.config.gasPrice + ) : colors.grey("-"); const sortedData = contract.gasData.sort((a, b) => a - b); @@ -119,7 +143,8 @@ class GasTable { hAlign: "right", content: colors.green(stats.cost.toString()) }); - + section.push({ hAlign: "right", content: stats.total }); + section.push({ hAlign: "right", content: stats.totalCost }); deployRows.push(section); }); @@ -172,7 +197,7 @@ class GasTable { }, { hAlign: "center", - colSpan: 2, + colSpan: 4, content: colors.grey(`Block limit: ${info.blockLimit} gas`) } ]; @@ -210,7 +235,11 @@ class GasTable { colors.green("Max"), colors.green("Avg"), colors.bold("# calls"), - colors.bold(`${this.config.currency.toLowerCase()} (avg)`) + colors.bold(`${this.config.currency.toLowerCase()} (avg)`), + colors.green("Total gas"), + colors.green("Total cost"), + + ]; // ---------------------------------------------------------------------------------------------