diff --git a/packages/desktop/components/popups/NodeInfoPopup.svelte b/packages/desktop/components/popups/NodeInfoPopup.svelte index 73599496cc3..765ac2294e6 100644 --- a/packages/desktop/components/popups/NodeInfoPopup.svelte +++ b/packages/desktop/components/popups/NodeInfoPopup.svelte @@ -2,7 +2,8 @@ import { onMount } from 'svelte' import { Button, Checkbox, CopyableBox, Spinner, Text } from 'shared/components' import { formatNumber, localize } from '@core/i18n' - import { INode, INodeInfo } from '@core/network' + import { INode } from '@core/network' + import { INodeInfo } from '@iota/sdk/out/types' import { closePopup } from '@auxiliary/popup' import { showAppNotification } from '@auxiliary/notification' import { resolveObjectPath, setClipboard } from '@core/utils' diff --git a/packages/desktop/views/onboarding/views/restore-from-stronghold/views/ImportStrongholdView.svelte b/packages/desktop/views/onboarding/views/restore-from-stronghold/views/ImportStrongholdView.svelte index de291337ab3..73beefe68e1 100644 --- a/packages/desktop/views/onboarding/views/restore-from-stronghold/views/ImportStrongholdView.svelte +++ b/packages/desktop/views/onboarding/views/restore-from-stronghold/views/ImportStrongholdView.svelte @@ -79,7 +79,7 @@ async function shouldMigrate(): Promise { try { - await restoreBackup(importFilePath, '', $onboardingProfile.network.protocol.bech32Hrp) + await restoreBackup(importFilePath, '', $onboardingProfile.network.bech32Hrp) } catch (err) { const isMigrationRequired = CLIENT_ERROR_REGEXES[ClientError.MigrationRequired].test(err?.error) return isMigrationRequired diff --git a/packages/desktop/views/onboarding/views/restore-profile/views/ClaimFinderView.svelte b/packages/desktop/views/onboarding/views/restore-profile/views/ClaimFinderView.svelte index f9e88dd9c01..8d4f2e46bf5 100644 --- a/packages/desktop/views/onboarding/views/restore-profile/views/ClaimFinderView.svelte +++ b/packages/desktop/views/onboarding/views/restore-profile/views/ClaimFinderView.svelte @@ -36,6 +36,8 @@ import { onDestroy, onMount } from 'svelte' import { restoreProfileRouter } from '../restore-profile-router' import { AnimationEnum } from '@auxiliary/animation' + import { getBaseToken } from '@core/profile' + import { getAndUpdateNodeInfo } from '@core/network' $: shimmerClaimingAccounts = $onboardingProfile?.shimmerClaimingAccounts ?? [] @@ -172,7 +174,8 @@ } } - onMount(() => { + onMount(async () => { + await getAndUpdateNodeInfo() void ledgerRaceConditionProtectionWrapper(setupShimmerClaiming) }) @@ -199,10 +202,7 @@ {#if shimmerClaimingAccounts && shimmerClaimingAccounts?.length > 0}
{#each shimmerClaimingAccounts as shimmerClaimingAccount} - + {/each}
{/if} diff --git a/packages/shared/components/AssetIcon.svelte b/packages/shared/components/AssetIcon.svelte index b91f112f1a8..adc525add08 100644 --- a/packages/shared/components/AssetIcon.svelte +++ b/packages/shared/components/AssetIcon.svelte @@ -2,7 +2,7 @@ import { AnimationRenderer } from '@auxiliary/animation' import { Icon as IconEnum, NETWORK_ICON_SVG } from '@auxiliary/icon' import { getIconColorFromString } from '@core/account' - import { COIN_TYPE, DEFAULT_BASE_TOKEN, NetworkId } from '@core/network' + import { COIN_TYPE, NetworkId } from '@core/network' import { isBright } from '@core/utils' import { ANIMATED_TOKEN_IDS, IPersistedAsset, TokenStandard, getAssetInitials } from '@core/wallet' import { Animation, AssetIconSize, Icon, VerificationBadge } from 'shared/components' @@ -17,6 +17,8 @@ let assetIconWrapperWidth: number let assetLogoUrl: string + const IOTA_NAMES = [NetworkId.Iota, 'tst'] + $: isAnimation = asset.id in ANIMATED_TOKEN_IDS $: asset, updateAssetIcon() $: assetIconColor = isBright(assetIconBackgroundColor) ? 'text-gray-800' : 'text-white' @@ -42,19 +44,13 @@ ].includes(assetId) ) { assetIconBackgroundColor = '#C4D1E8' - } else if (String(DEFAULT_BASE_TOKEN[NetworkId.Iota]?.name?.toLowerCase()) === assetName) { + } else if (String(NetworkId.Iota) === assetName) { assetIconBackgroundColor = '#000000' - } else if (String(DEFAULT_BASE_TOKEN[NetworkId.Shimmer]?.name?.toLowerCase()) === assetName) { + } else if (String(NetworkId.Shimmer) === assetName) { assetIconBackgroundColor = '#25DFCA' } - if ( - [ - String(DEFAULT_BASE_TOKEN[NetworkId.Iota]?.name?.toLowerCase()), - String(DEFAULT_BASE_TOKEN[NetworkId.IotaTestnet]?.name?.toLowerCase()), - String(DEFAULT_BASE_TOKEN[NetworkId.IotaAlphanet]?.name?.toLowerCase()), - ].includes(assetName) - ) { + if (IOTA_NAMES.includes(assetName)) { icon = NETWORK_ICON_SVG[NetworkId.Iota] } else { icon = NETWORK_ICON_SVG[NetworkId.Shimmer] diff --git a/packages/shared/lib/contexts/onboarding/actions/findShimmerRewards.ts b/packages/shared/lib/contexts/onboarding/actions/findShimmerRewards.ts index 61b4f32fcbf..4d9d02b9200 100644 --- a/packages/shared/lib/contexts/onboarding/actions/findShimmerRewards.ts +++ b/packages/shared/lib/contexts/onboarding/actions/findShimmerRewards.ts @@ -2,19 +2,19 @@ import { showAppNotification } from '@auxiliary/notification' import { IAccount } from '@core/account' import { localize } from '@core/i18n' import { updateLedgerNanoStatus } from '@core/ledger' -import { AccountRecoveryProfileConfiguration, ProfileType, UnableToFindProfileTypeError } from '@core/profile' +import { + AccountRecoveryProfileConfiguration, + ProfileType, + UnableToFindProfileTypeError, + getBaseToken, +} from '@core/profile' import { RecoverAccountsPayload, recoverAccounts } from '@core/profile-manager' import { zip } from '@core/utils' import { formatTokenAmountBestMatch } from '@core/wallet/utils' import { get } from 'svelte/store' import { SHIMMER_CLAIMING_ACCOUNT_RECOVERY_CONFIGURATION, SHIMMER_CLAIMING_ACCOUNT_SYNC_OPTIONS } from '../constants' import { getSortedRenamedBoundAccounts, prepareShimmerClaimingAccount } from '../helpers' -import { - getOnboardingBaseToken, - onboardingProfile, - shimmerClaimingProfileManager, - updateShimmerClaimingAccount, -} from '../stores' +import { onboardingProfile, shimmerClaimingProfileManager, updateShimmerClaimingAccount } from '../stores' import { sumTotalUnclaimedRewards } from '../utils' const DEPTH_SEARCH_ACCOUNT_START_INDEX = 0 @@ -161,7 +161,7 @@ export function setTotalUnclaimedShimmerRewards(_totalUnclaimedShimmerRewards: n function showRewardsFoundNotification(updatedTotalUnclaimedShimmerRewards: number): void { const foundRewardsAmount = updatedTotalUnclaimedShimmerRewards - totalUnclaimedShimmerRewards - const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getOnboardingBaseToken()) + const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getBaseToken()) showAppNotification({ type: 'success', alert: true, diff --git a/packages/shared/lib/contexts/onboarding/actions/restoreBackupFromStrongholdFile.ts b/packages/shared/lib/contexts/onboarding/actions/restoreBackupFromStrongholdFile.ts index 4d8b756cb5a..380c1784fe8 100644 --- a/packages/shared/lib/contexts/onboarding/actions/restoreBackupFromStrongholdFile.ts +++ b/packages/shared/lib/contexts/onboarding/actions/restoreBackupFromStrongholdFile.ts @@ -7,7 +7,7 @@ import { onboardingProfile } from '../stores' export async function restoreBackupFromStrongholdFile(strongholdPassword: string): Promise { const { id, importFilePath, clientOptions, network } = get(onboardingProfile) try { - await restoreBackup(importFilePath, strongholdPassword, network.protocol.bech32Hrp) + await restoreBackup(importFilePath, strongholdPassword, network.bech32Hrp) } catch (err) { const storageDirectory = await getStorageDirectoryOfProfile(id) await restoreBackupByCopyingFile( diff --git a/packages/shared/lib/contexts/onboarding/actions/syncShimmerClaimingAccount.ts b/packages/shared/lib/contexts/onboarding/actions/syncShimmerClaimingAccount.ts index ae003e641f0..7acaea7e830 100644 --- a/packages/shared/lib/contexts/onboarding/actions/syncShimmerClaimingAccount.ts +++ b/packages/shared/lib/contexts/onboarding/actions/syncShimmerClaimingAccount.ts @@ -6,10 +6,11 @@ import { getAccount, profileManager } from '@core/profile-manager' import { MissingShimmerClaimingProfileManagerError } from '../errors' import { prepareShimmerClaimingAccount } from '../helpers' -import { getOnboardingBaseToken, shimmerClaimingProfileManager, updateShimmerClaimingAccount } from '../stores' +import { shimmerClaimingProfileManager, updateShimmerClaimingAccount } from '../stores' import { setTotalUnclaimedShimmerRewards } from '@contexts/onboarding' import { formatTokenAmountBestMatch } from '@core/wallet/utils' import { showAppNotification } from '@auxiliary/notification' +import { getBaseToken } from '@core/profile' export async function syncShimmerClaimingAccount(account: IAccount): Promise { const _shimmerClaimingProfileManager = get(shimmerClaimingProfileManager) @@ -28,7 +29,7 @@ export async function syncShimmerClaimingAccount(account: IAccount): Promise 0) { const foundRewardsAmount = syncedShimmerClaimingAccount?.unclaimedRewards - const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getOnboardingBaseToken()) + const foundRewardsAmountFormatted = formatTokenAmountBestMatch(foundRewardsAmount, getBaseToken()) showAppNotification({ type: 'success', diff --git a/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts b/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts index 05bb340800d..5eeca341cbb 100644 --- a/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts +++ b/packages/shared/lib/contexts/onboarding/stores/onboarding-profile.store.ts @@ -3,7 +3,6 @@ import { derived, get, Readable, writable } from 'svelte/store' import { isLedgerProfile } from '@core/profile' import { IOnboardingProfile, IShimmerClaimingAccount } from '../interfaces' -import { IBaseToken } from '@core/wallet/interfaces' import { IPersistedNetwork } from '@core/network' export const onboardingProfile = writable>(null) @@ -36,7 +35,3 @@ export function updateShimmerClaimingAccount(shimmerClaimingAccount: IShimmerCla ) updateOnboardingProfile({ shimmerClaimingAccounts }) } - -export function getOnboardingBaseToken(): IBaseToken { - return get(onboardingProfile)?.network?.baseToken -} diff --git a/packages/shared/lib/core/network/constants/default-base-token.constant.ts b/packages/shared/lib/core/network/constants/default-base-token.constant.ts deleted file mode 100644 index b5e3804a84d..00000000000 --- a/packages/shared/lib/core/network/constants/default-base-token.constant.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { NetworkId } from '@core/network/enums' -import { IBaseToken } from '@core/wallet/interfaces' -import { TokenStandard } from '@core/wallet/enums' - -const DEFAULT_IOTA_BASE_TOKEN: IBaseToken = { - standard: TokenStandard.BaseToken, - name: 'IOTA', - tickerSymbol: 'IOTA', - unit: 'IOTA', - decimals: 6, - subunit: 'micro', - useMetricPrefix: false, -} - -const DEFAULT_IOTA_ALPHANET_BASE_TOKEN: IBaseToken = { - standard: TokenStandard.BaseToken, - name: 'IOTA', - tickerSymbol: 'IOTA', - unit: 'IOTA', - decimals: 6, - subunit: 'micro', - useMetricPrefix: false, -} - -const DEFAULT_IOTA_TESTNET_BASE_TOKEN: IBaseToken = { - standard: TokenStandard.BaseToken, - name: 'TST', - tickerSymbol: 'TST', - unit: 'TST', - decimals: 6, - subunit: 'testies', - useMetricPrefix: false, -} - -const DEFAULT_SHIMMER_BASE_TOKEN: IBaseToken = { - standard: TokenStandard.BaseToken, - name: 'Shimmer', - tickerSymbol: 'SMR', - unit: 'SMR', - decimals: 6, - subunit: 'glow', - useMetricPrefix: false, -} - -const DEFAULT_SHIMMER_TESTNET_BASE_TOKEN: IBaseToken = { - standard: TokenStandard.BaseToken, - name: 'Shimmer', - tickerSymbol: 'SMR', - unit: 'SMR', - decimals: 6, - subunit: 'glow', - useMetricPrefix: false, -} - -export const DEFAULT_BASE_TOKEN: Readonly<{ [key in NetworkId]?: IBaseToken }> = { - [NetworkId.Iota]: DEFAULT_IOTA_BASE_TOKEN, - [NetworkId.IotaTestnet]: DEFAULT_IOTA_TESTNET_BASE_TOKEN, - [NetworkId.IotaAlphanet]: DEFAULT_IOTA_ALPHANET_BASE_TOKEN, - [NetworkId.Shimmer]: DEFAULT_SHIMMER_BASE_TOKEN, - [NetworkId.ShimmerTestnet]: DEFAULT_SHIMMER_TESTNET_BASE_TOKEN, -} diff --git a/packages/shared/lib/core/network/constants/default-network-metadata.constant.ts b/packages/shared/lib/core/network/constants/default-network-metadata.constant.ts index 52c9aa9101a..9d0a328888a 100644 --- a/packages/shared/lib/core/network/constants/default-network-metadata.constant.ts +++ b/packages/shared/lib/core/network/constants/default-network-metadata.constant.ts @@ -1,5 +1,5 @@ -import { COIN_TYPE, DEFAULT_BASE_TOKEN } from '../constants' -import { NetworkId, TokenSupply } from '../enums' +import { COIN_TYPE } from '../constants' +import { NetworkId } from '../enums' import { IStardustNetworkMetadata } from '../interfaces' import { NetworkMetadata } from '../types' @@ -8,95 +8,30 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in NetworkId]?: NetworkMe id: NetworkId.Shimmer, name: 'Shimmer', coinType: COIN_TYPE[NetworkId.Shimmer], - protocol: { - version: 2, - networkName: 'shimmer', - bech32Hrp: 'smr', - minPowScore: 1500, - belowMaxDepth: 15, - rentStructure: { - vByteCost: 100, - vByteFactorData: 1, - vByteFactorKey: 10, - }, - tokenSupply: TokenSupply.Shimmer, - }, - baseToken: DEFAULT_BASE_TOKEN[NetworkId.Shimmer], + bech32Hrp: 'smr', }, [NetworkId.ShimmerTestnet]: { id: NetworkId.ShimmerTestnet, name: 'Shimmer Testnet', coinType: COIN_TYPE[NetworkId.ShimmerTestnet], - protocol: { - version: 2, - networkName: 'shimmer-testnet', - bech32Hrp: 'rms', - minPowScore: 1500, - belowMaxDepth: 15, - rentStructure: { - vByteCost: 100, - vByteFactorData: 1, - vByteFactorKey: 10, - }, - tokenSupply: TokenSupply.ShimmerTestnet, - }, - baseToken: DEFAULT_BASE_TOKEN[NetworkId.ShimmerTestnet], + bech32Hrp: 'rms', }, [NetworkId.Iota]: { id: NetworkId.Iota, name: 'IOTA', coinType: COIN_TYPE[NetworkId.Iota], - protocol: { - version: 2, - networkName: 'iota', - bech32Hrp: 'iota', - minPowScore: 1500, - belowMaxDepth: 15, - rentStructure: { - vByteCost: 250, - vByteFactorData: 1, - vByteFactorKey: 10, - }, - tokenSupply: TokenSupply.Iota, - }, - baseToken: DEFAULT_BASE_TOKEN[NetworkId.Iota], + bech32Hrp: 'iota', }, [NetworkId.IotaTestnet]: { id: NetworkId.IotaTestnet, name: 'IOTA Testnet', coinType: COIN_TYPE[NetworkId.IotaTestnet], - protocol: { - version: 2, - networkName: 'iota-testnet', - bech32Hrp: 'tst', - minPowScore: 1500, - belowMaxDepth: 15, - rentStructure: { - vByteCost: 100, - vByteFactorData: 1, - vByteFactorKey: 10, - }, - tokenSupply: TokenSupply.IotaTestnet, - }, - baseToken: DEFAULT_BASE_TOKEN[NetworkId.IotaTestnet], + bech32Hrp: 'tst', }, [NetworkId.IotaAlphanet]: { id: NetworkId.IotaAlphanet, name: 'IOTA Alphanet', coinType: COIN_TYPE[NetworkId.IotaAlphanet], - protocol: { - version: 2, - networkName: 'iota-alphanet-2', - bech32Hrp: 'atoi', - minPowScore: 1500, - belowMaxDepth: 15, - rentStructure: { - vByteCost: 250, - vByteFactorData: 1, - vByteFactorKey: 10, - }, - tokenSupply: TokenSupply.Iota, - }, - baseToken: DEFAULT_BASE_TOKEN[NetworkId.IotaAlphanet], + bech32Hrp: 'atoi', }, } diff --git a/packages/shared/lib/core/network/constants/index.ts b/packages/shared/lib/core/network/constants/index.ts index b10972bc5b5..75194f80ad1 100644 --- a/packages/shared/lib/core/network/constants/index.ts +++ b/packages/shared/lib/core/network/constants/index.ts @@ -1,5 +1,4 @@ export * from './coin-type.constant' -export * from './default-base-token.constant' export * from './default-chain-configurations.constant' export * from './default-max-parallel-api-requests' export * from './default-network-metadata.constant' diff --git a/packages/shared/lib/core/network/interfaces/index.ts b/packages/shared/lib/core/network/interfaces/index.ts index 228da613644..b10517a02d1 100644 --- a/packages/shared/lib/core/network/interfaces/index.ts +++ b/packages/shared/lib/core/network/interfaces/index.ts @@ -6,6 +6,5 @@ export * from './network-status.interface' export * from './node-info-response.interface' export * from './node.interface' export * from './persisted-network.interface' -export * from './protocol.interface' export * from './rent-structure.interface' export * from './stardust-network-metadata.interface' diff --git a/packages/shared/lib/core/network/interfaces/protocol.interface.ts b/packages/shared/lib/core/network/interfaces/protocol.interface.ts deleted file mode 100644 index 1a0dfdd1dea..00000000000 --- a/packages/shared/lib/core/network/interfaces/protocol.interface.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { IRentStructure } from './rent-structure.interface' - -export interface IProtocol { - version: number - networkName: string - bech32Hrp: string - minPowScore: number - belowMaxDepth?: number - rentStructure: IRentStructure - tokenSupply: string -} diff --git a/packages/shared/lib/core/network/interfaces/stardust-network-metadata.interface.ts b/packages/shared/lib/core/network/interfaces/stardust-network-metadata.interface.ts index 1922f7daddc..3dbbcf4204c 100644 --- a/packages/shared/lib/core/network/interfaces/stardust-network-metadata.interface.ts +++ b/packages/shared/lib/core/network/interfaces/stardust-network-metadata.interface.ts @@ -1,6 +1,4 @@ -import { IBaseToken } from '@core/wallet' import { NetworkId } from '../enums' -import { IProtocol } from './protocol.interface' /** * Holds relevant data @@ -11,6 +9,5 @@ export interface IStardustNetworkMetadata { id: NetworkId name: string coinType: number - protocol: IProtocol - baseToken: IBaseToken + bech32Hrp: string } diff --git a/packages/shared/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts b/packages/shared/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts index 6c69d819296..a0e97a15214 100644 --- a/packages/shared/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts +++ b/packages/shared/lib/core/network/utils/buildPersistedNetworkFromNodeInfoResponse.ts @@ -1,6 +1,4 @@ -import { TokenStandard } from '@core/wallet/enums' import { COIN_TYPE, DEFAULT_NETWORK_METADATA } from '../constants' -import { NetworkId } from '../enums' import { INodeInfoResponse, IPersistedNetwork } from '../interfaces' import { getNetworkIdFromNetworkName } from './getNetworkIdFromNetworkName' @@ -10,14 +8,14 @@ export function buildPersistedNetworkFromNodeInfoResponse( ): IPersistedNetwork { const networkName = nodeInfoResponse?.nodeInfo?.protocol.networkName const networkId = getNetworkIdFromNetworkName(networkName) - const name = networkId === NetworkId.Custom ? networkName : DEFAULT_NETWORK_METADATA[networkId]?.name + const bech32Hrp = nodeInfoResponse?.nodeInfo?.protocol.bech32Hrp ?? DEFAULT_NETWORK_METADATA?.[networkId]?.bech32Hrp + const name = networkName ?? DEFAULT_NETWORK_METADATA?.[networkId]?.name const _coinType = coinType ?? COIN_TYPE[networkId] ?? 1 return { id: networkId, name: name ?? 'Unknown Network', coinType: _coinType, - protocol: nodeInfoResponse?.nodeInfo?.protocol, - baseToken: { standard: TokenStandard.BaseToken, ...nodeInfoResponse?.nodeInfo?.baseToken }, + bech32Hrp, chains: [], } } diff --git a/packages/shared/lib/core/profile/actions/active-profile/getBaseToken.ts b/packages/shared/lib/core/profile/actions/active-profile/getBaseToken.ts index bfb2182ddd8..4021bceff24 100644 --- a/packages/shared/lib/core/profile/actions/active-profile/getBaseToken.ts +++ b/packages/shared/lib/core/profile/actions/active-profile/getBaseToken.ts @@ -1,8 +1,12 @@ -import { activeProfile } from '@core/profile/stores' -import { IBaseToken } from '@core/wallet' +import { IBaseToken, TokenStandard } from '@core/wallet' +import { nodeInfo } from '@core/network' import { get } from 'svelte/store' export function getBaseToken(): IBaseToken { - const $activeProfile = get(activeProfile) - return $activeProfile?.network?.baseToken + const $nodeInfo = get(nodeInfo) + + return { + standard: TokenStandard.BaseToken, + ...$nodeInfo?.baseToken, + } } diff --git a/packages/shared/lib/core/profile/actions/active-profile/getNetworkHrp.ts b/packages/shared/lib/core/profile/actions/active-profile/getNetworkHrp.ts index d44190554ec..f6980a4d38c 100644 --- a/packages/shared/lib/core/profile/actions/active-profile/getNetworkHrp.ts +++ b/packages/shared/lib/core/profile/actions/active-profile/getNetworkHrp.ts @@ -3,5 +3,5 @@ import { get } from 'svelte/store' export function getNetworkHrp(): string { const $activeProfile = get(activeProfile) - return $activeProfile.network.protocol.bech32Hrp + return $activeProfile.network.bech32Hrp } diff --git a/packages/shared/lib/core/profile/actions/profiles/checkAndMigrateProfiles.ts b/packages/shared/lib/core/profile/actions/profiles/checkAndMigrateProfiles.ts index 8dcbdbae95f..da3bdd6155a 100644 --- a/packages/shared/lib/core/profile/actions/profiles/checkAndMigrateProfiles.ts +++ b/packages/shared/lib/core/profile/actions/profiles/checkAndMigrateProfiles.ts @@ -3,6 +3,7 @@ import { COIN_TYPE, DEFAULT_CHAIN_CONFIGURATIONS, DEFAULT_MAX_PARALLEL_API_REQUESTS, + DEFAULT_NETWORK_METADATA, getDefaultPersistedNetwork, IIscpChainMetadata, NetworkId, @@ -74,6 +75,7 @@ const persistedProfileMigrationsMap: Record { it('should return undefined if amount is empty', () => { expect(convertToRawAmount('', INVALID_TOKEN_METADATA)).toStrictEqual(undefined) @@ -43,40 +64,40 @@ describe('File: convertToRawAmount.ts', () => { describe('given the tokenMetadata standard is BaseToken', () => { describe("given useMetricPrefix is false (currently IOTA's case)", () => { it("should return Big(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.Iota], 'IOTA') - expect(value).toStrictEqual(Big('1').mul(Big(10).pow(DEFAULT_BASE_TOKEN[NetworkId.Iota].decimals))) + let value = convertToRawAmount('1', DEFAULT_IOTA_BASE_TOKEN, 'IOTA') + expect(value).toStrictEqual(Big('1').mul(Big(10).pow(DEFAULT_IOTA_BASE_TOKEN.decimals))) }) 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') expect(value).toStrictEqual(Big('1').mul(Big(10).pow(MAX_SUPPORTED_DECIMALS))) }) it('should return same Big(amount) if selectedUnit is subunit', () => { - expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[NetworkId.Iota], 'micro')).toStrictEqual(Big('1')) + expect(convertToRawAmount('1', DEFAULT_IOTA_BASE_TOKEN, 'micro')).toStrictEqual(Big('1')) }) it('should return undefined if a unit is not provided', () => { - expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[NetworkId.Iota])).toStrictEqual(undefined) + expect(convertToRawAmount('1', DEFAULT_IOTA_BASE_TOKEN)).toStrictEqual(undefined) }) it('should return undefined if provided unit does not match the tokenMetadata unit or subunit', () => { - expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[NetworkId.Iota], 'test')).toStrictEqual(undefined) + expect(convertToRawAmount('1', DEFAULT_IOTA_BASE_TOKEN, 'test')).toStrictEqual(undefined) }) }) describe("given useMetricPrefix is false (currently Shimmer's case)", () => { it("should return Big(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.Shimmer], 'SMR') - expect(value).toStrictEqual(Big('1').mul(Big(10).pow(DEFAULT_BASE_TOKEN[NetworkId.Shimmer].decimals))) + let value = convertToRawAmount('1', DEFAULT_SHIMMER_BASE_TOKEN, 'SMR') + expect(value).toStrictEqual(Big('1').mul(Big(10).pow(DEFAULT_SHIMMER_BASE_TOKEN.decimals))) }) 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') expect(value).toStrictEqual(Big('1').mul(Big(10).pow(MAX_SUPPORTED_DECIMALS))) }) it('should return same Big(amount) if selectedUnit is subunit', () => { - expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[NetworkId.Shimmer], 'glow')).toStrictEqual(Big('1')) + expect(convertToRawAmount('1', DEFAULT_SHIMMER_BASE_TOKEN, 'glow')).toStrictEqual(Big('1')) }) it('should return undefined if a unit is not provided', () => { - expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[NetworkId.Shimmer])).toStrictEqual(undefined) + expect(convertToRawAmount('1', DEFAULT_SHIMMER_BASE_TOKEN)).toStrictEqual(undefined) }) it('should return undefined if provided unit does not match the tokenMetadata unit or subunit', () => { - expect(convertToRawAmount('1', DEFAULT_BASE_TOKEN[NetworkId.Shimmer], 'test')).toStrictEqual(undefined) + expect(convertToRawAmount('1', DEFAULT_SHIMMER_BASE_TOKEN, 'test')).toStrictEqual(undefined) }) }) }) diff --git a/packages/shared/lib/core/wallet/utils/formatTokenAmountPrecise.ts b/packages/shared/lib/core/wallet/utils/formatTokenAmountPrecise.ts index 8829fb90845..b5a0a246a89 100644 --- a/packages/shared/lib/core/wallet/utils/formatTokenAmountPrecise.ts +++ b/packages/shared/lib/core/wallet/utils/formatTokenAmountPrecise.ts @@ -4,7 +4,7 @@ import { TokenMetadata } from '../types' export function formatTokenAmountPrecise(amount: number, tokenMetadata: TokenMetadata): string { const formattedAmount = formatNumber(amount, 0, 0, 0, true) - if (tokenMetadata.standard === TokenStandard.BaseToken) { + if (tokenMetadata?.standard === TokenStandard.BaseToken) { if (tokenMetadata?.useMetricPrefix) { return formattedAmount + ' ' + tokenMetadata?.unit } else {