-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: format units according to asset decimals + unknown asset (#115)
Closes FE-31 this PR address fully the format of amounts being showed across the explorer. will format to assets decimal config OR format the raw amount if it’s a unknown asset (unknown asset decimals) - update to `fuels/assets@0.1.3` to get new asset utils functions - share assetId with components that didn’t have it - apply correct amount formatted to this pages/components - BalanceItem - Utxos - TxAssetItem - TxInput - TxOutput
- Loading branch information
1 parent
9351a8b
commit fe981bd
Showing
10 changed files
with
147 additions
and
32 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,12 @@ | ||
import { CHAIN_IDS, getAssetFuel } from '@fuels/assets'; | ||
import type { Asset } from '@fuels/assets'; | ||
import { useMemo } from 'react'; | ||
|
||
export const useFuelAsset = (asset?: Asset | null) => { | ||
const fuelAsset = useMemo( | ||
() => (asset ? getAssetFuel(asset, CHAIN_IDS.fuel.beta4) : undefined), | ||
[asset?.symbol, asset?.name, asset?.networks.length], | ||
); | ||
|
||
return fuelAsset; | ||
}; |
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,13 @@ | ||
import type { BNInput } from 'fuels'; | ||
import { bn } from 'fuels'; | ||
|
||
/** | ||
* Formats the given amount by multiplying it by 10 and formatting it with 1 unit. | ||
* This is a workaround because formatting with zero units doesn't work. | ||
* @param amount - The amount to format. | ||
* @returns The formatted amount. | ||
*/ | ||
export function formatZeroUnits(amount: BNInput) { | ||
const formatted = bn(amount).mul(10).format({ units: 1, precision: 0 }); | ||
return formatted; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.