diff --git a/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte b/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte index 3f6127eaae..0e36e29447 100644 --- a/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte @@ -14,7 +14,7 @@ } from '@iota/sdk/out/types' import { closePopup } from '@desktop/auxiliary/popup' import { api, getClient } from '@core/profile-manager' - import { formatTokenAmountPrecise } from '@core/token' + import { formatTokenAmountBestMatch } from '@core/token' import { getActiveNetworkId } from '@core/network' import PopupTemplate from '../PopupTemplate.svelte' @@ -38,7 +38,7 @@ try { const client = await getClient() const resp = await client.buildAliasOutput(params) - storageDeposit = formatTokenAmountPrecise(Number(resp.amount), getBaseToken()) + storageDeposit = formatTokenAmountBestMatch(BigInt(resp.amount), getBaseToken()) } catch (err) { handleError(err) } diff --git a/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte b/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte index 1aa2c0984e..b93fc753eb 100644 --- a/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte @@ -7,7 +7,7 @@ import { getBaseToken, checkActiveProfileAuth } from '@core/profile/actions' import { mintNativeToken, mintTokenDetails, buildFoundryOutputBuilderParams, IMintTokenDetails } from '@core/wallet' import { closePopup, openPopup, PopupId } from '@desktop/auxiliary/popup' - import { IIrc30Metadata, TokenStandard, formatTokenAmountPrecise } from '@core/token' + import { IIrc30Metadata, TokenStandard, formatTokenAmountBestMatch } from '@core/token' import { getClient } from '@core/profile-manager' import PopupTemplate from '../PopupTemplate.svelte' @@ -28,7 +28,7 @@ ) const client = await getClient() const preparedOutput = await client.buildFoundryOutput(foundryOutputParams) - storageDeposit = formatTokenAmountPrecise(Number(preparedOutput.amount) ?? 0, getBaseToken()) + storageDeposit = formatTokenAmountBestMatch(BigInt(preparedOutput.amount ?? 0), getBaseToken()) } } diff --git a/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte b/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte index b020a204b9..030f2a6a8f 100644 --- a/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte @@ -6,7 +6,7 @@ import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts' import { getClient } from '@core/profile-manager' import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions' - import { formatTokenAmountPrecise } from '@core/token' + import { formatTokenAmountBestMatch } from '@core/token' import { buildNftOutputBuilderParams, mintNftCollection, mintNftCollectionDetails } from '@core/wallet' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' import { MediaIcon, PopupTab, getTabItems } from '@ui' @@ -103,7 +103,7 @@ items={[ { key: localize('general.storageDeposit'), - value: formatTokenAmountPrecise(storageDeposit, getBaseToken()), + value: formatTokenAmountBestMatch(BigInt(storageDeposit), getBaseToken()), }, { key: localize('general.immutableIssuer'), diff --git a/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte b/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte index c1385fe69e..036a87176e 100644 --- a/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte @@ -6,7 +6,7 @@ import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts' import { getClient } from '@core/profile-manager' import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions' - import { formatTokenAmountPrecise } from '@core/token' + import { formatTokenAmountBestMatch } from '@core/token' import { buildNftOutputBuilderParams, mintNft, mintNftDetails } from '@core/wallet' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' import { MediaIcon, PopupTab, getTabItems } from '@ui' @@ -125,20 +125,22 @@ { key: localize('general.storageDepositPerNft'), value: - quantity > 1 ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) : undefined, + quantity > 1 + ? formatTokenAmountBestMatch(storageDeposit, getBaseToken()) + : undefined, }, { key: localize('general.totalStorageDeposit'), value: quantity > 1 - ? formatTokenAmountPrecise(totalStorageDeposit, getBaseToken()) + ? formatTokenAmountBestMatch(totalStorageDeposit, getBaseToken()) : undefined, }, { key: localize('general.storageDeposit'), value: quantity === 1 - ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) + ? formatTokenAmountBestMatch(storageDeposit, getBaseToken()) : undefined, }, { diff --git a/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte b/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte index d03358c5cb..760e3165f3 100644 --- a/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte +++ b/packages/desktop/views/dashboard/collectibles/components/Irc27CollectibleDetails.svelte @@ -4,7 +4,7 @@ import { ExplorerEndpoint, getActiveNetworkId, getDefaultExplorerUrl } from '@core/network' import { IIrc27Nft } from '@core/nfts' import { getBaseToken } from '@core/profile/actions' - import { formatTokenAmountPrecise } from '@core/token' + import { formatTokenAmountBestMatch } from '@core/token' import { getBech32AddressFromAddressTypes, getHexAddressFromAddressTypes } from '@core/wallet' import { AddressType } from '@iota/sdk/out/types' import { NetworkLabel } from '@ui' @@ -51,7 +51,7 @@ }, { key: localize('general.storageDeposit'), - value: storageDeposit ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) : undefined, + value: storageDeposit ? formatTokenAmountBestMatch(storageDeposit, getBaseToken()) : undefined, }, { key: localize('general.standard'), diff --git a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts index b138e035ed..92fe293821 100644 --- a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts @@ -10,7 +10,6 @@ const IOTA_BASE_TOKEN: IBaseToken = { unit: 'IOTA', decimals: 6, subunit: 'micro', - useMetricPrefix: false, } export const SHIMMER_BASE_TOKEN: IBaseToken = { @@ -20,7 +19,6 @@ export const SHIMMER_BASE_TOKEN: IBaseToken = { unit: 'SMR', decimals: 6, subunit: 'glow', - useMetricPrefix: false, } export const EVM_BASE_TOKEN: IBaseToken = { diff --git a/packages/shared/src/lib/core/token/interfaces/base-token.interface.ts b/packages/shared/src/lib/core/token/interfaces/base-token.interface.ts index 355ccd1fc8..4c91bcf5e4 100644 --- a/packages/shared/src/lib/core/token/interfaces/base-token.interface.ts +++ b/packages/shared/src/lib/core/token/interfaces/base-token.interface.ts @@ -7,5 +7,4 @@ export interface IBaseToken { unit: string subunit?: string | null decimals: number - useMetricPrefix?: boolean } diff --git a/packages/shared/src/lib/core/token/tests/convertToRawAmount.test.ts b/packages/shared/src/lib/core/token/tests/convertToRawAmount.test.ts index 87688df736..64e8c045ce 100644 --- a/packages/shared/src/lib/core/token/tests/convertToRawAmount.test.ts +++ b/packages/shared/src/lib/core/token/tests/convertToRawAmount.test.ts @@ -9,7 +9,6 @@ const WEB3_TOKEN_METADATA: TokenMetadata = { unit: 'RAWR', decimals: 60, subunit: 'MEOW', - useMetricPrefix: false, standard: TokenStandard.BaseToken, } @@ -32,27 +31,25 @@ describe('File: convertToRawAmount.ts', () => { }) describe('given the tokenMetadata standard is BaseToken', () => { - describe("given useMetricPrefix is false (currently Shimmer's case)", () => { - const networkId = SupportedNetworkId.Shimmer - it("should return amount * decimal property if selectedUnit is unit and baseToken's decimal is less than MAX_SUPPORTED_DECIMALS", () => { - let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'SMR')?.toString() ?? '0' - expect(value).toStrictEqual('1000000') - }) - it("should return XXX if selectedUnit is unit and baseToken's decimals property is greater than MAX_SUPPORTED_DECIMALS", () => { - let value = convertToRawAmount('1', WEB3_TOKEN_METADATA, 'RAWR')?.toString() ?? '0' - expect(value).toStrictEqual('1000000000000000000000000000000000000000000000000000000000000') - }) - it('should return same amount if selectedUnit is subunit', () => { - let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'glow')?.toString() ?? '0' - expect(value).toStrictEqual('1') - }) - it('should return base tokens unit if no unit is provided', () => { - let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId])?.toString() ?? '0' - expect(value).toStrictEqual('1000000') - }) - it('should return undefined if provided unit does not match the tokenMetadata unit or subunit', () => { - expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'test')).toStrictEqual(undefined) - }) + const networkId = SupportedNetworkId.Shimmer + it("should return amount * decimal property if selectedUnit is unit and baseToken's decimal is less than MAX_SUPPORTED_DECIMALS", () => { + let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'SMR')?.toString() ?? '0' + expect(value).toStrictEqual('1000000') + }) + it("should return XXX if selectedUnit is unit and baseToken's decimals property is greater than MAX_SUPPORTED_DECIMALS", () => { + let value = convertToRawAmount('1', WEB3_TOKEN_METADATA, 'RAWR')?.toString() ?? '0' + expect(value).toStrictEqual('1000000000000000000000000000000000000000000000000000000000000') + }) + it('should return same amount if selectedUnit is subunit', () => { + let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'glow')?.toString() ?? '0' + expect(value).toStrictEqual('1') + }) + it('should return base tokens unit if no unit is provided', () => { + let value = convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId])?.toString() ?? '0' + expect(value).toStrictEqual('1000000') + }) + it('should return undefined if provided unit does not match the tokenMetadata unit or subunit', () => { + expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[networkId], 'test')).toStrictEqual(undefined) }) }) describe('given the tokenMetadata standard is Irc30', () => { diff --git a/packages/shared/src/lib/core/token/utils/formatTokenAmountPrecise.ts b/packages/shared/src/lib/core/token/utils/formatTokenAmountPrecise.ts deleted file mode 100644 index bc8f448f80..0000000000 --- a/packages/shared/src/lib/core/token/utils/formatTokenAmountPrecise.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { formatNumber } from '@core/i18n' -import { TokenStandard } from '@core/token/enums' -import { TokenMetadata } from '@core/token/types' - -export function formatTokenAmountPrecise(amount: number, tokenMetadata: TokenMetadata): string { - const formattedAmount = formatNumber(amount, 0, 0, 0, true) - if (tokenMetadata.standard === TokenStandard.BaseToken) { - if (tokenMetadata?.useMetricPrefix) { - return formattedAmount + ' ' + tokenMetadata?.unit - } else { - return formattedAmount + ' ' + tokenMetadata?.subunit - } - } else { - return formattedAmount + ' ' + tokenMetadata?.symbol - } -} diff --git a/packages/shared/src/lib/core/token/utils/index.ts b/packages/shared/src/lib/core/token/utils/index.ts index e2ff382912..ebcfa65483 100644 --- a/packages/shared/src/lib/core/token/utils/index.ts +++ b/packages/shared/src/lib/core/token/utils/index.ts @@ -1,7 +1,6 @@ export * from './buildPersistedTokenFromMetadata' export * from './convertToRawAmount' export * from './formatTokenAmountBestMatch' -export * from './formatTokenAmountPrecise' export * from './getMaxDecimalsFromTokenMetadata' export * from './getTokenInitials' export * from './getUnitFromTokenMetadata' diff --git a/packages/shared/src/locales/en.json b/packages/shared/src/locales/en.json index 24576b9ee4..25f6af5768 100644 --- a/packages/shared/src/locales/en.json +++ b/packages/shared/src/locales/en.json @@ -980,8 +980,7 @@ "tickerSymbol": "Ticker", "unit": "Unit", "subunit": "Sub-unit", - "decimals": "Decimals", - "useMetricPrefix": "Use metric prefix" + "decimals": "Decimals" } }, "jwt": "JSON web token", diff --git a/packages/shared/test/mocks/profile-manager.mock.ts b/packages/shared/test/mocks/profile-manager.mock.ts index 5b8ca71190..af28132f0f 100644 --- a/packages/shared/test/mocks/profile-manager.mock.ts +++ b/packages/shared/test/mocks/profile-manager.mock.ts @@ -116,7 +116,6 @@ export class ProfileManagerMock implements IProfileManager { unit: 'SMR', subunit: 'glow', decimals: 6, - useMetricPrefix: false, }, metrics: { blocksPerSecond: 1.3,