-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use amount.display to avoid rounding... * don't expose raw error!!! * rewrite amount formatting util * hack to truncate balances in UI
- Loading branch information
1 parent
5071501
commit a40a8d0
Showing
7 changed files
with
43 additions
and
33 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,24 @@ | ||
import { getTokenDecimals } from 'utils'; | ||
import { amount, Chain } from '@wormhole-foundation/sdk'; | ||
import { TokenConfig } from 'config/types'; | ||
|
||
export const formatAmount = ( | ||
chain: Chain, | ||
token: TokenConfig, | ||
val: string | bigint | null, | ||
truncate?: number, | ||
): string | null => { | ||
if (!val) { | ||
return null; | ||
} | ||
|
||
const decimals = getTokenDecimals(chain, token.tokenId); | ||
|
||
let balanceAmount = amount.fromBaseUnits(BigInt(val), decimals); | ||
|
||
if (truncate) { | ||
balanceAmount = amount.truncate(balanceAmount, truncate); | ||
} | ||
|
||
return amount.display(balanceAmount); | ||
}; |
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