From 159997539fa67aca51186424aed92a10a57d7e7f Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Mon, 1 Jul 2024 19:05:50 -0300 Subject: [PATCH] chore: adds profile migration --- .../profile/constants/profile-version.constant.ts | 4 ++-- .../alpha/alpha-profile-migration-22-to-23.ts | 13 +++++++++++++ .../migrations/alpha/alpha-profile-migration-map.ts | 2 ++ .../prod/prod-profile-migration-12-to-13.ts | 13 +++++++++++++ .../migrations/prod/prod-profile-migration-map.ts | 2 ++ 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-22-to-23.ts create mode 100644 packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-12-to-13.ts 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 c401f50226..0c1f60063e 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]: 22, + [AppStage.ALPHA]: 23, [AppStage.BETA]: 1, - [AppStage.PROD]: 12, + [AppStage.PROD]: 13, } diff --git a/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-22-to-23.ts b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-22-to-23.ts new file mode 100644 index 0000000000..7be0910670 --- /dev/null +++ b/packages/shared/src/lib/core/profile/migrations/alpha/alpha-profile-migration-22-to-23.ts @@ -0,0 +1,13 @@ +import { CryptoCurrency, FiatCurrency } from '@core/market' +import { IPersistedProfile } from '@core/profile/interfaces' + +export function alphaProfileMigration22To23(existingProfile: unknown): Promise { + const profile = existingProfile as IPersistedProfile + const marketCurrencies = [...Object.values(FiatCurrency), ...Object.values(CryptoCurrency)] + + if (!marketCurrencies.includes(profile?.settings?.marketCurrency)) { + profile.settings.marketCurrency = FiatCurrency.USD + } + + 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 ae0fc54a75..0106ed25b1 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 @@ -14,6 +14,7 @@ import { alphaProfileMigration19To20 } from './alpha-profile-migration-19-to-20' import { alphaProfileMigration2To3 } from './alpha-profile-migration-2-to-3' import { alphaProfileMigration20To21 } from './alpha-profile-migration-20-to-21' import { alphaProfileMigration21To22 } from './alpha-profile-migration-21-to-22' +import { alphaProfileMigration22To23 } from './alpha-profile-migration-22-to-23' 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' @@ -48,5 +49,6 @@ export const ALPHA_PROFILE_MIGRATION_MAP: ProfileMigrationMap = { 20: alphaProfileMigration20To21, // ^^^ release 1.0.4 ^^^ 21: alphaProfileMigration21To22, + 22: alphaProfileMigration22To23, // ^^^ release 1.0.8 ^^^ } diff --git a/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-12-to-13.ts b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-12-to-13.ts new file mode 100644 index 0000000000..978755684c --- /dev/null +++ b/packages/shared/src/lib/core/profile/migrations/prod/prod-profile-migration-12-to-13.ts @@ -0,0 +1,13 @@ +import { CryptoCurrency, FiatCurrency } from '@core/market' +import { IPersistedProfile } from '@core/profile/interfaces' + +export function prodProfileMigration12To13(existingProfile: unknown): Promise { + const profile = existingProfile as IPersistedProfile + const marketCurrencies = [...Object.values(FiatCurrency), ...Object.values(CryptoCurrency)] + + if (!marketCurrencies.includes(profile?.settings?.marketCurrency)) { + profile.settings.marketCurrency = FiatCurrency.USD + } + + 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 a714993fd6..91c5ef42b6 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 @@ -12,6 +12,7 @@ import { prodProfileMigration9To10 } from './prod-profile-migration-9-to-10' import { prodProfileMigration8To9 } from './prod-profile-migration-8-to-9' import { prodProfileMigration10To11 } from './prod-profile-migration-10-to-11' import { prodProfileMigration11To12 } from './prod-profile-migration-11-to-12' +import { prodProfileMigration12To13 } from './prod-profile-migration-12-to-13' export const PROD_PROFILE_MIGRATION_MAP: ProfileMigrationMap = { 0: prodProfileMigration0To1, @@ -29,5 +30,6 @@ export const PROD_PROFILE_MIGRATION_MAP: ProfileMigrationMap = { 10: prodProfileMigration10To11, // ^^^ release 1.0.4 ^^^ 11: prodProfileMigration11To12, + 12: prodProfileMigration12To13, // ^^^ release 1.0.8 ^^^ }