blockchain-api
Version:
API utilities for interacting with the Exatechl2 blockchain
46 lines (45 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNetworkStats = getNetworkStats;
exports.formatNumber = formatNumber;
exports.formatPercentChange = formatPercentChange;
const core_1 = require("../../core");
/**
*
* @returns
*/
async function getNetworkStats() {
try {
const response = await (0, core_1.callExplorerApi)('stats');
if (response && response.status === 'success' && response.data) {
return response.data;
}
throw new Error('Invalid response format from explorer API');
}
catch (error) {
console.error('Error fetching network stats:', error);
throw error;
}
}
/**
*
* @param value
* @returns
*/
function formatNumber(value) {
if (value === null || value === undefined)
return '0';
const num = typeof value === 'string' ? parseFloat(value) : value;
return num.toLocaleString();
}
/**
*
* @param value
* @returns
*/
function formatPercentChange(value) {
if (value === null || value === undefined)
return '0%';
const sign = value > 0 ? '+' : '';
return `${sign}${value.toFixed(1)}%`;
}