forked from TrueFiEng/devcon-raffle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🍡 Display balance with less precision digits (#51)
Co-authored-by: Bartlomiej Tarczynski <[email protected]>
- Loading branch information
1 parent
b4657f9
commit ff866b6
Showing
3 changed files
with
18 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { formatEther } from 'viem' | ||
|
||
const decimalPlaces = 4 | ||
const factor = 10 ** decimalPlaces | ||
|
||
export function formatBalance(balance: bigint | undefined) { | ||
if (!balance) { | ||
return '-' | ||
} | ||
|
||
const balanceStr = formatEther(balance) | ||
const formattedValue = Math.round(Number(balanceStr) * factor) / factor | ||
return formattedValue.toString() | ||
} |