Skip to content

Commit

Permalink
feat: migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi committed May 29, 2024
1 parent a22ba2c commit 92fa825
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/desktop/components/ContactCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ContactAvatar {contact} />
<div class="flex w-full text-left overflow-hidden">
<Text type="base" truncate>
{contact.name}
{contact?.name}
</Text>
</div>
{#if showBreadcrumb}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppStage } from '@core/app/enums'

export const PROFILE_VERSION: Record<AppStage, number> = {
[AppStage.ALPHA]: 19,
[AppStage.ALPHA]: 20,
[AppStage.BETA]: 1,
[AppStage.PROD]: 10,
[AppStage.PROD]: 11,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { IContactAddressMap } from '@core/contact'
import { isEvmNetwork, NetworkId, SupportedNetworkId } from '@core/network'
import { IPersistedProfile } from '@core/profile/interfaces'

export function migrateEvmContacts(profile: IPersistedProfile): void {
const evmNetworks = Object.keys(profile.networkContactAddresses).filter((networkId) =>
isEvmNetwork(networkId as NetworkId)
)

const migratedContacts: IContactAddressMap = structuredClone(
profile.networkContactAddresses[SupportedNetworkId.GenericEvm] ?? {}
)

evmNetworks.forEach((network) => {
const networkContacts: IContactAddressMap = profile.networkContactAddresses[network] ?? {}
Object.entries(networkContacts).forEach(([address, contactAddress]) => {
migratedContacts[address] = contactAddress
})
delete profile.networkContactAddresses[network]
})

profile.networkContactAddresses[SupportedNetworkId.GenericEvm] = migratedContacts
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IPersistedProfile } from '../../interfaces'
import { migrateEvmContacts } from '../../migrations/actions/migrateEvmContacts'

export function alphaProfileMigration19To20(existingProfile: unknown): Promise<void> {
const profile = existingProfile as IPersistedProfile

migrateEvmContacts(profile)

return Promise.resolve()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { alphaProfileMigration15To16 } from './alpha-profile-migration-15-to-16'
import { alphaProfileMigration16To17 } from './alpha-profile-migration-16-to-17'
import { alphaProfileMigration17To18 } from './alpha-profile-migration-17-to-18'
import { alphaProfileMigration18To19 } from './alpha-profile-migration-18-to-19'
import { alphaProfileMigration19To20 } from './alpha-profile-migration-19-to-20'
import { alphaProfileMigration2To3 } from './alpha-profile-migration-2-to-3'
import { alphaProfileMigration3To4 } from './alpha-profile-migration-3-to-4'
import { alphaProfileMigration4To5 } from './alpha-profile-migration-4-to-5'
Expand Down Expand Up @@ -41,4 +42,5 @@ export const ALPHA_PROFILE_MIGRATION_MAP: ProfileMigrationMap = {
17: alphaProfileMigration17To18,
18: alphaProfileMigration18To19,
// ^^^ release 1.0.3 ^^^
19: alphaProfileMigration19To20,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IPersistedProfile } from '../../interfaces'
import { migrateEvmContacts } from '../actions/migrateEvmContacts'

export function prodProfileMigration10To11(existingProfile: unknown): Promise<void> {
const profile = existingProfile as IPersistedProfile

migrateEvmContacts(profile)

return Promise.resolve()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { prodProfileMigration6To7 } from './prod-profile-migration-6-to-7'
import { prodProfileMigration7To8 } from './prod-profile-migration-7-to-8'
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'

export const PROD_PROFILE_MIGRATION_MAP: ProfileMigrationMap = {
0: prodProfileMigration0To1,
Expand All @@ -24,4 +25,5 @@ export const PROD_PROFILE_MIGRATION_MAP: ProfileMigrationMap = {
8: prodProfileMigration8To9, // Migration was removed and replaced with 10To11 after 9To10
// ^^^ release 1.0.3 ^^^
9: prodProfileMigration9To10, // rechecking some previous migrations due to a bug during migrations
10: prodProfileMigration10To11,
}

0 comments on commit 92fa825

Please sign in to comment.