From 37f6946bcb925b9430019f38add27c0fd1bf4900 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Thu, 9 May 2024 23:26:15 +0100 Subject: [PATCH 01/12] enhancement: initial iota testnet parameters --- .../components/avatars/NetworkAvatar.svelte | 2 ++ .../src/components/avatars/TokenAvatar.svelte | 6 +++++ .../organisms/NodeConfigurationForm.svelte | 2 +- .../icon/constants/default-network-icon.ts | 1 + .../icon/constants/default-token-icon.ts | 3 +++ .../enums/onboarding-network-type.enum.ts | 1 + .../constants/default-base-token.constant.ts | 16 +++++++++++++ .../constants/default-bech32-hrp.constant.ts | 1 + .../constants/default-coin-type.constant.ts | 2 ++ .../default-explorer-urls.constant.ts | 4 +++- ...ault-isc-chains-configurations.constant.ts | 23 +++++++++++++++++-- .../default-network-metadata.constant.ts | 8 +++++++ .../constants/default-node-urls.constant.ts | 1 + .../constants/default-protocol.constant.ts | 15 ++++++++++++ .../constants/explorer-endpoints.constant.ts | 12 ++++++++++ .../network/constants/faucet-urls.constant.ts | 1 + .../supported-network-id.constant.ts | 2 ++ .../lib/core/network/enums/chain-id.enum.ts | 5 ++-- .../enums/stardust-network-name.enum.ts | 1 + 19 files changed, 100 insertions(+), 6 deletions(-) diff --git a/packages/shared/src/components/avatars/NetworkAvatar.svelte b/packages/shared/src/components/avatars/NetworkAvatar.svelte index a490e99c9d..b02d203cce 100644 --- a/packages/shared/src/components/avatars/NetworkAvatar.svelte +++ b/packages/shared/src/components/avatars/NetworkAvatar.svelte @@ -13,6 +13,7 @@ [SupportedNetworkId.Iota]: '#000000', [SupportedNetworkId.Shimmer]: 'shimmer-background', [SupportedNetworkId.Testnet]: 'shimmer-background', + [SupportedNetworkId.IotaTestnet]: '#000000', [SupportedNetworkId.IotaEvm]: '#0A0FB0', [SupportedNetworkId.ShimmerEvm]: 'shimmer-background', [SupportedNetworkId.TestnetEvm]: 'text-secondary', @@ -21,6 +22,7 @@ const AVATAR_TEXT_COLOR: { [id in NetworkId]?: string } = { [SupportedNetworkId.Iota]: '#FFFFFF', [SupportedNetworkId.Shimmer]: 'shimmer', + [SupportedNetworkId.IotaTestnet]: '#FFFFFF', [SupportedNetworkId.Testnet]: 'text-secondary', [SupportedNetworkId.IotaEvm]: '#FFFFFF', [SupportedNetworkId.ShimmerEvm]: 'text-invert', diff --git a/packages/shared/src/components/avatars/TokenAvatar.svelte b/packages/shared/src/components/avatars/TokenAvatar.svelte index cc3a2f499a..eadd4b30e5 100644 --- a/packages/shared/src/components/avatars/TokenAvatar.svelte +++ b/packages/shared/src/components/avatars/TokenAvatar.svelte @@ -20,6 +20,9 @@ [SupportedNetworkId.Shimmer]: { [BASE_TOKEN_ID]: 'shimmer', }, + [SupportedNetworkId.IotaTestnet]: { + [BASE_TOKEN_ID]: '#000000', + }, [SupportedNetworkId.Testnet]: { [BASE_TOKEN_ID]: 'shimmer', }, @@ -41,6 +44,9 @@ [SupportedNetworkId.Shimmer]: { [BASE_TOKEN_ID]: 'shimmer-background', }, + [SupportedNetworkId.IotaTestnet]: { + [BASE_TOKEN_ID]: '#FFFFFF', + }, [SupportedNetworkId.Testnet]: { [BASE_TOKEN_ID]: 'shimmer-background', }, diff --git a/packages/shared/src/components/organisms/NodeConfigurationForm.svelte b/packages/shared/src/components/organisms/NodeConfigurationForm.svelte index 87de8e20f3..f64c5e05c8 100644 --- a/packages/shared/src/components/organisms/NodeConfigurationForm.svelte +++ b/packages/shared/src/components/organisms/NodeConfigurationForm.svelte @@ -72,7 +72,7 @@ const errorUrlValidity = checkNodeUrlValidity( currentClientOptions?.nodes, node.url, - $activeProfile.features.developer + $activeProfile?.features?.developer ?? false ) if (errorUrlValidity) { formError = localize(errorUrlValidity) ?? '' diff --git a/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts b/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts index f3fce1ede5..0c4d44bb5d 100644 --- a/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts +++ b/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts @@ -4,6 +4,7 @@ import { NetworkId, SupportedNetworkId } from '@core/network' export const DEFAULT_NETWORK_ICON: { [id in NetworkId]?: IconName } = { [SupportedNetworkId.Iota]: IconName.Iota, [SupportedNetworkId.Shimmer]: IconName.Shimmer, + [SupportedNetworkId.IotaTestnet]: IconName.Iota, [SupportedNetworkId.Testnet]: IconName.Shimmer, [SupportedNetworkId.IotaEvm]: IconName.Iota, [SupportedNetworkId.ShimmerEvm]: IconName.Shimmer, diff --git a/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts b/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts index 36e1b0d718..f6b30a9b96 100644 --- a/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts +++ b/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts @@ -9,6 +9,9 @@ export const DEFAULT_TOKEN_ICON: { [networkId in NetworkId]?: { [tokenId: string [SupportedNetworkId.Shimmer]: { [BASE_TOKEN_ID]: IconName.Shimmer, }, + [SupportedNetworkId.IotaTestnet]: { + [BASE_TOKEN_ID]: IconName.Iota, + }, [SupportedNetworkId.Testnet]: { [BASE_TOKEN_ID]: IconName.Shimmer, }, diff --git a/packages/shared/src/lib/contexts/onboarding/enums/onboarding-network-type.enum.ts b/packages/shared/src/lib/contexts/onboarding/enums/onboarding-network-type.enum.ts index 1707bd5626..e6ace5c5da 100644 --- a/packages/shared/src/lib/contexts/onboarding/enums/onboarding-network-type.enum.ts +++ b/packages/shared/src/lib/contexts/onboarding/enums/onboarding-network-type.enum.ts @@ -1,6 +1,7 @@ export enum OnboardingNetworkType { Iota = 'iota', Shimmer = 'shimmer', + IotaTestnet = 'iotaTestnet', Testnet = 'testnet', Custom = 'custom', } 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 bd3eba72f9..a75a41fbe1 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 @@ -31,6 +31,20 @@ export const SHIMMER_EVM_BASE_TOKEN: IBaseToken = { decimals: 18, } +const IOTA_TESTNET_BASE_TOKEN: IBaseToken = { + standard: TokenStandard.BaseToken, + name: 'Test Token', + tickerSymbol: 'TST', + unit: 'TST', + decimals: 6, + subunit: 'testies', +} + +export const IOTA_TESTNET_EVM_BASE_TOKEN: IBaseToken = { + ...IOTA_TESTNET_BASE_TOKEN, + decimals: 18, +} + export const EVM_BASE_TOKEN: IBaseToken = { standard: TokenStandard.BaseToken, name: 'Ether', @@ -42,9 +56,11 @@ export const EVM_BASE_TOKEN: IBaseToken = { export const DEFAULT_BASE_TOKEN: Readonly<{ [id in NetworkId]: IBaseToken }> = { [SupportedNetworkId.Iota]: IOTA_BASE_TOKEN, [SupportedNetworkId.Shimmer]: SHIMMER_BASE_TOKEN, + [SupportedNetworkId.IotaTestnet]: IOTA_TESTNET_BASE_TOKEN, [SupportedNetworkId.Testnet]: SHIMMER_BASE_TOKEN, [SupportedNetworkId.IotaEvm]: IOTA_EVM_BASE_TOKEN, [SupportedNetworkId.ShimmerEvm]: SHIMMER_EVM_BASE_TOKEN, + [SupportedNetworkId.IotaTestnetEvm]: IOTA_TESTNET_EVM_BASE_TOKEN, [SupportedNetworkId.TestnetEvm]: SHIMMER_EVM_BASE_TOKEN, [SupportedNetworkId.Ethereum]: EVM_BASE_TOKEN, [SupportedNetworkId.Sepolia]: EVM_BASE_TOKEN, diff --git a/packages/shared/src/lib/core/network/constants/default-bech32-hrp.constant.ts b/packages/shared/src/lib/core/network/constants/default-bech32-hrp.constant.ts index a122bf8885..2c0b5158fa 100644 --- a/packages/shared/src/lib/core/network/constants/default-bech32-hrp.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-bech32-hrp.constant.ts @@ -3,6 +3,7 @@ import { SupportedNetworkId } from './supported-network-id.constant' export const IOTA_BECH32_HRP = 'iota' export const SHIMMER_BECH32_HRP = 'smr' +export const IOTA_TESTNET_BECH32_HRP = 'tst' export const TESTNET_BECH32_HRP = 'rms' export const DEFAULT_BECH32_HRP: Readonly<{ [id in StardustNetworkId]?: string }> = { diff --git a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts index 4e99839e71..dc817746d4 100644 --- a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts @@ -9,9 +9,11 @@ export const ETHEREUM_COIN_TYPE = 60 export const DEFAULT_COIN_TYPE: Readonly<{ [key in NetworkId]: number }> = { [SupportedNetworkId.Iota]: IOTA_COIN_TYPE, [SupportedNetworkId.Shimmer]: SHIMMER_COIN_TYPE, + [SupportedNetworkId.IotaTestnet]: TEST_COIN_TYPE, [SupportedNetworkId.Testnet]: TEST_COIN_TYPE, [SupportedNetworkId.IotaEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.ShimmerEvm]: ETHEREUM_COIN_TYPE, + [SupportedNetworkId.IotaTestnetEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.TestnetEvm]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.Ethereum]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.Sepolia]: ETHEREUM_COIN_TYPE, diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts index 80089e9471..eaf50ca95e 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts @@ -4,10 +4,12 @@ import { SupportedNetworkId } from './supported-network-id.constant' export const DEFAULT_EXPLORER_URLS: Readonly<{ [key in NetworkId]?: string }> = { [SupportedNetworkId.Iota]: 'https://explorer.iota.org', [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network', + [SupportedNetworkId.IotaTestnet]: 'https://explorer.iota.org/iota-testnet', [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network', [SupportedNetworkId.IotaEvm]: 'https://explorer.evm.iota.org', - [SupportedNetworkId.Ethereum]: 'https://eth.blockscout.com', [SupportedNetworkId.ShimmerEvm]: 'https://explorer.evm.shimmer.network', + [SupportedNetworkId.IotaTestnetEvm]: 'https://explorer.evm.testnet.iota.org', [SupportedNetworkId.TestnetEvm]: 'https://explorer.evm.testnet.shimmer.network', + [SupportedNetworkId.Ethereum]: 'https://eth.blockscout.com', [SupportedNetworkId.Sepolia]: 'https://eth-sepolia.blockscout.com', } diff --git a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts index be69e5248f..9422c85be3 100644 --- a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts @@ -3,6 +3,7 @@ import { IIscChainConfiguration } from '../interfaces' import { StardustNetworkId } from '../types' import { DEFAULT_BASE_TOKEN } from './default-base-token.constant' import { DEFAULT_COIN_TYPE } from './default-coin-type.constant' +import { DEFAULT_EXPLORER_URLS } from './default-explorer-urls.constant' import { SupportedIscNetworkId, SupportedNetworkId, SupportedStardustNetworkId } from './supported-network-id.constant' import { isFeatureEnabled } from '@lib/features/utils' @@ -39,8 +40,8 @@ const SHIMMER_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { } // exported as used in tests -export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { - id: SupportedIscNetworkId.TestnetEvm, +export const IOTA_TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { + id: SupportedIscNetworkId.IotaTestnetEvm, type: NetworkType.Isc, name: 'Testnet EVM', chainId: ChainId.TestnetEvm, @@ -53,6 +54,21 @@ export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { explorerUrl: 'https://explorer.evm.testnet.shimmer.network/', } +// exported as used in tests +export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { + id: SupportedIscNetworkId.IotaTestnetEvm, + type: NetworkType.Isc, + name: 'IOTA Testnet EVM', + chainId: ChainId.IotaTestnetEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaTestnetEvm], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaTestnetEvm] ?? 0, + aliasAddress: 'tst1pzxsrr7apqkdzz633dyntmvxwtyvk029p39te5j0m33q6946h7akzv663zu', + rpcEndpoint: 'https://json-rpc.evm.testnet.iotaledger.net/', + apiEndpoint: 'https://api.evm.testnet.iotaledger.net/', + explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.IotaTestnetEvm], +} + export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetworkId]?: IIscChainConfiguration }> = { ...(isFeatureEnabled('onboarding.iota.defaultIscChains') && { [SupportedStardustNetworkId.Iota]: IOTA_EVM_CHAIN_CONFIGURATION, @@ -63,4 +79,7 @@ export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetwor ...(isFeatureEnabled('onboarding.testnet.defaultIscChains') && { [SupportedStardustNetworkId.Testnet]: TESTNET_EVM_CHAIN_CONFIGURATION, }), + ...(isFeatureEnabled('onboarding.iotaTestnet.defaultIscChains') && { + [SupportedStardustNetworkId.Testnet]: IOTA_TESTNET_EVM_CHAIN_CONFIGURATION, + }), } diff --git a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts index 568f5bad9e..4ee18a4dac 100644 --- a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts @@ -24,6 +24,14 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in StardustNetworkId]?: N protocol: DEFAULT_PROTOCOL[SupportedNetworkId.Shimmer], baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.Shimmer], }, + [SupportedNetworkId.IotaTestnet]: { + id: SupportedNetworkId.IotaTestnet, + name: 'Testnet', + namespace: NetworkNamespace.Stardust, + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaTestnet], + protocol: DEFAULT_PROTOCOL[SupportedNetworkId.IotaTestnet], + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaTestnet], + }, [SupportedNetworkId.Testnet]: { id: SupportedNetworkId.Testnet, name: 'Testnet', diff --git a/packages/shared/src/lib/core/network/constants/default-node-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-node-urls.constant.ts index 9cffeaa2ec..4ae6014944 100644 --- a/packages/shared/src/lib/core/network/constants/default-node-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-node-urls.constant.ts @@ -4,5 +4,6 @@ import { SupportedNetworkId } from './supported-network-id.constant' export const DEFAULT_NODE_URLS: Readonly<{ [id in StardustNetworkId]?: string[] }> = { [SupportedNetworkId.Iota]: ['https://api.stardust-mainnet.iotaledger.net', 'https://iota-node.tanglebay.com'], [SupportedNetworkId.Shimmer]: ['https://api.shimmer.network', 'https://shimmer-node.tanglebay.com'], + [SupportedNetworkId.IotaTestnet]: ['https://api.testnet.iotaledger.net'], [SupportedNetworkId.Testnet]: ['https://api.testnet.shimmer.network'], } diff --git a/packages/shared/src/lib/core/network/constants/default-protocol.constant.ts b/packages/shared/src/lib/core/network/constants/default-protocol.constant.ts index 3ea18c3330..e3bd50f44b 100644 --- a/packages/shared/src/lib/core/network/constants/default-protocol.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-protocol.constant.ts @@ -32,6 +32,20 @@ const DEFAULT_SHIMMER_PROTOCOL: IProtocol = { tokenSupply: TokenSupply.Shimmer, } +const DEFAULT_IOTA_TESTNET_PROTOCOL: IProtocol = { + version: 2, + networkName: StardustNetworkName.IotaTestnet, + bech32Hrp: DEFAULT_BECH32_HRP[SupportedNetworkId.IotaTestnet] ?? '', + minPowScore: 1500, + belowMaxDepth: 15, + rentStructure: { + vByteCost: 250, + vByteFactorData: 1, + vByteFactorKey: 10, + }, + tokenSupply: TokenSupply.Iota, +} + const DEFAULT_TESTNET_PROTOCOL: IProtocol = { version: 2, networkName: StardustNetworkName.Testnet, @@ -49,5 +63,6 @@ const DEFAULT_TESTNET_PROTOCOL: IProtocol = { export const DEFAULT_PROTOCOL: Readonly<{ [id in StardustNetworkId]?: IProtocol }> = { [SupportedNetworkId.Iota]: DEFAULT_IOTA_PROTOCOL, [SupportedNetworkId.Shimmer]: DEFAULT_SHIMMER_PROTOCOL, + [SupportedNetworkId.IotaTestnet]: DEFAULT_IOTA_TESTNET_PROTOCOL, [SupportedNetworkId.Testnet]: DEFAULT_TESTNET_PROTOCOL, } diff --git a/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts b/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts index 8067074838..aee1b3ab06 100644 --- a/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts +++ b/packages/shared/src/lib/core/network/constants/explorer-endpoints.constant.ts @@ -17,6 +17,13 @@ export const EXPLORER_ENDPOINTS: Readonly<{ [key in NetworkId]?: { [key in Explo [ExplorerEndpoint.Foundry]: `shimmer/${ExplorerEndpoint.Foundry}`, [ExplorerEndpoint.Address]: 'shimmer/addr', }, + [SupportedNetworkId.IotaTestnet]: { + [ExplorerEndpoint.Transaction]: `testnet/${ExplorerEndpoint.Transaction}`, + [ExplorerEndpoint.Output]: `testnet/${ExplorerEndpoint.Output}`, + [ExplorerEndpoint.Nft]: `testnet/${ExplorerEndpoint.Nft}`, + [ExplorerEndpoint.Foundry]: `testnet/${ExplorerEndpoint.Foundry}`, + [ExplorerEndpoint.Address]: 'testnet/addr', + }, [SupportedNetworkId.Testnet]: { [ExplorerEndpoint.Transaction]: `testnet/${ExplorerEndpoint.Transaction}`, [ExplorerEndpoint.Output]: `testnet/${ExplorerEndpoint.Output}`, @@ -34,6 +41,11 @@ export const EXPLORER_ENDPOINTS: Readonly<{ [key in NetworkId]?: { [key in Explo [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, [ExplorerEndpoint.Address]: ExplorerEndpoint.Address, }, + [SupportedNetworkId.IotaTestnetEvm]: { + [ExplorerEndpoint.Transaction]: 'tx', + [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, + [ExplorerEndpoint.Address]: ExplorerEndpoint.Address, + }, [SupportedNetworkId.TestnetEvm]: { [ExplorerEndpoint.Transaction]: 'tx', [ExplorerEndpoint.Token]: ExplorerEndpoint.Token, diff --git a/packages/shared/src/lib/core/network/constants/faucet-urls.constant.ts b/packages/shared/src/lib/core/network/constants/faucet-urls.constant.ts index 13c7bb4979..6607ed7059 100644 --- a/packages/shared/src/lib/core/network/constants/faucet-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/faucet-urls.constant.ts @@ -2,5 +2,6 @@ import { StardustNetworkId } from '../types' import { SupportedNetworkId } from './supported-network-id.constant' export const FAUCET_URLS: Readonly<{ [id in StardustNetworkId]?: string }> = { + [SupportedNetworkId.IotaTestnet]: 'https://faucet.testnet.iotaledger.net/api/enqueue', [SupportedNetworkId.Testnet]: 'https://faucet.testnet.shimmer.network/api/enqueue', } diff --git a/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts b/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts index 60f69f58df..c8a12949b7 100644 --- a/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts +++ b/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts @@ -7,6 +7,7 @@ export const SupportedStardustNetworkId: Record = { Iota: `${NetworkNamespace.Stardust}:${StardustNetworkName.Iota}`, Shimmer: `${NetworkNamespace.Stardust}:${StardustNetworkName.Shimmer}`, Testnet: `${NetworkNamespace.Stardust}:${StardustNetworkName.Testnet}`, + IotaTestnet: `${NetworkNamespace.Stardust}:${StardustNetworkName.IotaTestnet}`, } export const SupportedL1EvmNetworkId: Record = { @@ -18,6 +19,7 @@ export const SupportedIscNetworkId: Record = { IotaEvm: `${NetworkNamespace.Evm}:${ChainId.IotaEvm}`, ShimmerEvm: `${NetworkNamespace.Evm}:${ChainId.ShimmerEvm}`, TestnetEvm: `${NetworkNamespace.Evm}:${ChainId.TestnetEvm}`, + IotaTestnetEvm: `${NetworkNamespace.Evm}:${ChainId.IotaTestnetEvm}`, } export const SupportedNetworkId = { diff --git a/packages/shared/src/lib/core/network/enums/chain-id.enum.ts b/packages/shared/src/lib/core/network/enums/chain-id.enum.ts index 9ba80d7efa..65b05db509 100644 --- a/packages/shared/src/lib/core/network/enums/chain-id.enum.ts +++ b/packages/shared/src/lib/core/network/enums/chain-id.enum.ts @@ -1,7 +1,8 @@ export enum ChainId { IotaEvm = '8822', - Ethereum = '1', ShimmerEvm = '148', - TestnetEvm = '1073', + IotaTestnetEvm = '1073', + TestnetEvm = '1075', + Ethereum = '1', Sepolia = '11155111', } diff --git a/packages/shared/src/lib/core/network/enums/stardust-network-name.enum.ts b/packages/shared/src/lib/core/network/enums/stardust-network-name.enum.ts index 8c26268d2c..19f4b7d6ae 100644 --- a/packages/shared/src/lib/core/network/enums/stardust-network-name.enum.ts +++ b/packages/shared/src/lib/core/network/enums/stardust-network-name.enum.ts @@ -2,4 +2,5 @@ export enum StardustNetworkName { Iota = 'iota-mainnet', Shimmer = 'shimmer', Testnet = 'testnet-2', + IotaTestnet = 'testnet', } From 04ea3cdfbff4a4dd26f34258ac12e4efde926359 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 10 May 2024 10:02:36 +0100 Subject: [PATCH 02/12] feat: add testnet selection to onboarding --- .../desktop/features/onboarding.features.ts | 54 ++++++++- .../NetworkSetupRouterView.svelte | 4 +- .../network-setup/network-setup-route.enum.ts | 1 + .../network-setup/network-setup-router.ts | 14 ++- .../views/ChooseNetworkView.svelte | 36 ++++-- .../views/TestnetSelectionView.svelte | 111 ++++++++++++++++++ .../views/network-setup/views/index.js | 1 + .../lib/core/router/classes/router.class.ts | 6 +- .../src/lib/core/router/interfaces/index.ts | 1 - .../interfaces/router-event.interface.ts | 5 - .../router/interfaces/router.interface.ts | 4 +- .../src/lib/core/router/routers/app-router.ts | 13 +- .../core/router/subrouters/login-router.ts | 9 +- packages/shared/src/locales/en.json | 11 ++ 14 files changed, 226 insertions(+), 44 deletions(-) create mode 100644 packages/desktop/views/onboarding/views/network-setup/views/TestnetSelectionView.svelte delete mode 100644 packages/shared/src/lib/core/router/interfaces/router-event.interface.ts diff --git a/packages/desktop/features/onboarding.features.ts b/packages/desktop/features/onboarding.features.ts index 54ec956446..424ded72dc 100644 --- a/packages/desktop/features/onboarding.features.ts +++ b/packages/desktop/features/onboarding.features.ts @@ -96,7 +96,7 @@ const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = { }, } -const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { +const onboardingFeaturesForIotaTestnet: IOnboardingFeaturesForNetwork = { enabled: true, newProfile: { enabled: true, @@ -124,7 +124,41 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { }, claimRewards: { enabled: true, - hidden: false, + hidden: true, + recoveryPhrase: { + enabled: true, + }, + strongholdBackup: { + enabled: true, + }, + ledgerBackup: { + enabled: true, + }, + }, + defaultIscChains: { + enabled: true, + }, + defaultEvmChains: { + enabled: true, + }, +} + +const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { + enabled: true, + newProfile: { + enabled: true, + softwareProfile: { + enabled: true, + skipVerification: { + enabled: false, + }, + }, + ledgerProfile: { + enabled: true, + }, + }, + restoreProfile: { + enabled: true, recoveryPhrase: { enabled: true, }, @@ -135,6 +169,19 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { enabled: true, }, }, + claimRewards: { + enabled: false, + hidden: false, + recoveryPhrase: { + enabled: false, + }, + strongholdBackup: { + enabled: false, + }, + ledgerBackup: { + enabled: false, + }, + }, defaultIscChains: { enabled: true, }, @@ -183,7 +230,7 @@ const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = { }, }, defaultIscChains: { - enabled: false, + enabled: true, }, defaultEvmChains: { enabled: false, @@ -194,6 +241,7 @@ const onboardingFeatures: OnboardingFeatures = { enabled: true, iota: onboardingFeaturesForIota, shimmer: onboardingFeaturesForShimmer, + iotaTestnet: onboardingFeaturesForIotaTestnet, testnet: onboardingFeaturesForTestnet, custom: onboardingFeaturesForCustom, importFromThirdParty: { diff --git a/packages/desktop/views/onboarding/views/network-setup/NetworkSetupRouterView.svelte b/packages/desktop/views/onboarding/views/network-setup/NetworkSetupRouterView.svelte index a8bc4d6910..524071e423 100644 --- a/packages/desktop/views/onboarding/views/network-setup/NetworkSetupRouterView.svelte +++ b/packages/desktop/views/onboarding/views/network-setup/NetworkSetupRouterView.svelte @@ -3,7 +3,7 @@ import features from '@features/features' import { NetworkSetupRoute } from './network-setup-route.enum' import { networkSetupRoute } from './network-setup-router' - import { ChooseNetworkView, CustomNetworkView } from './views' + import { ChooseNetworkView, CustomNetworkView, TestnetSelectionView } from './views' $: if (features.analytics.onboardingRoute.enabled && $networkSetupRoute) { Platform.trackEvent('network-setup-route', { route: $networkSetupRoute }) @@ -12,6 +12,8 @@ {#if $networkSetupRoute === NetworkSetupRoute.ChooseNetwork} +{:else if $networkSetupRoute === NetworkSetupRoute.TestnetSelection} + {:else if $networkSetupRoute === NetworkSetupRoute.CustomNetwork} {/if} diff --git a/packages/desktop/views/onboarding/views/network-setup/network-setup-route.enum.ts b/packages/desktop/views/onboarding/views/network-setup/network-setup-route.enum.ts index db798051fc..fd66d1069e 100644 --- a/packages/desktop/views/onboarding/views/network-setup/network-setup-route.enum.ts +++ b/packages/desktop/views/onboarding/views/network-setup/network-setup-route.enum.ts @@ -1,4 +1,5 @@ export enum NetworkSetupRoute { ChooseNetwork = 'chooseNetwork', + TestnetSelection = 'testnetSelection', CustomNetwork = 'customNetwork', } diff --git a/packages/desktop/views/onboarding/views/network-setup/network-setup-router.ts b/packages/desktop/views/onboarding/views/network-setup/network-setup-router.ts index 1664ac4289..c9f358bf87 100644 --- a/packages/desktop/views/onboarding/views/network-setup/network-setup-router.ts +++ b/packages/desktop/views/onboarding/views/network-setup/network-setup-router.ts @@ -11,20 +11,26 @@ export class NetworkSetupRouter extends Subrouter { super(NetworkSetupRoute.ChooseNetwork, networkSetupRoute, parentRouter) } - next(): void { + next(params?: { type: 'testnet' | 'custom' }): void { const _onboardingProfile = get(onboardingProfile) const currentRoute = get(this.routeStore) switch (currentRoute) { case NetworkSetupRoute.ChooseNetwork: { const network = _onboardingProfile?.network - if (network) { + if (params?.type === 'testnet') { + networkSetupRoute.set(NetworkSetupRoute.TestnetSelection) + return + } else if (network) { this.parentRouter?.next() return } else { - this.setNext(NetworkSetupRoute.CustomNetwork) - break + networkSetupRoute.set(NetworkSetupRoute.CustomNetwork) + return } } + case NetworkSetupRoute.TestnetSelection: + this.parentRouter?.next() + return case NetworkSetupRoute.CustomNetwork: this.parentRouter?.next() return diff --git a/packages/desktop/views/onboarding/views/network-setup/views/ChooseNetworkView.svelte b/packages/desktop/views/onboarding/views/network-setup/views/ChooseNetworkView.svelte index 62cff0eb43..fd2892b9d4 100644 --- a/packages/desktop/views/onboarding/views/network-setup/views/ChooseNetworkView.svelte +++ b/packages/desktop/views/onboarding/views/network-setup/views/ChooseNetworkView.svelte @@ -37,14 +37,26 @@ } function onContinueClick(): void { - if (selectedNetworkType !== OnboardingNetworkType.Custom) { - const networkName = getNetworkNameFromOnboardingNetworkType(selectedNetworkType) - const networkId: StardustNetworkId = `${NetworkNamespace.Stardust}:${networkName}` - const network = getDefaultStardustNetwork(networkId) - const clientOptions = getDefaultClientOptions(networkId) - updateOnboardingProfile({ network, clientOptions }) + switch (selectedNetworkType) { + case OnboardingNetworkType.Iota: + case OnboardingNetworkType.Shimmer: + { + const networkName = getNetworkNameFromOnboardingNetworkType(selectedNetworkType) + const networkId: StardustNetworkId = `${NetworkNamespace.Stardust}:${networkName}` + const network = getDefaultStardustNetwork(networkId) + const clientOptions = getDefaultClientOptions(networkId) + updateOnboardingProfile({ network, clientOptions }) + $networkSetupRouter.next() + } + break + case OnboardingNetworkType.IotaTestnet: + case OnboardingNetworkType.Testnet: + $networkSetupRouter.next({ type: 'testnet' }) + break + case OnboardingNetworkType.Custom: + $networkSetupRouter.next({ type: 'custom' }) + break } - $networkSetupRouter.next() } function getNetworkNameFromOnboardingNetworkType( @@ -55,6 +67,8 @@ return StardustNetworkName.Iota case OnboardingNetworkType.Shimmer: return StardustNetworkName.Shimmer + case OnboardingNetworkType.IotaTestnet: + return StardustNetworkName.IotaTestnet case OnboardingNetworkType.Testnet: return StardustNetworkName.Testnet case OnboardingNetworkType.Custom: @@ -96,8 +110,8 @@ )} icon={IconName.Iota} iconSize="md" - iconColor="#ffffff" - backgroundColor="#000000" + iconColor="iota" + backgroundColor="iota-background" hidden={features?.onboarding?.[OnboardingNetworkType.Iota]?.hidden} disabled={!features?.onboarding?.[OnboardingNetworkType.Iota]?.enabled} onClick={() => onNetworkClick(OnboardingNetworkType.Iota)} @@ -112,8 +126,8 @@ )} icon={IconName.Shimmer} iconSize="md" - iconColor="blue-900" - backgroundColor="shimmer" + iconColor="shimmer" + backgroundColor="shimmer-background" hidden={features?.onboarding?.[OnboardingNetworkType.Shimmer]?.hidden} disabled={!features?.onboarding?.[OnboardingNetworkType.Shimmer]?.enabled} onClick={() => onNetworkClick(OnboardingNetworkType.Shimmer)} diff --git a/packages/desktop/views/onboarding/views/network-setup/views/TestnetSelectionView.svelte b/packages/desktop/views/onboarding/views/network-setup/views/TestnetSelectionView.svelte new file mode 100644 index 0000000000..df58bf029b --- /dev/null +++ b/packages/desktop/views/onboarding/views/network-setup/views/TestnetSelectionView.svelte @@ -0,0 +1,111 @@ + + + +
+
+
diff --git a/packages/desktop/views/onboarding/views/network-setup/views/index.js b/packages/desktop/views/onboarding/views/network-setup/views/index.js index 883477729b..f165066715 100644 --- a/packages/desktop/views/onboarding/views/network-setup/views/index.js +++ b/packages/desktop/views/onboarding/views/network-setup/views/index.js @@ -1,2 +1,3 @@ export { default as ChooseNetworkView } from './ChooseNetworkView.svelte' export { default as CustomNetworkView } from './CustomNetworkView.svelte' +export { default as TestnetSelectionView } from './TestnetSelectionView.svelte' diff --git a/packages/shared/src/lib/core/router/classes/router.class.ts b/packages/shared/src/lib/core/router/classes/router.class.ts index b15ec87813..c791d4c679 100644 --- a/packages/shared/src/lib/core/router/classes/router.class.ts +++ b/packages/shared/src/lib/core/router/classes/router.class.ts @@ -1,6 +1,6 @@ import { get, Writable } from 'svelte/store' -import { IRouter, IRouterEvent } from '../interfaces' +import { IRouter } from '../interfaces' export abstract class Router implements IRouter { protected history: R[] = [] @@ -35,9 +35,9 @@ export abstract class Router implements IRouter { } // This function should be implemented in the child router - next(event?: IRouterEvent): void { + next(params?: Record): void { throw Error(`Unimplemented state machine within custom router!\n - Called with event: ${JSON.stringify(event)}`) + Called with event: ${JSON.stringify(params)}`) } previous(): void { diff --git a/packages/shared/src/lib/core/router/interfaces/index.ts b/packages/shared/src/lib/core/router/interfaces/index.ts index 5d16bfea85..e9ef49e0dc 100644 --- a/packages/shared/src/lib/core/router/interfaces/index.ts +++ b/packages/shared/src/lib/core/router/interfaces/index.ts @@ -1,4 +1,3 @@ export * from './router.interface' -export * from './router-event.interface' export * from './router-manager.interface' export * from './router-manager-options.interface' diff --git a/packages/shared/src/lib/core/router/interfaces/router-event.interface.ts b/packages/shared/src/lib/core/router/interfaces/router-event.interface.ts deleted file mode 100644 index 3539c3c657..0000000000 --- a/packages/shared/src/lib/core/router/interfaces/router-event.interface.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface IRouterEvent { - reset?: boolean - shouldAddProfile?: boolean - thirdPartyProfilesImported?: boolean -} diff --git a/packages/shared/src/lib/core/router/interfaces/router.interface.ts b/packages/shared/src/lib/core/router/interfaces/router.interface.ts index 3db3b416da..2b66123787 100644 --- a/packages/shared/src/lib/core/router/interfaces/router.interface.ts +++ b/packages/shared/src/lib/core/router/interfaces/router.interface.ts @@ -1,7 +1,5 @@ -import { IRouterEvent } from './router-event.interface' - export interface IRouter { - next(event?: IRouterEvent): void + next(params?: Record): void previous(): void reset?(): void diff --git a/packages/shared/src/lib/core/router/routers/app-router.ts b/packages/shared/src/lib/core/router/routers/app-router.ts index d60db086e3..403f4c1950 100644 --- a/packages/shared/src/lib/core/router/routers/app-router.ts +++ b/packages/shared/src/lib/core/router/routers/app-router.ts @@ -4,7 +4,6 @@ import { profiles } from '@core/profile/stores' import { Router } from '../classes' import { AppRoute, LoginRoute } from '../enums' -import { IRouterEvent } from '../interfaces' import { loginRoute } from '../subrouters' export const appRoute = writable(undefined) @@ -25,13 +24,11 @@ export class AppRouter extends Router { this.init() } - public next(event?: IRouterEvent): void { - const params = event || {} - + public next(params?: { shouldAddProfile: boolean; reset: boolean; thirdPartyProfilesImported: boolean }): void { const currentRoute = get(this.routeStore) switch (currentRoute) { case AppRoute.Login: { - if (params.shouldAddProfile) { + if (params?.shouldAddProfile) { this.setNext(AppRoute.Onboarding) } else { this.setNext(AppRoute.Dashboard) @@ -39,17 +36,17 @@ export class AppRouter extends Router { break } case AppRoute.Dashboard: { - if (params.reset) { + if (params?.reset) { this.setNext(AppRoute.Login) } break } case AppRoute.Onboarding: { - if (params.shouldAddProfile) { + if (params?.shouldAddProfile) { this.setNext(AppRoute.Onboarding) } else { loginRoute.set( - params.thirdPartyProfilesImported ? LoginRoute.SelectProfile : LoginRoute.LoadProfile + params?.thirdPartyProfilesImported ? LoginRoute.SelectProfile : LoginRoute.LoadProfile ) this.setNext(AppRoute.Login) } diff --git a/packages/shared/src/lib/core/router/subrouters/login-router.ts b/packages/shared/src/lib/core/router/subrouters/login-router.ts index 17bfbe9fd2..380b93f61e 100644 --- a/packages/shared/src/lib/core/router/subrouters/login-router.ts +++ b/packages/shared/src/lib/core/router/subrouters/login-router.ts @@ -9,7 +9,6 @@ import { } from '../../../../../../desktop/views/update-stronghold/update-stronghold-router' import { Subrouter } from '../classes' import { LoginRoute } from '../enums' -import { IRouterEvent } from '../interfaces' import { appRouter } from '../routers' export const loginRoute = writable(undefined) @@ -20,7 +19,7 @@ export class LoginRouter extends Subrouter { super(LoginRoute.SelectProfile, loginRoute, get(appRouter)) } - next(event?: IRouterEvent): void { + next(params?: Record): void { const currentRoute = get(this.routeStore) const requiresUpdate = @@ -31,8 +30,8 @@ export class LoginRouter extends Subrouter { switch (currentRoute) { case LoginRoute.SelectProfile: { - if (event?.shouldAddProfile) { - this.parentRouter?.next(event) + if (params?.shouldAddProfile) { + this.parentRouter?.next(params) return } else { this.setNext(LoginRoute.EnterPin) @@ -51,7 +50,7 @@ export class LoginRouter extends Subrouter { this.setNext(LoginRoute.LoadProfile) break case LoginRoute.LoadProfile: - this.parentRouter?.next(event) + this.parentRouter?.next(params) return } } diff --git a/packages/shared/src/locales/en.json b/packages/shared/src/locales/en.json index 06f68cb2d3..e7632edff1 100644 --- a/packages/shared/src/locales/en.json +++ b/packages/shared/src/locales/en.json @@ -54,6 +54,17 @@ "secondary": "Connect to any network with custom settings" } }, + "testnetSelection": { + "title": "Select your testnet", + "iotaTestnet": { + "primary": "IOTA Testnet", + "secondary": "Test network using valueless TST tokens" + }, + "testnet": { + "primary": "Shimmer Testnet", + "secondary": "Test network using valueless RMS tokens" + } + }, "setupCustomNetwork": { "title": "Advanced configuration" } From 3236cbcce11fafe2ba69490928ab3f13f716ad0c Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 10 May 2024 12:05:44 +0100 Subject: [PATCH 03/12] various fixes to network parameters --- .../desktop/features/onboarding.features.ts | 2 +- .../src/components/avatars/TokenAvatar.svelte | 10 ++++- .../icon/constants/default-network-icon.ts | 1 + .../icon/constants/default-token-icon.ts | 3 ++ ...ault-isc-chains-configurations.constant.ts | 39 +++++++++---------- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/packages/desktop/features/onboarding.features.ts b/packages/desktop/features/onboarding.features.ts index 424ded72dc..36ef2c4878 100644 --- a/packages/desktop/features/onboarding.features.ts +++ b/packages/desktop/features/onboarding.features.ts @@ -170,7 +170,7 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { }, }, claimRewards: { - enabled: false, + enabled: true, hidden: false, recoveryPhrase: { enabled: false, diff --git a/packages/shared/src/components/avatars/TokenAvatar.svelte b/packages/shared/src/components/avatars/TokenAvatar.svelte index b1281cce6f..5637ea1193 100644 --- a/packages/shared/src/components/avatars/TokenAvatar.svelte +++ b/packages/shared/src/components/avatars/TokenAvatar.svelte @@ -21,7 +21,7 @@ [BASE_TOKEN_ID]: 'shimmer-background', }, [SupportedNetworkId.IotaTestnet]: { - [BASE_TOKEN_ID]: '#000000', + [BASE_TOKEN_ID]: 'iota-background', }, [SupportedNetworkId.Testnet]: { [BASE_TOKEN_ID]: 'shimmer-background', @@ -32,6 +32,9 @@ [SupportedNetworkId.ShimmerEvm]: { [BASE_TOKEN_ID]: 'shimmer-background', }, + [SupportedNetworkId.IotaTestnetEvm]: { + [BASE_TOKEN_ID]: 'iota-background', + }, [SupportedNetworkId.TestnetEvm]: { [BASE_TOKEN_ID]: 'shimmer-background', }, @@ -45,7 +48,7 @@ [BASE_TOKEN_ID]: 'shimmer', }, [SupportedNetworkId.IotaTestnet]: { - [BASE_TOKEN_ID]: '#FFFFFF', + [BASE_TOKEN_ID]: 'iota', }, [SupportedNetworkId.Testnet]: { [BASE_TOKEN_ID]: 'shimmer', @@ -56,6 +59,9 @@ [SupportedNetworkId.ShimmerEvm]: { [BASE_TOKEN_ID]: 'shimmer', }, + [SupportedNetworkId.IotaTestnetEvm]: { + [BASE_TOKEN_ID]: 'iota', + }, [SupportedNetworkId.TestnetEvm]: { [BASE_TOKEN_ID]: 'shimmer', }, diff --git a/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts b/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts index 0c4d44bb5d..6faca58ddb 100644 --- a/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts +++ b/packages/shared/src/lib/auxiliary/icon/constants/default-network-icon.ts @@ -8,5 +8,6 @@ export const DEFAULT_NETWORK_ICON: { [id in NetworkId]?: IconName } = { [SupportedNetworkId.Testnet]: IconName.Shimmer, [SupportedNetworkId.IotaEvm]: IconName.Iota, [SupportedNetworkId.ShimmerEvm]: IconName.Shimmer, + [SupportedNetworkId.IotaTestnetEvm]: IconName.Iota, [SupportedNetworkId.TestnetEvm]: IconName.Shimmer, } diff --git a/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts b/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts index f6b30a9b96..8021d9eb27 100644 --- a/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts +++ b/packages/shared/src/lib/auxiliary/icon/constants/default-token-icon.ts @@ -21,6 +21,9 @@ export const DEFAULT_TOKEN_ICON: { [networkId in NetworkId]?: { [tokenId: string [SupportedNetworkId.ShimmerEvm]: { [BASE_TOKEN_ID]: IconName.Shimmer, }, + [SupportedNetworkId.IotaTestnetEvm]: { + [BASE_TOKEN_ID]: IconName.Iota, + }, [SupportedNetworkId.TestnetEvm]: { [BASE_TOKEN_ID]: IconName.Shimmer, }, diff --git a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts index 9422c85be3..126dd22e31 100644 --- a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts @@ -39,23 +39,7 @@ const SHIMMER_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { explorerUrl: 'https://explorer.evm.shimmer.network/', } -// exported as used in tests -export const IOTA_TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { - id: SupportedIscNetworkId.IotaTestnetEvm, - type: NetworkType.Isc, - name: 'Testnet EVM', - chainId: ChainId.TestnetEvm, - namespace: NetworkNamespace.Evm, - baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.TestnetEvm], - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.TestnetEvm] ?? 0, - aliasAddress: 'rms1ppp00k5mmd2m8my8ukkp58nd3rskw6rx8l09aj35984k74uuc5u2cywn3ex', - rpcEndpoint: 'https://json-rpc.evm.testnet.shimmer.network/', - apiEndpoint: 'https://api.evm.testnet.shimmer.network/', - explorerUrl: 'https://explorer.evm.testnet.shimmer.network/', -} - -// exported as used in tests -export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { +const IOTA_TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { id: SupportedIscNetworkId.IotaTestnetEvm, type: NetworkType.Isc, name: 'IOTA Testnet EVM', @@ -69,6 +53,21 @@ export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.IotaTestnetEvm], } +// exported as used in tests +export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { + id: SupportedIscNetworkId.IotaTestnetEvm, + type: NetworkType.Isc, + name: 'Shimmer Testnet EVM', + chainId: ChainId.TestnetEvm, + namespace: NetworkNamespace.Evm, + baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.TestnetEvm], + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.TestnetEvm] ?? 0, + aliasAddress: 'rms1ppp00k5mmd2m8my8ukkp58nd3rskw6rx8l09aj35984k74uuc5u2cywn3ex', + rpcEndpoint: 'https://json-rpc.evm.testnet.shimmer.network/', + apiEndpoint: 'https://api.evm.testnet.shimmer.network/', + explorerUrl: 'https://explorer.evm.testnet.shimmer.network/', +} + export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetworkId]?: IIscChainConfiguration }> = { ...(isFeatureEnabled('onboarding.iota.defaultIscChains') && { [SupportedStardustNetworkId.Iota]: IOTA_EVM_CHAIN_CONFIGURATION, @@ -76,10 +75,10 @@ export const DEFAULT_ISC_CHAINS_CONFIGURATIONS: Readonly<{ [id in StardustNetwor ...(isFeatureEnabled('onboarding.shimmer.defaultIscChains') && { [SupportedStardustNetworkId.Shimmer]: SHIMMER_EVM_CHAIN_CONFIGURATION, }), + ...(isFeatureEnabled('onboarding.iotaTestnet.defaultIscChains') && { + [SupportedStardustNetworkId.IotaTestnet]: IOTA_TESTNET_EVM_CHAIN_CONFIGURATION, + }), ...(isFeatureEnabled('onboarding.testnet.defaultIscChains') && { [SupportedStardustNetworkId.Testnet]: TESTNET_EVM_CHAIN_CONFIGURATION, }), - ...(isFeatureEnabled('onboarding.iotaTestnet.defaultIscChains') && { - [SupportedStardustNetworkId.Testnet]: IOTA_TESTNET_EVM_CHAIN_CONFIGURATION, - }), } From 6f03a600ec5ce7dcb2e4548dd4a7dfdd905a44ef Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 10 May 2024 12:52:02 +0100 Subject: [PATCH 04/12] fix: network config id --- .../constants/default-isc-chains-configurations.constant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts index 126dd22e31..206f3dd5fc 100644 --- a/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-isc-chains-configurations.constant.ts @@ -55,7 +55,7 @@ const IOTA_TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { // exported as used in tests export const TESTNET_EVM_CHAIN_CONFIGURATION: IIscChainConfiguration = { - id: SupportedIscNetworkId.IotaTestnetEvm, + id: SupportedIscNetworkId.TestnetEvm, type: NetworkType.Isc, name: 'Shimmer Testnet EVM', chainId: ChainId.TestnetEvm, From 99c2d87c4fe21e40975d5c5c088b86c5c747c4c2 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 10 May 2024 12:53:26 +0100 Subject: [PATCH 05/12] ui: update network and base token colours --- .../src/components/avatars/NetworkAvatar.svelte | 16 ++++++++-------- .../src/components/avatars/TokenAvatar.svelte | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/shared/src/components/avatars/NetworkAvatar.svelte b/packages/shared/src/components/avatars/NetworkAvatar.svelte index f113cdb10b..35230168a1 100644 --- a/packages/shared/src/components/avatars/NetworkAvatar.svelte +++ b/packages/shared/src/components/avatars/NetworkAvatar.svelte @@ -12,23 +12,23 @@ const AVATAR_BACKGROUND_COLOR: { [id in NetworkId]?: string } = { [SupportedNetworkId.Iota]: 'iota-background', [SupportedNetworkId.Shimmer]: 'shimmer-background', - [SupportedNetworkId.Testnet]: 'shimmer-background', - [SupportedNetworkId.IotaTestnet]: 'iota-background', + [SupportedNetworkId.Testnet]: 'text-secondary', + [SupportedNetworkId.IotaTestnet]: 'text-secondary', [SupportedNetworkId.IotaEvm]: 'iota-evm-background', [SupportedNetworkId.ShimmerEvm]: 'shimmer-evm-background', - [SupportedNetworkId.IotaTestnetEvm]: 'iota-evm-background', - [SupportedNetworkId.TestnetEvm]: 'shimmer-evm-background', + [SupportedNetworkId.IotaTestnetEvm]: 'iota-evm-background/90', + [SupportedNetworkId.TestnetEvm]: 'shimmer-evm-background/90', } const AVATAR_TEXT_COLOR: { [id in NetworkId]?: string } = { [SupportedNetworkId.Iota]: 'iota', [SupportedNetworkId.Shimmer]: 'shimmer', - [SupportedNetworkId.IotaTestnet]: 'text-secondary', - [SupportedNetworkId.Testnet]: 'text-secondary', + [SupportedNetworkId.IotaTestnet]: '#FFFFFF', + [SupportedNetworkId.Testnet]: '#FFFFFF', [SupportedNetworkId.IotaEvm]: 'iota-evm', [SupportedNetworkId.ShimmerEvm]: 'shimmer-evm', - [SupportedNetworkId.IotaTestnetEvm]: 'iota-evm', - [SupportedNetworkId.TestnetEvm]: 'shimmer-evm', + [SupportedNetworkId.IotaTestnetEvm]: '#FFFFFF', + [SupportedNetworkId.TestnetEvm]: '#FFFFFF', } let anchor: HTMLElement diff --git a/packages/shared/src/components/avatars/TokenAvatar.svelte b/packages/shared/src/components/avatars/TokenAvatar.svelte index 5637ea1193..e0b5f09d6c 100644 --- a/packages/shared/src/components/avatars/TokenAvatar.svelte +++ b/packages/shared/src/components/avatars/TokenAvatar.svelte @@ -21,10 +21,10 @@ [BASE_TOKEN_ID]: 'shimmer-background', }, [SupportedNetworkId.IotaTestnet]: { - [BASE_TOKEN_ID]: 'iota-background', + [BASE_TOKEN_ID]: 'text-secondary', }, [SupportedNetworkId.Testnet]: { - [BASE_TOKEN_ID]: 'shimmer-background', + [BASE_TOKEN_ID]: 'text-secondary', }, [SupportedNetworkId.IotaEvm]: { [BASE_TOKEN_ID]: 'iota-background', @@ -33,10 +33,10 @@ [BASE_TOKEN_ID]: 'shimmer-background', }, [SupportedNetworkId.IotaTestnetEvm]: { - [BASE_TOKEN_ID]: 'iota-background', + [BASE_TOKEN_ID]: 'text-secondary', }, [SupportedNetworkId.TestnetEvm]: { - [BASE_TOKEN_ID]: 'shimmer-background', + [BASE_TOKEN_ID]: 'text-secondary', }, } @@ -48,10 +48,10 @@ [BASE_TOKEN_ID]: 'shimmer', }, [SupportedNetworkId.IotaTestnet]: { - [BASE_TOKEN_ID]: 'iota', + [BASE_TOKEN_ID]: '#FFFFFF', }, [SupportedNetworkId.Testnet]: { - [BASE_TOKEN_ID]: 'shimmer', + [BASE_TOKEN_ID]: '#FFFFFF', }, [SupportedNetworkId.IotaEvm]: { [BASE_TOKEN_ID]: 'iota', @@ -60,10 +60,10 @@ [BASE_TOKEN_ID]: 'shimmer', }, [SupportedNetworkId.IotaTestnetEvm]: { - [BASE_TOKEN_ID]: 'iota', + [BASE_TOKEN_ID]: '#FFFFFF', }, [SupportedNetworkId.TestnetEvm]: { - [BASE_TOKEN_ID]: 'shimmer', + [BASE_TOKEN_ID]: '#FFFFFF', }, } From f18b0a1edfcdf3f202e80318093e745956abb2fa Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Fri, 10 May 2024 13:35:58 +0100 Subject: [PATCH 06/12] update testnet names --- .../network/constants/default-network-metadata.constant.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts index 4ee18a4dac..1311c184d9 100644 --- a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts @@ -26,7 +26,7 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in StardustNetworkId]?: N }, [SupportedNetworkId.IotaTestnet]: { id: SupportedNetworkId.IotaTestnet, - name: 'Testnet', + name: 'IOTA Testnet', namespace: NetworkNamespace.Stardust, coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaTestnet], protocol: DEFAULT_PROTOCOL[SupportedNetworkId.IotaTestnet], @@ -34,7 +34,7 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in StardustNetworkId]?: N }, [SupportedNetworkId.Testnet]: { id: SupportedNetworkId.Testnet, - name: 'Testnet', + name: 'Shimmer Testnet', namespace: NetworkNamespace.Stardust, coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Testnet], protocol: DEFAULT_PROTOCOL[SupportedNetworkId.Testnet], From 438f6be4f77deb710cc0fab133f30a09726e9c30 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Tue, 14 May 2024 20:32:01 +0100 Subject: [PATCH 07/12] fix: testnet explorer --- .../core/network/constants/default-explorer-urls.constant.ts | 2 +- .../network/constants/default-network-metadata.constant.ts | 1 + .../src/lib/core/network/utils/getExplorerApiNetworkName.ts | 2 +- packages/shared/src/lib/core/network/utils/getExplorerUrl.ts | 2 +- packages/shared/src/lib/core/utils/url.ts | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts index eaf50ca95e..9e10af6968 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts @@ -4,7 +4,7 @@ import { SupportedNetworkId } from './supported-network-id.constant' export const DEFAULT_EXPLORER_URLS: Readonly<{ [key in NetworkId]?: string }> = { [SupportedNetworkId.Iota]: 'https://explorer.iota.org', [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network', - [SupportedNetworkId.IotaTestnet]: 'https://explorer.iota.org/iota-testnet', + [SupportedNetworkId.IotaTestnet]: 'https://explorer.iota.org', [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network', [SupportedNetworkId.IotaEvm]: 'https://explorer.evm.iota.org', [SupportedNetworkId.ShimmerEvm]: 'https://explorer.evm.shimmer.network', diff --git a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts index f525a916a1..61f1927e2f 100644 --- a/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-network-metadata.constant.ts @@ -34,6 +34,7 @@ export const DEFAULT_NETWORK_METADATA: Readonly<{ [key in StardustNetworkId]?: N coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.IotaTestnet], protocol: DEFAULT_PROTOCOL[SupportedNetworkId.IotaTestnet], baseToken: DEFAULT_BASE_TOKEN[SupportedNetworkId.IotaTestnet], + explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.IotaTestnet], }, [SupportedNetworkId.Testnet]: { id: SupportedNetworkId.Testnet, diff --git a/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts b/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts index 0e56fa9cb1..ccf841ff48 100644 --- a/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts +++ b/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts @@ -10,6 +10,6 @@ export function getExplorerApiNetworkName(networkId: NetworkId): string { case SupportedStardustNetworkId.Testnet: return 'testnet' default: - return '' + return 'iota-testnet' } } diff --git a/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts index a8dba19500..d866c1cbb2 100644 --- a/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts +++ b/packages/shared/src/lib/core/network/utils/getExplorerUrl.ts @@ -12,6 +12,6 @@ export function getExplorerUrl( const baseUrl = getNetwork(networkId)?.explorerUrl ?? '' const endpoint = getExplorerEndpoint(networkId, requestedEndpoint) ?? '' - const url = buildUrl({ origin: baseUrl, pathname: `${endpoint}${pathParameter ? '/' + pathParameter : ''}` }) + const url = buildUrl({ base: baseUrl, pathname: `${endpoint}${pathParameter ? '/' + pathParameter : ''}` }) return url?.href } diff --git a/packages/shared/src/lib/core/utils/url.ts b/packages/shared/src/lib/core/utils/url.ts index db670eac24..d6747130d4 100644 --- a/packages/shared/src/lib/core/utils/url.ts +++ b/packages/shared/src/lib/core/utils/url.ts @@ -25,14 +25,14 @@ export function cleanUrl( } type UrlParams = { - origin: string + base: string pathname?: string query?: QueryParameters } export function buildUrl(urlParams: UrlParams): URL | undefined { try { - const url = new URL(urlParams.pathname ?? '', urlParams.origin) + const url = new URL(urlParams.pathname ?? '', urlParams.base) for (const key of Object.keys(urlParams.query ?? {})) { const value = urlParams.query?.[key] if (!value) continue From ff00447fe037ab4c74a6362e55cf36c65826f78d Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Wed, 15 May 2024 09:05:25 +0100 Subject: [PATCH 08/12] fix: pr comments --- .../src/lib/core/network/utils/getExplorerApiNetworkName.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts b/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts index ccf841ff48..ce804aad49 100644 --- a/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts +++ b/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts @@ -7,9 +7,11 @@ export function getExplorerApiNetworkName(networkId: NetworkId): string { return 'mainnet' case SupportedStardustNetworkId.Shimmer: return 'shimmer' + case SupportedStardustNetworkId.IotaTestnet: + return 'iota-testnet' case SupportedStardustNetworkId.Testnet: return 'testnet' default: - return 'iota-testnet' + return '' } } From c22c3ececf1afe201e6ba4f70026e9a954def18c Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Wed, 15 May 2024 09:23:17 +0100 Subject: [PATCH 09/12] fix: tests --- packages/shared/src/lib/core/network/tests/network.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/shared/src/lib/core/network/tests/network.test.ts b/packages/shared/src/lib/core/network/tests/network.test.ts index 900d64b992..fe673e03e8 100644 --- a/packages/shared/src/lib/core/network/tests/network.test.ts +++ b/packages/shared/src/lib/core/network/tests/network.test.ts @@ -23,6 +23,7 @@ describe('File: network.ts', () => { const EXPECTED_NODE_URLS: Readonly<{ [key in StardustNetworkId]?: string[] }> = { [SupportedNetworkId.Iota]: ['https://api.stardust-mainnet.iotaledger.net', 'https://iota-node.tanglebay.com'], [SupportedNetworkId.Shimmer]: ['https://api.shimmer.network', 'https://shimmer-node.tanglebay.com'], + [SupportedNetworkId.IotaTestnet]: ['https://api.testnet.iotaledger.net'], [SupportedNetworkId.Testnet]: ['https://api.testnet.shimmer.network'], } From d93f8d8f9e4f807684a3695b502df59ce4fdf639 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Wed, 15 May 2024 09:58:08 +0100 Subject: [PATCH 10/12] feat: clean up explorer url building Co-authored-by: Mark Nardi --- .../src/lib/core/network/apis/explorer.api.ts | 40 +++++++++++++------ .../default-explorer-urls.constant.ts | 8 ++-- .../utils/getExplorerApiNetworkName.ts | 17 -------- .../core/network/utils/getExplorerEndpoint.ts | 3 +- .../src/lib/core/network/utils/index.ts | 1 - packages/shared/src/lib/core/utils/string.ts | 4 ++ packages/shared/src/lib/core/utils/url.ts | 5 ++- 7 files changed, 40 insertions(+), 38 deletions(-) delete mode 100644 packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts diff --git a/packages/shared/src/lib/core/network/apis/explorer.api.ts b/packages/shared/src/lib/core/network/apis/explorer.api.ts index d1ac5378f2..d64251786a 100644 --- a/packages/shared/src/lib/core/network/apis/explorer.api.ts +++ b/packages/shared/src/lib/core/network/apis/explorer.api.ts @@ -1,18 +1,31 @@ -import { DEFAULT_APPLICATION_JSON_REQUEST_OPTIONS } from '@core/utils' +import { DEFAULT_APPLICATION_JSON_REQUEST_OPTIONS, buildUrl } from '@core/utils' import {} from '../enums' import { DEFAULT_EXPLORER_API_BASE_URL } from '../constants/default-explorer-api-base-url.constant' import { ExplorerApiEndpoint } from '../enums' -import { IExplorerApiNetworks } from '../interfaces' -import { getExplorerApiNetworkName } from '../utils' +import { IExplorerApiNetwork, IExplorerApiNetworks } from '../interfaces' import { NetworkId } from '../types' +import { SupportedStardustNetworkId } from '../constants' + +const ExplorerNetworkId = { + [SupportedStardustNetworkId.Iota]: 'mainnet', + [SupportedStardustNetworkId.Shimmer]: 'shimmer', + [SupportedStardustNetworkId.IotaTestnet]: 'iota-testnet', + [SupportedStardustNetworkId.Testnet]: 'shimmer-testnet', +} export class ExplorerApi { - static async makeRequest(endpoint: ExplorerApiEndpoint, queryParams?: string): Promise { + static async makeRequest(endpoint: ExplorerApiEndpoint): Promise { try { - const response = await fetch( - `${DEFAULT_EXPLORER_API_BASE_URL}${endpoint}?${queryParams ?? ''}`, - DEFAULT_APPLICATION_JSON_REQUEST_OPTIONS - ) + const requestUrl = buildUrl({ + base: DEFAULT_EXPLORER_API_BASE_URL, + pathname: endpoint, + }) + + if (!requestUrl) { + throw new Error('Invalid request URL') + } + + const response = await fetch(requestUrl.href, DEFAULT_APPLICATION_JSON_REQUEST_OPTIONS) const data = await response.json() return data } catch (err) { @@ -21,10 +34,13 @@ export class ExplorerApi { } } + static async getNetworkInfo(networkId: NetworkId): Promise { + const networksInfo = await ExplorerApi.makeRequest(ExplorerApiEndpoint.Networks) + const networkInfo = networksInfo?.networks.find((network) => network.network === ExplorerNetworkId[networkId]) + return networkInfo + } + static async getCirculatingSupply(networkId: NetworkId): Promise { - const networkName = getExplorerApiNetworkName(networkId) - const networksInfo = await this.makeRequest(ExplorerApiEndpoint.Networks, networkId) - const networkInfo = networksInfo?.networks.find((network) => network.network === networkName) - return networkInfo?.circulatingSupply ?? 0 + return (await ExplorerApi.getNetworkInfo(networkId))?.circulatingSupply ?? 0 } } diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts index 9e10af6968..2e0bb24349 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-urls.constant.ts @@ -2,10 +2,10 @@ import { NetworkId } from '../types' import { SupportedNetworkId } from './supported-network-id.constant' export const DEFAULT_EXPLORER_URLS: Readonly<{ [key in NetworkId]?: string }> = { - [SupportedNetworkId.Iota]: 'https://explorer.iota.org', - [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network', - [SupportedNetworkId.IotaTestnet]: 'https://explorer.iota.org', - [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network', + [SupportedNetworkId.Iota]: 'https://explorer.iota.org/mainnet/', + [SupportedNetworkId.Shimmer]: 'https://explorer.shimmer.network/shimmer/', + [SupportedNetworkId.IotaTestnet]: 'https://explorer.iota.org/iota-testnet/', + [SupportedNetworkId.Testnet]: 'https://explorer.shimmer.network/testnet/', [SupportedNetworkId.IotaEvm]: 'https://explorer.evm.iota.org', [SupportedNetworkId.ShimmerEvm]: 'https://explorer.evm.shimmer.network', [SupportedNetworkId.IotaTestnetEvm]: 'https://explorer.evm.testnet.iota.org', diff --git a/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts b/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts deleted file mode 100644 index ce804aad49..0000000000 --- a/packages/shared/src/lib/core/network/utils/getExplorerApiNetworkName.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { SupportedStardustNetworkId } from '../constants' -import { NetworkId } from '../types' - -export function getExplorerApiNetworkName(networkId: NetworkId): string { - switch (networkId) { - case SupportedStardustNetworkId.Iota: - return 'mainnet' - case SupportedStardustNetworkId.Shimmer: - return 'shimmer' - case SupportedStardustNetworkId.IotaTestnet: - return 'iota-testnet' - case SupportedStardustNetworkId.Testnet: - return 'testnet' - default: - return '' - } -} diff --git a/packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts b/packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts index 6d538993a2..e6ddaf8251 100644 --- a/packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts +++ b/packages/shared/src/lib/core/network/utils/getExplorerEndpoint.ts @@ -1,6 +1,5 @@ import { ExplorerEndpoint } from '../enums' import { NetworkId } from '../types' -import { getExplorerApiNetworkName } from './getExplorerApiNetworkName' import { isStardustNetwork } from './isStardustNetwork' import { isEvmNetwork } from './isEvmNetwork' @@ -20,7 +19,7 @@ const EVM_EXPLORER_ENDPOINTS: Readonly<{ [key in ExplorerEndpoint]?: string }> = export function getExplorerEndpoint(networkId: NetworkId, explorerEndpoint: ExplorerEndpoint): string | undefined { if (isStardustNetwork(networkId)) { - return `${getExplorerApiNetworkName(networkId)}/${STARDUST_EXPLORER_ENDPOINTS[explorerEndpoint]}` + return STARDUST_EXPLORER_ENDPOINTS[explorerEndpoint] } else if (isEvmNetwork(networkId)) { return EVM_EXPLORER_ENDPOINTS[explorerEndpoint] } diff --git a/packages/shared/src/lib/core/network/utils/index.ts b/packages/shared/src/lib/core/network/utils/index.ts index 20ebbb806e..215202d625 100644 --- a/packages/shared/src/lib/core/network/utils/index.ts +++ b/packages/shared/src/lib/core/network/utils/index.ts @@ -10,7 +10,6 @@ export * from './getDefaultStardustNetwork' export * from './getEvmTransactionOptions' export * from './getExplorerEndpoint' export * from './getExplorerUrl' -export * from './getExplorerApiNetworkName' export * from './getNetworkIdFromOnboardingNetworkType' export * from './getOnboardingNetworkTypeFromNetworkId' export * from './getSplitNetworkId' diff --git a/packages/shared/src/lib/core/utils/string.ts b/packages/shared/src/lib/core/utils/string.ts index 4a1bbbd34a..5f046583a2 100644 --- a/packages/shared/src/lib/core/utils/string.ts +++ b/packages/shared/src/lib/core/utils/string.ts @@ -15,6 +15,10 @@ export function stripTrailingSlash(str: string): string { return str ? str.replace(/\/+$/, '') : '' } +export function addTrailingSlash(str: string): string { + return stripTrailingSlash(str) + '/' +} + /** * Strip spaces from the text * @param str The text to strip the values from diff --git a/packages/shared/src/lib/core/utils/url.ts b/packages/shared/src/lib/core/utils/url.ts index d6747130d4..05c1961bfd 100644 --- a/packages/shared/src/lib/core/utils/url.ts +++ b/packages/shared/src/lib/core/utils/url.ts @@ -1,4 +1,4 @@ -import { stripSpaces, stripTrailingSlash } from './string' +import { addTrailingSlash, stripSpaces, stripTrailingSlash } from './string' import { QueryParameters } from './types' export function cleanUrl( @@ -32,7 +32,8 @@ type UrlParams = { export function buildUrl(urlParams: UrlParams): URL | undefined { try { - const url = new URL(urlParams.pathname ?? '', urlParams.base) + // URL parser requires a slash at the end of the base URL to parse the URL correctly + const url = new URL(urlParams.pathname ?? '', addTrailingSlash(urlParams.base)) for (const key of Object.keys(urlParams.query ?? {})) { const value = urlParams.query?.[key] if (!value) continue From 8ba4c3c4ae0c64f4fae9685821eec120521cfff1 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Wed, 15 May 2024 10:13:58 +0100 Subject: [PATCH 11/12] fix: tests --- .../src/lib/core/network/apis/explorer.api.ts | 21 +++++++++---------- .../supported-network-id.constant.ts | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/shared/src/lib/core/network/apis/explorer.api.ts b/packages/shared/src/lib/core/network/apis/explorer.api.ts index d64251786a..1abe0060a0 100644 --- a/packages/shared/src/lib/core/network/apis/explorer.api.ts +++ b/packages/shared/src/lib/core/network/apis/explorer.api.ts @@ -1,17 +1,10 @@ -import { DEFAULT_APPLICATION_JSON_REQUEST_OPTIONS, buildUrl } from '@core/utils' -import {} from '../enums' +import { DEFAULT_APPLICATION_JSON_REQUEST_OPTIONS } from '@core/utils/constants' +import { buildUrl } from '@core/utils/url' +import { SupportedNetworkId } from '../constants' import { DEFAULT_EXPLORER_API_BASE_URL } from '../constants/default-explorer-api-base-url.constant' import { ExplorerApiEndpoint } from '../enums' import { IExplorerApiNetwork, IExplorerApiNetworks } from '../interfaces' -import { NetworkId } from '../types' -import { SupportedStardustNetworkId } from '../constants' - -const ExplorerNetworkId = { - [SupportedStardustNetworkId.Iota]: 'mainnet', - [SupportedStardustNetworkId.Shimmer]: 'shimmer', - [SupportedStardustNetworkId.IotaTestnet]: 'iota-testnet', - [SupportedStardustNetworkId.Testnet]: 'shimmer-testnet', -} +import type { NetworkId } from '../types' export class ExplorerApi { static async makeRequest(endpoint: ExplorerApiEndpoint): Promise { @@ -35,6 +28,12 @@ export class ExplorerApi { } static async getNetworkInfo(networkId: NetworkId): Promise { + const ExplorerNetworkId = { + [SupportedNetworkId.Iota]: 'mainnet', + [SupportedNetworkId.Shimmer]: 'shimmer', + [SupportedNetworkId.IotaTestnet]: 'iota-testnet', + [SupportedNetworkId.Testnet]: 'shimmer-testnet', + } const networksInfo = await ExplorerApi.makeRequest(ExplorerApiEndpoint.Networks) const networkInfo = networksInfo?.networks.find((network) => network.network === ExplorerNetworkId[networkId]) return networkInfo diff --git a/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts b/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts index c8a12949b7..5503ead686 100644 --- a/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts +++ b/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts @@ -1,4 +1,4 @@ -import { EvmNetworkId, StardustNetworkId } from '../types' +import type { EvmNetworkId, StardustNetworkId } from '../types/network-id.type' import { ChainId } from '../enums/chain-id.enum' import { NetworkNamespace } from '../enums/network-namespace.enum' import { StardustNetworkName } from '../enums/stardust-network-name.enum' From 811b697857b36d411e50f15ed558816b52266cef Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Wed, 15 May 2024 10:18:50 +0100 Subject: [PATCH 12/12] fix: check-types --- packages/desktop/lib/electron/managers/transak.manager.ts | 2 +- .../dashboard/campaigns/components/CampaignHeader.svelte | 4 ++-- packages/shared/src/lib/core/market/apis/coingecko.api.ts | 2 +- packages/shared/src/lib/core/router/routers/app-router.ts | 2 +- packages/shared/src/lib/core/utils/api.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/desktop/lib/electron/managers/transak.manager.ts b/packages/desktop/lib/electron/managers/transak.manager.ts index 67344cacd7..442bee3740 100644 --- a/packages/desktop/lib/electron/managers/transak.manager.ts +++ b/packages/desktop/lib/electron/managers/transak.manager.ts @@ -258,7 +258,7 @@ export default class TransakManager implements ITransakManager { colorMode, } - const urlObject = buildUrl({ origin: TRANSAK_WIDGET_URL, query: queryParams }) + const urlObject = buildUrl({ base: TRANSAK_WIDGET_URL, query: queryParams }) return urlObject?.href ?? '' } diff --git a/packages/desktop/views/dashboard/campaigns/components/CampaignHeader.svelte b/packages/desktop/views/dashboard/campaigns/components/CampaignHeader.svelte index 1f89a57bbb..805382afd8 100644 --- a/packages/desktop/views/dashboard/campaigns/components/CampaignHeader.svelte +++ b/packages/desktop/views/dashboard/campaigns/components/CampaignHeader.svelte @@ -46,14 +46,14 @@ function onProjectClick(): void { const url = buildUrl({ - origin: TIDE_BASE_URL, + base: TIDE_BASE_URL, pathname: `${TideWebsiteEndpoint.Project}/${campaign.projectId}`, }) openUrlInBrowser(url?.href) } function onCampaignClick(): void { - const url = buildUrl({ origin: TIDE_BASE_URL, pathname: `${TideWebsiteEndpoint.Campaign}/${campaign.id}` }) + const url = buildUrl({ base: TIDE_BASE_URL, pathname: `${TideWebsiteEndpoint.Campaign}/${campaign.id}` }) openUrlInBrowser(url?.href) } diff --git a/packages/shared/src/lib/core/market/apis/coingecko.api.ts b/packages/shared/src/lib/core/market/apis/coingecko.api.ts index c85a54b03b..172deb11a8 100644 --- a/packages/shared/src/lib/core/market/apis/coingecko.api.ts +++ b/packages/shared/src/lib/core/market/apis/coingecko.api.ts @@ -9,7 +9,7 @@ export class CoinGeckoApi { static async makeRequest(endpoint: string, query?: QueryParameters): Promise { try { const url = buildUrl({ - origin: MARKET_API_BASE_URL, + base: MARKET_API_BASE_URL, pathname: `api/v3/${endpoint}`, query, }) diff --git a/packages/shared/src/lib/core/router/routers/app-router.ts b/packages/shared/src/lib/core/router/routers/app-router.ts index 403f4c1950..e0624664b1 100644 --- a/packages/shared/src/lib/core/router/routers/app-router.ts +++ b/packages/shared/src/lib/core/router/routers/app-router.ts @@ -24,7 +24,7 @@ export class AppRouter extends Router { this.init() } - public next(params?: { shouldAddProfile: boolean; reset: boolean; thirdPartyProfilesImported: boolean }): void { + public next(params?: { shouldAddProfile?: boolean; reset?: boolean; thirdPartyProfilesImported?: boolean }): void { const currentRoute = get(this.routeStore) switch (currentRoute) { case AppRoute.Login: { diff --git a/packages/shared/src/lib/core/utils/api.ts b/packages/shared/src/lib/core/utils/api.ts index f8cd749d3c..b1d214f18e 100644 --- a/packages/shared/src/lib/core/utils/api.ts +++ b/packages/shared/src/lib/core/utils/api.ts @@ -50,7 +50,7 @@ export class BaseApi { } const url = buildUrl({ - origin: this._baseUrl, + base: this._baseUrl, pathname: `${this._basePath ? this._basePath + '/' : ''}${path}`, query: queryParameters, })