From 6f078bfa168dd74fecb5142d25b973f3eaa1de52 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Fri, 3 May 2024 13:38:35 +0200 Subject: [PATCH 1/2] chore: cleanup network feature flags --- packages/desktop/features/network.features.ts | 3 --- packages/desktop/features/onboarding.features.ts | 3 +++ .../convertOnboardingProfileToPersistedProfile.ts | 2 +- .../src/lib/core/network/stores/networks.store.ts | 11 +++-------- .../features/interfaces/network-features.interface.ts | 1 - .../lib/features/types/onboarding-features.type.ts | 1 + 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/desktop/features/network.features.ts b/packages/desktop/features/network.features.ts index 46e5469254..4aa3ab67d4 100644 --- a/packages/desktop/features/network.features.ts +++ b/packages/desktop/features/network.features.ts @@ -8,9 +8,6 @@ const networkFeatures: INetworkFeatures = { enabled: false, }, }, - evmNetworks: { - enabled: false, - }, } export default networkFeatures diff --git a/packages/desktop/features/onboarding.features.ts b/packages/desktop/features/onboarding.features.ts index d7bc4104e2..c4686b3749 100644 --- a/packages/desktop/features/onboarding.features.ts +++ b/packages/desktop/features/onboarding.features.ts @@ -172,6 +172,9 @@ const onboardingFeatures: OnboardingFeatures = { shimmer: onboardingFeaturesForShimmer, testnet: onboardingFeaturesForTestnet, custom: onboardingFeaturesForCustom, + addEvmNetworks: { + enabled: false, + }, importFromThirdParty: { enabled: true, }, diff --git a/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts b/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts index 1e734047bb..ab5e37c721 100644 --- a/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts +++ b/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts @@ -15,7 +15,7 @@ export function convertOnboardingProfileToPersistedProfile( } let evmNetworks: IPureEvmNetworkConfiguration[] | undefined - if (features.network.evmNetworks.enabled) { + if (features.onboarding.addEvmNetworks.enabled) { const addMainnetEthereum = [SupportedNetworkId.Shimmer, SupportedNetworkId.Iota].includes(network.id) evmNetworks = [ DEFAULT_L1_EVM_NETWORK_CONFIGURATION[ diff --git a/packages/shared/src/lib/core/network/stores/networks.store.ts b/packages/shared/src/lib/core/network/stores/networks.store.ts index 0b9b0d925c..509c271410 100644 --- a/packages/shared/src/lib/core/network/stores/networks.store.ts +++ b/packages/shared/src/lib/core/network/stores/networks.store.ts @@ -1,8 +1,5 @@ import { Writable, writable, get } from 'svelte/store' - import { activeProfile } from '@core/profile/stores' -import features from '@features/features' - import { IscChain, EvmNetwork, StardustNetwork } from '../classes' import { IEvmNetwork, IIscChain, IStardustNetwork } from '../interfaces' import { EvmNetworkId, Network, NetworkId } from '../types' @@ -18,11 +15,9 @@ export function initializeNetworks(): void { _networks.push(stardustNetwork, ...stardustNetwork.iscChains) } - if (features.network.evmNetworks.enabled) { - profile.evmNetworks?.forEach((evmNetwork) => { - _networks.push(new EvmNetwork(evmNetwork)) - }) - } + profile.evmNetworks?.forEach((evmNetwork) => { + _networks.push(new EvmNetwork(evmNetwork)) + }) networks.set(_networks) } diff --git a/packages/shared/src/lib/features/interfaces/network-features.interface.ts b/packages/shared/src/lib/features/interfaces/network-features.interface.ts index 1534e6e447..6fc43109fd 100644 --- a/packages/shared/src/lib/features/interfaces/network-features.interface.ts +++ b/packages/shared/src/lib/features/interfaces/network-features.interface.ts @@ -4,5 +4,4 @@ export interface INetworkFeatures extends IFeatureFlag { config: IFeatureFlag & { addChain: IFeatureFlag } - evmNetworks: IFeatureFlag } diff --git a/packages/shared/src/lib/features/types/onboarding-features.type.ts b/packages/shared/src/lib/features/types/onboarding-features.type.ts index 3f35ce59e7..c1a45afe25 100644 --- a/packages/shared/src/lib/features/types/onboarding-features.type.ts +++ b/packages/shared/src/lib/features/types/onboarding-features.type.ts @@ -4,6 +4,7 @@ import { IFeatureFlag, IOnboardingFeaturesForNetwork } from '../interfaces' export type OnboardingFeatures = IFeatureFlag & { [key in OnboardingNetworkType]?: IOnboardingFeaturesForNetwork & IFeatureFlag } & { + addEvmNetworks: IFeatureFlag importFromThirdParty: IFeatureFlag strongholdVersionCheck: IFeatureFlag confetti: IFeatureFlag From 9d06cf6a12bb9d98c765f5f8923d055526ef20f7 Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Tue, 7 May 2024 10:26:03 +0100 Subject: [PATCH 2/2] refactor: move feature flag to constant for evm chains --- .../desktop/features/onboarding.features.ts | 15 ++++-- ...vertOnboardingProfileToPersistedProfile.ts | 14 +----- ...gurations-for-stardust-network.constant.ts | 50 +++++++++++++++++++ ...-l1-evm-network-configurations.constant.ts | 34 ------------- .../src/lib/core/network/constants/index.ts | 2 +- ...boarding-features-for-network.interface.ts | 1 + .../types/onboarding-features.type.ts | 1 - 7 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts delete mode 100644 packages/shared/src/lib/core/network/constants/default-l1-evm-network-configurations.constant.ts diff --git a/packages/desktop/features/onboarding.features.ts b/packages/desktop/features/onboarding.features.ts index a6051bfeae..54ec956446 100644 --- a/packages/desktop/features/onboarding.features.ts +++ b/packages/desktop/features/onboarding.features.ts @@ -44,6 +44,9 @@ const onboardingFeaturesForIota: IOnboardingFeaturesForNetwork = { defaultIscChains: { enabled: false, }, + defaultEvmChains: { + enabled: false, + }, } const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = { @@ -88,6 +91,9 @@ const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = { defaultIscChains: { enabled: true, }, + defaultEvmChains: { + enabled: false, + }, } const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { @@ -132,6 +138,9 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = { defaultIscChains: { enabled: true, }, + defaultEvmChains: { + enabled: true, + }, } const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = { @@ -176,6 +185,9 @@ const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = { defaultIscChains: { enabled: false, }, + defaultEvmChains: { + enabled: false, + }, } const onboardingFeatures: OnboardingFeatures = { @@ -184,9 +196,6 @@ const onboardingFeatures: OnboardingFeatures = { shimmer: onboardingFeaturesForShimmer, testnet: onboardingFeaturesForTestnet, custom: onboardingFeaturesForCustom, - addEvmNetworks: { - enabled: false, - }, importFromThirdParty: { enabled: true, }, diff --git a/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts b/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts index ab5e37c721..49d7211333 100644 --- a/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts +++ b/packages/shared/src/lib/contexts/onboarding/helpers/convertOnboardingProfileToPersistedProfile.ts @@ -2,9 +2,7 @@ import { IPersistedProfile } from '@core/profile/interfaces' import { DEFAULT_PERSISTED_PROFILE_OBJECT } from '@core/profile/constants' import { IOnboardingProfile } from '../interfaces' -import { DEFAULT_L1_EVM_NETWORK_CONFIGURATION, SupportedNetworkId } from '@core/network/constants' -import features from '@features/features' -import { IPureEvmNetworkConfiguration } from '@core/network/interfaces' +import { DEFAULT_EVM_NETWORK_CONFIGURATIONS_FOR_STARDUST_NETWORK } from '@core/network/constants' export function convertOnboardingProfileToPersistedProfile( onboardingProfile?: Partial @@ -14,15 +12,7 @@ export function convertOnboardingProfileToPersistedProfile( throw new Error('Network is undefined!') } - let evmNetworks: IPureEvmNetworkConfiguration[] | undefined - if (features.onboarding.addEvmNetworks.enabled) { - const addMainnetEthereum = [SupportedNetworkId.Shimmer, SupportedNetworkId.Iota].includes(network.id) - evmNetworks = [ - DEFAULT_L1_EVM_NETWORK_CONFIGURATION[ - addMainnetEthereum ? SupportedNetworkId.Ethereum : SupportedNetworkId.Sepolia - ], - ] - } + const evmNetworks = DEFAULT_EVM_NETWORK_CONFIGURATIONS_FOR_STARDUST_NETWORK[network.id] ?? [] return { ...structuredClone(DEFAULT_PERSISTED_PROFILE_OBJECT), diff --git a/packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts b/packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts new file mode 100644 index 0000000000..3952b292bb --- /dev/null +++ b/packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts @@ -0,0 +1,50 @@ +import { isFeatureEnabled } from '@lib/features/utils' +import { ChainId, NetworkNamespace, NetworkType } from '../enums' +import { IPureEvmNetworkConfiguration } from '../interfaces' +import { StardustNetworkId } from '../types' +import { EVM_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 { + SupportedL1EvmNetworkId, + SupportedNetworkId, + SupportedStardustNetworkId, +} from './supported-network-id.constant' + +const ETHEREUM_NETWORK_CONFIGURATION: IPureEvmNetworkConfiguration = { + type: NetworkType.Evm, + name: 'Ethereum', + baseToken: EVM_BASE_TOKEN, + id: SupportedL1EvmNetworkId.Ethereum, + chainId: ChainId.Ethereum, + namespace: NetworkNamespace.Evm, + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Ethereum] ?? 0, + explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.Ethereum], + rpcEndpoint: 'https://ethereum-rpc.publicnode.com', +} + +export const SEPOLIA_NETWORK_CONFIGURATION: IPureEvmNetworkConfiguration = { + type: NetworkType.Evm, + name: 'Sepolia Testnet', + baseToken: EVM_BASE_TOKEN, + id: SupportedL1EvmNetworkId.Sepolia, + chainId: ChainId.Sepolia, + namespace: NetworkNamespace.Evm, + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Sepolia] ?? 0, + explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.Sepolia], + rpcEndpoint: 'https://ethereum-sepolia-rpc.publicnode.com', +} + +export const DEFAULT_EVM_NETWORK_CONFIGURATIONS_FOR_STARDUST_NETWORK: Readonly<{ + [key in StardustNetworkId]: IPureEvmNetworkConfiguration[] +}> = { + ...(isFeatureEnabled('onboarding.iota.defaultEvmChains') && { + [SupportedStardustNetworkId.Iota]: [ETHEREUM_NETWORK_CONFIGURATION], + }), + ...(isFeatureEnabled('onboarding.shimmer.defaultEvmChains') && { + [SupportedStardustNetworkId.Shimmer]: [ETHEREUM_NETWORK_CONFIGURATION], + }), + ...(isFeatureEnabled('onboarding.testnet.defaultEvmChains') && { + [SupportedStardustNetworkId.Testnet]: [SEPOLIA_NETWORK_CONFIGURATION], + }), +} diff --git a/packages/shared/src/lib/core/network/constants/default-l1-evm-network-configurations.constant.ts b/packages/shared/src/lib/core/network/constants/default-l1-evm-network-configurations.constant.ts deleted file mode 100644 index 689fadb358..0000000000 --- a/packages/shared/src/lib/core/network/constants/default-l1-evm-network-configurations.constant.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { ChainId, NetworkType, NetworkNamespace } from '../enums' -import { IPureEvmNetworkConfiguration } from '../interfaces' -import { EvmNetworkId } from '../types' -import { DEFAULT_COIN_TYPE } from './default-coin-type.constant' -import { SupportedL1EvmNetworkId, SupportedNetworkId } from './supported-network-id.constant' -import { DEFAULT_EXPLORER_URLS } from './default-explorer-urls.constant' -import { EVM_BASE_TOKEN } from './default-base-token.constant' - -export const DEFAULT_L1_EVM_NETWORK_CONFIGURATION: Readonly<{ - [key in EvmNetworkId]: IPureEvmNetworkConfiguration -}> = { - [SupportedL1EvmNetworkId.Ethereum]: { - type: NetworkType.Evm, - name: 'Ethereum', - baseToken: EVM_BASE_TOKEN, - id: SupportedL1EvmNetworkId.Ethereum, - chainId: ChainId.Ethereum, - namespace: NetworkNamespace.Evm, - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Ethereum] ?? 0, - explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.Ethereum], - rpcEndpoint: 'https://ethereum-rpc.publicnode.com', - }, - [SupportedL1EvmNetworkId.Sepolia]: { - type: NetworkType.Evm, - name: 'Sepolia Testnet', - baseToken: EVM_BASE_TOKEN, - id: SupportedL1EvmNetworkId.Sepolia, - chainId: ChainId.Sepolia, - namespace: NetworkNamespace.Evm, - coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Sepolia] ?? 0, - explorerUrl: DEFAULT_EXPLORER_URLS[SupportedNetworkId.Sepolia], - rpcEndpoint: 'https://ethereum-sepolia-rpc.publicnode.com', - }, -} diff --git a/packages/shared/src/lib/core/network/constants/index.ts b/packages/shared/src/lib/core/network/constants/index.ts index 42325d40c8..ca78462814 100644 --- a/packages/shared/src/lib/core/network/constants/index.ts +++ b/packages/shared/src/lib/core/network/constants/index.ts @@ -6,7 +6,7 @@ export * from './default-coin-type.constant' export * from './default-bech32-hrp.constant' export * from './default-base-token.constant' export * from './default-isc-chains-configurations.constant' -export * from './default-l1-evm-network-configurations.constant' +export * from './default-evm-network-configurations-for-stardust-network.constant' export * from './default-explorer-urls.constant' export * from './default-protocol.constant' export * from './default-network-metadata.constant' diff --git a/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts b/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts index 6fc84fc93c..d9221b46b6 100644 --- a/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts +++ b/packages/shared/src/lib/features/interfaces/onboarding-features-for-network.interface.ts @@ -18,4 +18,5 @@ export interface IOnboardingFeaturesForNetwork extends IFeatureFlag { ledgerBackup: IFeatureFlag } defaultIscChains: IFeatureFlag + defaultEvmChains: IFeatureFlag } diff --git a/packages/shared/src/lib/features/types/onboarding-features.type.ts b/packages/shared/src/lib/features/types/onboarding-features.type.ts index 3cdbaedae1..17efeb4a06 100644 --- a/packages/shared/src/lib/features/types/onboarding-features.type.ts +++ b/packages/shared/src/lib/features/types/onboarding-features.type.ts @@ -4,7 +4,6 @@ import { IFeatureFlag, IOnboardingFeaturesForNetwork } from '../interfaces' export type OnboardingFeatures = IFeatureFlag & { [key in OnboardingNetworkType]: IOnboardingFeaturesForNetwork & IFeatureFlag } & { - addEvmNetworks: IFeatureFlag importFromThirdParty: IFeatureFlag strongholdVersionCheck: IFeatureFlag confetti: IFeatureFlag