@@ -11,9 +11,10 @@ import {
11
11
} from '@metamask/keyring-api' ;
12
12
import { captureException } from '@sentry/react-native' ;
13
13
14
- const migrationVersion = 66 ;
15
-
16
- function getScopesForAccountType ( accountType : string ) : string [ ] {
14
+ function getScopesForAccountType (
15
+ accountType : string ,
16
+ migrationNumber : number ,
17
+ ) : string [ ] {
17
18
switch ( accountType ) {
18
19
case EthAccountType . Eoa :
19
20
case EthAccountType . Erc4337 :
@@ -27,7 +28,7 @@ function getScopesForAccountType(accountType: string): string[] {
27
28
// Default to EVM namespace for unknown account types
28
29
captureException (
29
30
new Error (
30
- `Migration ${ migrationVersion } : Unknown account type ${ accountType } , defaulting to EVM namespace ` ,
31
+ `Migration ${ migrationNumber } : Unknown account type ${ accountType } , defaulting to EVM EOA ` ,
31
32
) ,
32
33
) ;
33
34
return [ EthScope . Eoa ] ;
@@ -45,8 +46,8 @@ function getScopesForAccountType(accountType: string): string[] {
45
46
* @param state - The state to migrate
46
47
* @returns The migrated state
47
48
*/
48
- export default function migrate ( state : unknown ) {
49
- if ( ! ensureValidState ( state , migrationVersion ) ) {
49
+ export function migration66 ( state : unknown , migrationNumber : number ) {
50
+ if ( ! ensureValidState ( state , migrationNumber ) ) {
50
51
return state ;
51
52
}
52
53
@@ -70,7 +71,7 @@ export default function migrate(state: unknown) {
70
71
) {
71
72
captureException (
72
73
new Error (
73
- `Migration ${ migrationVersion } : Invalid state structure for AccountsController` ,
74
+ `Migration ${ migrationNumber } : Invalid state structure for AccountsController` ,
74
75
) ,
75
76
) ;
76
77
return state ;
@@ -95,11 +96,21 @@ export default function migrate(state: unknown) {
95
96
}
96
97
97
98
Logger . log (
98
- `Migration ${ migrationVersion } : Adding scopes for account type ${ account . type } ` ,
99
+ `Migration ${ migrationNumber } : Adding scopes for account type ${ account . type } ` ,
99
100
) ;
100
101
101
- account . scopes = getScopesForAccountType ( account . type as string ) ;
102
+ account . scopes = getScopesForAccountType (
103
+ account . type as string ,
104
+ migrationNumber ,
105
+ ) ;
102
106
}
103
107
104
108
return state ;
105
109
}
110
+
111
+ /**
112
+ * Migration for adding scopes to accounts in the AccountsController.
113
+ */
114
+ export default function migrate ( state : unknown ) {
115
+ return migration66 ( state , 66 ) ;
116
+ }
0 commit comments