-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(synapse-interface): Generalizes airdrop decimal display based on …
…SDK gasAirdropAmount [SLT-269] (#3196) * Generalizes airdrop decimal display based on SDK gasAirdropAmount
- Loading branch information
1 parent
3222ee8
commit aa37b50
Showing
4 changed files
with
43 additions
and
643 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
23 changes: 23 additions & 0 deletions
23
packages/synapse-interface/utils/getSignificantDecimals.ts
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,23 @@ | ||
export const getSignificantDecimals = ( | ||
numberString: string, | ||
defaultDecimals: number = 2 | ||
): number => { | ||
const parts = numberString.split('.') | ||
const decimalPart = parts[1] | ||
|
||
if (!decimalPart) return 0 | ||
|
||
if (/^0*$/.test(decimalPart)) { | ||
return defaultDecimals | ||
} | ||
|
||
let significantDecimals = 0 | ||
|
||
for (let i = 0; i < decimalPart.length; i++) { | ||
if (decimalPart[i] !== '0') { | ||
significantDecimals = i + 1 | ||
} | ||
} | ||
|
||
return significantDecimals | ||
} |
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.