@@ -7,9 +7,15 @@ import { lockDevice } from '@suite/locks';
77import {
88 metadataActions ,
99 metadataLabelingActions ,
10+ selectHasLegacyLabelsMigrated ,
11+ selectIsMetadataEnabled ,
1012 selectLabelingDataForAccount ,
13+ selectSelectedProviderForLabels ,
1114} from '@suite/metadata' ;
12- import { createMetadataMigrationCompositionRoot } from '@suite/metadata-migration' ;
15+ import {
16+ createEnsureWalletSuiteSyncOnWithMigration ,
17+ createMetadataMigrationCompositionRoot ,
18+ } from '@suite/metadata-migration' ;
1319import type { MetadataMigrationDep } from '@suite/metadata-migration' ;
1420import { closeModal , openModal } from '@suite/modal' ;
1521import {
@@ -42,6 +48,7 @@ import {
4248 selectIsSuiteSyncEnabled ,
4349 selectSuiteSyncWalletLabel ,
4450} from '@suite-common/suite-sync' ;
51+ import { type SuiteSync } from '@suite-common/suite-sync-types' ;
4552import {
4653 type TokenDefinitionsState ,
4754 buildTokenDefinitionsFromStorage ,
@@ -108,7 +115,22 @@ export const createSuiteServicesCompositionRoot = (deps: SuiteAppDeps): SuiteSer
108115
109116 const analytics = createAnalytics ( ) ;
110117
111- const suiteSync = createSuiteSyncDesktopCompositionRoot ( {
118+ const getCurrentAccountLabels = toGetter ( deps . getState , selectAllLabelsForAccount ) ;
119+ const getAccountsByDeviceState = toGetter ( deps . getState , selectAccountsByDeviceState ) ;
120+ const migrateLegacyLabelsToSuiteSyncRef : {
121+ current : MetadataMigrationDep [ 'migrateLegacyLabelsToSuiteSync' ] | undefined ;
122+ } = { current : undefined } ;
123+
124+ const createDecoratedEnsureWalletSuiteSyncOn = createEnsureWalletSuiteSyncOnWithMigration ( {
125+ dispatch : deps . dispatch ,
126+ getMigrateLegacyLabelsToSuiteSync : ( ) => migrateLegacyLabelsToSuiteSyncRef . current ,
127+ getIsMetadataEnabled : toGetter ( deps . getState , selectIsMetadataEnabled ) ,
128+ getSelectedProviderForLabels : toGetter ( deps . getState , selectSelectedProviderForLabels ) ,
129+ getHasLegacyLabelsMigrated : toGetter ( deps . getState , selectHasLegacyLabelsMigrated ) ,
130+ getDeviceByStaticSessionId : toGetter ( deps . getState , selectDeviceByStaticSessionId ) ,
131+ } ) ;
132+
133+ const suiteSync : SuiteSync = createSuiteSyncDesktopCompositionRoot ( {
112134 dispatch : deps . dispatch ,
113135 getState : deps . getState ,
114136 platformEncryption : deps . platformEncryption ,
@@ -122,9 +144,18 @@ export const createSuiteServicesCompositionRoot = (deps: SuiteAppDeps): SuiteSer
122144 dispatch : deps . dispatch ,
123145 deviceStaticSessionId : device ?. state ?. staticSessionId ?? null ,
124146 } ) ,
147+ createDecoratedEnsureWalletSuiteSyncOn,
125148 } ) ;
126149
127- const getCurrentAccountLabels = toGetter ( deps . getState , selectAllLabelsForAccount ) ;
150+ const { migrateLegacyLabelsToSuiteSync } = createMetadataMigrationCompositionRoot ( {
151+ getState : deps . getState ,
152+ getAccountsByDeviceState,
153+ getCurrentWalletLabel : toGetter ( deps . getState , selectSuiteSyncWalletLabel ) ,
154+ getCurrentAccountLabels,
155+ labeling : suiteSync . labeling ,
156+ } ) ;
157+
158+ migrateLegacyLabelsToSuiteSyncRef . current = migrateLegacyLabelsToSuiteSync ;
128159
129160 const { bip329 } = createBip329CompositionRoot ( {
130161 getIsSuiteSyncEnabled : toGetter ( deps . getState , selectIsSuiteSyncEnabled ) ,
@@ -134,27 +165,8 @@ export const createSuiteServicesCompositionRoot = (deps: SuiteAppDeps): SuiteSer
134165 updateOutputLabel : suiteSync . labeling . updateOutputLabel ,
135166 } ) ;
136167
137- const getAccountsByDeviceState = toGetter ( deps . getState , selectAccountsByDeviceState ) ;
138-
139- const {
140- ensureWalletSuiteSyncOn : ensureWalletSuiteSyncOnWithMigration ,
141- migrateLegacyLabelsToSuiteSync,
142- } = createMetadataMigrationCompositionRoot ( {
143- dispatch : deps . dispatch ,
144- getState : deps . getState ,
145- ensureWalletSuiteSyncOn : suiteSync . ensureWalletSuiteSyncOn ,
146- getAccountsByDeviceState,
147- getCurrentWalletLabel : toGetter ( deps . getState , selectSuiteSyncWalletLabel ) ,
148- getCurrentAccountLabels,
149- getDeviceByStaticSessionId : toGetter ( deps . getState , selectDeviceByStaticSessionId ) ,
150- labeling : suiteSync . labeling ,
151- } ) ;
152-
153168 return {
154- suiteSync : {
155- ...suiteSync ,
156- ensureWalletSuiteSyncOn : ensureWalletSuiteSyncOnWithMigration ,
157- } ,
169+ suiteSync,
158170 bip329,
159171 migrateLegacyLabelsToSuiteSync,
160172 ensureDelegatedIdentityKey,
@@ -216,6 +228,7 @@ export const extraDependencies: ExtraDependenciesStatic = {
216228 storageLoadBlockchain : ( state : BlockchainState , { payload } : StorageLoadAction ) => {
217229 payload . backendSettings . forEach ( backend => {
218230 const blockchain = state [ backend . key ] ;
231+
219232 if ( blockchain ) {
220233 blockchain . backends = backend . value ;
221234 }
@@ -238,9 +251,11 @@ export const extraDependencies: ExtraDependenciesStatic = {
238251 networkSymbol : item . tx . symbol ,
239252 deviceStaticSessionId : item . tx . deviceState ,
240253 } ) ;
254+
241255 if ( ! state . transactions [ k ] ) {
242256 state . transactions [ k ] = [ ] ;
243257 }
258+
244259 state . transactions [ k ] [ item . order ] = item . tx ;
245260 } ) ;
246261
0 commit comments