UNPKG

blockchain-api

Version:

API utilities for interacting with the Exatechl2 blockchain

42 lines (35 loc) 1 kB
import {formatGasValue, calculateGasPercentage } from './formatters'; /** * * @param {string|number} gasUsed * @param {string|number} gasLimit * @returns {Object} */ export function calculateGasUsage( gasUsed: string | number | undefined, gasLimit: string | number | undefined ): { percentage: number; category: 'low' | 'medium' | 'high' } { const percentage = calculateGasPercentage(gasUsed, gasLimit); let category: 'low' | 'medium' | 'high'; 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} */ export function formatGasToGwei( gasPrice: string | number | undefined, decimals = 2 ): string { const formatted = formatGasValue(gasPrice, 'gwei', decimals); return formatted.replace(' Gwei', ''); }