From 383e239ec3c464d4a3a001753a668839a08555aa Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Wed, 11 Sep 2024 23:36:09 -0300 Subject: [PATCH] chore: adds profile migrations --- .../views/ManageNetworksDrawer.svelte | 4 ++-- ...gurations-for-stardust-network.constant.ts | 7 ++++++- .../constants/profile-version.constant.ts | 4 ++-- .../alpha/alpha-profile-migration-25-to-26.ts | 19 +++++++++++++++++++ .../alpha/alpha-profile-migration-map.ts | 2 ++ .../prod/prod-profile-migration-15-to-16.ts | 19 +++++++++++++++++++ .../prod/prod-profile-migration-map.ts | 2 ++ 7 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-25-to-26.ts create mode 100644 packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-15-to-16.ts diff --git a/packages/desktop/views/dashboard/drawers/network-config/views/ManageNetworksDrawer.svelte b/packages/desktop/views/dashboard/drawers/network-config/views/ManageNetworksDrawer.svelte index f10af354c6..d955d2ff87 100644 --- a/packages/desktop/views/dashboard/drawers/network-config/views/ManageNetworksDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/network-config/views/ManageNetworksDrawer.svelte @@ -5,7 +5,7 @@ import { localize } from '@core/i18n' import { addNewEvmNetwork, - KNOWN_EVM_NETWORKS_CONFIGURATIONS, + KNOWN_EVM_MAINNET_NETWORKS_CONFIGURATIONS, KNOWN_EVM_TESTNET_NETWORKS_CONFIGURATIONS, SupportedNetworkId, } from '@core/network' @@ -20,7 +20,7 @@ const networkConfigurations = isTestnet ? KNOWN_EVM_TESTNET_NETWORKS_CONFIGURATIONS - : KNOWN_EVM_NETWORKS_CONFIGURATIONS + : KNOWN_EVM_MAINNET_NETWORKS_CONFIGURATIONS const selectedChains = networkConfigurations.reduce((acc, networkConfiguration) => { acc[networkConfiguration.id] = $activeProfile?.evmNetworks.some( 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 index ea4906e1a8..dea45d37e7 100644 --- 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 @@ -177,7 +177,7 @@ export const IMMUTABLE_TESTNET_NETWORK_CONFIGURATION: IPureEvmNetworkConfigurati rpcEndpoint: 'https://rpc.testnet.immutable.com', } -export const KNOWN_EVM_NETWORKS_CONFIGURATIONS: Readonly = [ +export const KNOWN_EVM_MAINNET_NETWORKS_CONFIGURATIONS: Readonly = [ ETHEREUM_NETWORK_CONFIGURATION, ARBITRUM_NETWORK_CONFIGURATION, BASE_NETWORK_CONFIGURATION, @@ -195,6 +195,11 @@ export const KNOWN_EVM_TESTNET_NETWORKS_CONFIGURATIONS: Readonly = [ + ...KNOWN_EVM_MAINNET_NETWORKS_CONFIGURATIONS, + ...KNOWN_EVM_TESTNET_NETWORKS_CONFIGURATIONS, +] + export const DEFAULT_EVM_NETWORK_CONFIGURATIONS_FOR_STARDUST_NETWORK: Readonly<{ [key in StardustNetworkId]: IPureEvmNetworkConfiguration[] }> = { diff --git a/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts b/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts index 68478f0646..50e5e852a0 100644 --- a/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts +++ b/packages/shared/src/lib/core/profile/constants/profile-version.constant.ts @@ -1,7 +1,7 @@ import { AppStage } from '@core/app/enums' export const PROFILE_VERSION: Record = { - [AppStage.ALPHA]: 25, + [AppStage.ALPHA]: 26, [AppStage.BETA]: 1, - [AppStage.PROD]: 15, + [AppStage.PROD]: 16, } diff --git a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-25-to-26.ts b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-25-to-26.ts new file mode 100644 index 0000000000..eafa8b4848 --- /dev/null +++ b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-25-to-26.ts @@ -0,0 +1,19 @@ +import { IIscChainConfiguration } from '@core/network' +import { KNOWN_EVM_NETWORKS_CONFIGURATIONS } from '@core/network/constants' +import { IPersistedProfile } from '@core/profile/interfaces' + +export function alphaProfileMigration25To26(existingProfile: unknown): Promise { + const profile = existingProfile as IPersistedProfile + + const chainConfigurations = profile.network.chainConfigurations as (IIscChainConfiguration & { + explorerUrl?: string + })[] + chainConfigurations.forEach((chainConfiguration) => { + delete chainConfiguration.explorerUrl + chainConfiguration.explorer = KNOWN_EVM_NETWORKS_CONFIGURATIONS.find( + (networkConfiguration) => networkConfiguration.id === chainConfiguration.id + )?.explorer + }) + + return Promise.resolve() +} diff --git a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts index 1471fdd861..f17eb49076 100644 --- a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts +++ b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-map.ts @@ -17,6 +17,7 @@ import { alphaProfileMigration21To22 } from './alpha-profile-migration-21-to-22' import { alphaProfileMigration22To23 } from './alpha-profile-migration-22-to-23' import { alphaProfileMigration23To24 } from './alpha-profile-migration-23-to-24' import { alphaProfileMigration24To25 } from './alpha-profile-migration-24-to-25' +import { alphaProfileMigration25To26 } from './alpha-profile-migration-25-to-26' import { alphaProfileMigration3To4 } from './alpha-profile-migration-3-to-4' import { alphaProfileMigration4To5 } from './alpha-profile-migration-4-to-5' import { alphaProfileMigration5To6 } from './alpha-profile-migration-5-to-6' @@ -57,4 +58,5 @@ export const ALPHA_PROFILE_MIGRATION_MAP: ProfileMigrationMap = { 23: alphaProfileMigration23To24, // ^^^ release 1.1.3 ^^^ 24: alphaProfileMigration24To25, + 25: alphaProfileMigration25To26, } diff --git a/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-15-to-16.ts b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-15-to-16.ts new file mode 100644 index 0000000000..141160e9ff --- /dev/null +++ b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-15-to-16.ts @@ -0,0 +1,19 @@ +import { IIscChainConfiguration } from '@core/network' +import { KNOWN_EVM_NETWORKS_CONFIGURATIONS } from '@core/network/constants' +import { IPersistedProfile } from '@core/profile/interfaces' + +export function prodProfileMigration15To16(existingProfile: unknown): Promise { + const profile = existingProfile as IPersistedProfile + + const chainConfigurations = profile.network.chainConfigurations as (IIscChainConfiguration & { + explorerUrl?: string + })[] + chainConfigurations.forEach((chainConfiguration) => { + delete chainConfiguration.explorerUrl + chainConfiguration.explorer = KNOWN_EVM_NETWORKS_CONFIGURATIONS.find( + (networkConfiguration) => networkConfiguration.id === chainConfiguration.id + )?.explorer + }) + + return Promise.resolve() +} diff --git a/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-map.ts b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-map.ts index f942f72ca8..617ca09210 100644 --- a/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-map.ts +++ b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-map.ts @@ -15,6 +15,7 @@ import { prodProfileMigration11To12 } from './prod-profile-migration-11-to-12' import { prodProfileMigration12To13 } from './prod-profile-migration-12-to-13' import { prodProfileMigration13To14 } from './prod-profile-migration-13-to-14' import { prodProfileMigration14To15 } from './prod-profile-migration-14-to-15' +import { prodProfileMigration15To16 } from './prod-profile-migration-15-to-16' export const PROD_PROFILE_MIGRATION_MAP: ProfileMigrationMap = { 0: prodProfileMigration0To1, @@ -38,4 +39,5 @@ export const PROD_PROFILE_MIGRATION_MAP: ProfileMigrationMap = { 13: prodProfileMigration13To14, // ^^^ release 1.1.3 ^^^ 14: prodProfileMigration14To15, + 15: prodProfileMigration15To16, }