blockchain-api
Version:
API utilities for interacting with the Exatechl2 blockchain
36 lines (35 loc) • 948 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateGasUsage = calculateGasUsage;
exports.formatGasToGwei = formatGasToGwei;
const formatters_1 = require("./formatters");
/**
*
* @param {string|number} gasUsed
* @param {string|number} gasLimit
* @returns {Object}
*/
function calculateGasUsage(gasUsed, gasLimit) {
const percentage = (0, formatters_1.calculateGasPercentage)(gasUsed, gasLimit);
let category;
if (percentage > 90) {
category = 'high';
}
else if (percentage > 75) {
category = 'medium';
}
else {
category = 'low';
}
return { percentage, category };
}
/**
*
* @param {string|number} gasPrice
* @param {number} decimals
* @returns {string}
*/
function formatGasToGwei(gasPrice, decimals = 2) {
const formatted = (0, formatters_1.formatGasValue)(gasPrice, 'gwei', decimals);
return formatted.replace(' Gwei', '');
}