From 5ce99a5408f1b26fda46b006e798e794ac1e2882 Mon Sep 17 00:00:00 2001 From: asalef10 Date: Thu, 24 Apr 2025 11:14:46 +0300 Subject: [PATCH] Updated the formatBalance utility function --- .../VestingComponents/VestingStats.tsx | 4 ++-- src/pages/stakingPage/utils/formatters.ts | 21 +++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/pages/stakingPage/components/VestingComponents/VestingStats.tsx b/src/pages/stakingPage/components/VestingComponents/VestingStats.tsx index 7dcca07..011877f 100644 --- a/src/pages/stakingPage/components/VestingComponents/VestingStats.tsx +++ b/src/pages/stakingPage/components/VestingComponents/VestingStats.tsx @@ -40,7 +40,7 @@ export const VestingStats: React.FC = ({ - {vestingData ? formatBalance(vestingData.claimable) : '0.0000'} + {vestingData ? formatBalance(vestingData.claimable) : '0'} @@ -51,7 +51,7 @@ export const VestingStats: React.FC = ({ - {vestingData ? Number(formatBalance(vestingData.totalVested)).toFixed(2) : '0.0000'} + {vestingData ? formatBalance(vestingData.totalVested) : '0'} diff --git a/src/pages/stakingPage/utils/formatters.ts b/src/pages/stakingPage/utils/formatters.ts index ce6486c..6612e0e 100644 --- a/src/pages/stakingPage/utils/formatters.ts +++ b/src/pages/stakingPage/utils/formatters.ts @@ -1,23 +1,18 @@ /** - * Format balance with 4 decimal places and commas for large numbers + * Format balance with 2 decimal places and commas for large numbers */ export const formatBalance = (value: string): string => { try { // Convert scientific notation to regular number const num = Number(value); - if (isNaN(num)) return '0.0000'; + if (isNaN(num)) return '0.00'; - // If it's a large number, format it with commas - if (num > 1000) { - return num.toLocaleString('en-US', { - minimumFractionDigits: 4, - maximumFractionDigits: 4, - }); - } - - // Otherwise just show 4 decimal places - return num.toFixed(4); + // Format with 2 decimal places and commas for large numbers + return num.toLocaleString('en-US', { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }); } catch (error) { - return '0.0000'; + return '0.00'; } };