-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(govern) feat: migrate veOlas to govern
- Loading branch information
Atatakai
authored and
Atatakai
committed
Aug 8, 2024
1 parent
392c02b
commit 0e15424
Showing
33 changed files
with
2,031 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
import isNil from 'lodash/isNil'; | ||
|
||
/** | ||
* Return formatted number with appropriate suffix | ||
*/ | ||
export const formatWeiNumber = ({ | ||
value, | ||
minimumFractionDigits = 0, | ||
maximumFractionDigits = 2, | ||
}: { | ||
value: number | string | undefined; | ||
minimumFractionDigits?: number; | ||
maximumFractionDigits?: number; | ||
}) => { | ||
if (isNil(value) || Number(value) === 0) return '0'; | ||
|
||
return new Intl.NumberFormat('en', { | ||
notation: 'compact', | ||
minimumFractionDigits, | ||
maximumFractionDigits, | ||
}).format(Number(value)); | ||
}; | ||
|
||
/** | ||
* @param {number} balanceInWei | ||
* @returns formatted balance with appropriate suffix | ||
* Converts a number to a comma separated format | ||
* eg: 1000000 => 1,000,000, 12345.67 => 12,345.67 | ||
*/ | ||
export const formatWeiBalance = (balanceInWei: number | string) => { | ||
const formatNumberWithSuffix = (number: number) => { | ||
if (number >= 1e9) { | ||
return `${Math.floor((number / 1e9) * 10) / 10}B`; | ||
} | ||
if (number >= 1e6) { | ||
return `${Math.floor((number / 1e6) * 10) / 10}M`; | ||
} | ||
if (number >= 1e3) { | ||
return `${Math.floor((number / 1e3) * 10) / 10}k`; | ||
} | ||
return Math.floor(number * 10) / 10; | ||
}; | ||
export const getCommaSeparatedNumber = (value: number | string | undefined) => { | ||
if (isNil(value) || Number(value) === 0) return '0'; | ||
|
||
return formatNumberWithSuffix(parseFloat(`${balanceInWei}`)); | ||
return new Intl.NumberFormat('en', { | ||
maximumFractionDigits: 2, | ||
}).format(Number(value)); | ||
}; |
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
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
Oops, something went wrong.