diff --git a/src/components/default/StatsPanel/StatsPanel.tsx b/src/components/default/StatsPanel/StatsPanel.tsx index f9f4017..12d96ff 100644 --- a/src/components/default/StatsPanel/StatsPanel.tsx +++ b/src/components/default/StatsPanel/StatsPanel.tsx @@ -32,17 +32,17 @@ function StatsPanel(props: { visibilityInfo?: VisibilityInfo | null, noStats?: b const transactions = info ? info.height + info.tx_count : 0; - const infoHeight = Utils.formatNumber(info?.height || 0, 0); - const posDiff = Utils.toShiftedNumber(info?.pos_difficulty || "0", 0, 0); - const powDiff = Utils.formatNumber(info?.pow_difficulty || 0, 0); - const coinsEmitted = Utils.toShiftedNumber(info?.total_coins || "0", 12); - const transactionsString = Utils.formatNumber(transactions, 0); - const hashrate = Utils.toShiftedNumber(info?.current_network_hashrate_350 || 0, NET_MODE === "TEST" ? 0 : 9, 3); + const infoHeight = Utils.formatNumber(info?.height, 0) || "..."; + const posDiff = Utils.toShiftedNumber(info?.pos_difficulty, 0, 0) || "..."; + const powDiff = Utils.formatNumber(info?.pow_difficulty, 0) || "..."; + const coinsEmitted = Utils.toShiftedNumber(info?.total_coins, 12) || "..."; + const transactionsString = Utils.formatNumber(transactions, 0) || "..."; + const hashrate = Utils.toShiftedNumber(info?.current_network_hashrate_350, NET_MODE === "TEST" ? 0 : 9, 3) || "..."; - const stackedCoins = Utils.toShiftedNumber(visibilityInfo?.amount.toString() || "0", 12); - const percentage = visibilityInfo?.percentage || "0"; - const APY = parseFloat((visibilityInfo?.apy || 0).toFixed(4)); - const devFund = Utils.toShiftedNumber(visibilityInfo?.balance.toString() || "0", 12); + const stackedCoins = Utils.toShiftedNumber(visibilityInfo?.amount.toString(), 12) || "..."; + const percentage = visibilityInfo?.percentage || "..."; + const APY = visibilityInfo?.apy ? parseFloat((visibilityInfo?.apy || 0).toFixed(4)) : "..."; + const devFund = Utils.toShiftedNumber(visibilityInfo?.balance.toString(), 12) || "..."; function TopItem(props: { title: string, amount: string, percent?: string, customCurrency?: boolean }) { const { title, amount, percent, customCurrency } = props; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 03a7d3c..6971325 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -19,7 +19,8 @@ class Utils { return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } - static formatNumber(number: number | string, decimalPlaces: number = 2): string { + static formatNumber(number: number | string | undefined, decimalPlaces: number = 2): string { + if (number === undefined) return ""; const parsedNumber = typeof number === "number" ? number : parseFloat(number) || 0; const roundedNumber = parsedNumber.toFixed(decimalPlaces); const [integerPart, decimalPart] = roundedNumber.split("."); @@ -28,7 +29,7 @@ class Utils { return formattedNumber; } - static toShiftedNumber(number: number | string, shift: number = 2, decimalPlaces: number = 2) { + static toShiftedNumber(number: number | string | undefined, shift: number = 2, decimalPlaces: number = 2) { if (typeof number !== "string" && typeof number !== "number") return ""; const string = typeof number === "string" ? number : number.toString(); const input = string.replace(/\D/g, "");