generated from defi-wonderland/web3-react-boilerplate
-
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.
closes ZKS-111
- Loading branch information
Showing
5 changed files
with
51 additions
and
4 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
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 |
---|---|---|
|
@@ -50,7 +50,7 @@ | |
"type": "Validium" | ||
} | ||
], | ||
"total": 7000000, | ||
"total": 700000000, | ||
"tvl": [ | ||
{ | ||
"token": "ETH", | ||
|
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,3 +1,46 @@ | ||
export const truncateAddress = (address: string) => { | ||
return `${address.slice(0, 6)}...${address.slice(-4)}`; | ||
}; | ||
|
||
export function formatDataNumber(input: string | number, formatDecimal = 3, currency?: boolean, compact?: boolean) { | ||
const res: number = Number.parseFloat(input.toString()); | ||
|
||
if (res === 0 || isNaN(res)) return `${currency ? '$0' : '0'}`; | ||
|
||
if (res < 0.01) return formatSmallNumber(res); | ||
|
||
const userNotation = compact ? 'compact' : 'standard'; | ||
const notation = res > 1e12 ? 'scientific' : userNotation; | ||
|
||
return new Intl.NumberFormat('en-US', { | ||
maximumFractionDigits: formatDecimal, | ||
notation: notation, | ||
style: currency ? 'currency' : 'decimal', | ||
currency: 'USD', | ||
}).format(res); | ||
} | ||
|
||
export const formatSmallNumber = (value: number) => { | ||
if (value === 0) { | ||
return '0'; | ||
} | ||
|
||
const formattedValue = value.toString(); | ||
|
||
let numLeadingZeros = 0; | ||
|
||
// Count the leading zeros and decimal point | ||
for (let i = 0; i < formattedValue.length; i++) { | ||
if (formattedValue[i] === '0' || formattedValue[i] === '.') { | ||
numLeadingZeros++; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
// Return the number with 3 digits after the last leading zero | ||
const result = formattedValue.slice(0, numLeadingZeros + 3); | ||
|
||
// Trim any trailing zeros from the result | ||
return result.replace(/\.?0+$/, ''); | ||
}; |