-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FRE-960] feat(widget-v2): swap page route logic (#206)
- Loading branch information
Showing
9 changed files
with
233 additions
and
30 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
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,30 @@ | ||
import { BigNumber } from "bignumber.js"; | ||
import { formatUnits } from "viem"; | ||
|
||
export function formatNumberWithCommas(str: string | number) { | ||
const parts = str.toString().split("."); | ||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); | ||
return parts.join("."); | ||
} | ||
|
||
export function formatNumberWithoutCommas(str: string | number) { | ||
return str.toString().replace(/,/g, ""); | ||
} | ||
|
||
export function getAmountWei(amount?: string, decimals = 6) { | ||
if (!amount || !amount) return "0"; | ||
try { | ||
return new BigNumber(formatNumberWithoutCommas(amount)).shiftedBy(decimals ?? 6).toFixed(0); | ||
} catch (_err) { | ||
return "0"; | ||
} | ||
} | ||
|
||
export function parseAmountWei(amount?: string, decimals = 6) { | ||
if (!amount) return "0"; | ||
try { | ||
return formatUnits(BigInt(amount.replace(/,/g, "")), decimals ?? 6); | ||
} catch (_err) { | ||
return "0"; | ||
} | ||
} |
Oops, something went wrong.