Skip to content

Commit

Permalink
fix: resolve issue for state migration (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 authored Mar 21, 2024
1 parent 8f38b98 commit ce8a6d5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/clever-wasps-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@blockchain-lab-um/masca-types": patch
"@blockchain-lab-um/masca": patch
---

Resolve issue with importing old state.
1 change: 1 addition & 0 deletions packages/snap/src/General.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ class GeneralService {
isValidMascaState(latestState);
StorageService.set(latestState);
} catch (error) {
console.error(error);
throw new Error('Invalid backup state.');
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/snap/src/utils/stateMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ export const migrateToV2 = (state: MascaLegacyStateV1): MascaState => {
// Remove friendly dapps
delete newState.v2.config.dApp.friendlyDapps;

// Remove goerli from polygon state from all accounts
const accounts = Object.keys(newState.v2.accountState);

for (const account of accounts) {
for (const method of ['polygonid', 'iden3']) {
for (const chain of ['eth', 'polygon']) {
delete newState.v2.accountState[account].polygon.state[method][chain]
.goerli;
}
}
}

// Initialize permissions
newState.v2.config.dApp.permissions = { 'masca.io': getInitialPermissions() };

Expand Down
4 changes: 4 additions & 0 deletions packages/snap/tests/data/legacyStates/legacyStateV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ const emptyPolygonState: PolygonLegacyStateV1 = {
polygonid: {
eth: {
main: cloneDeep(emptyPolygonBaseState),
goerli: cloneDeep(emptyPolygonBaseState),
mumbai: cloneDeep(emptyPolygonBaseState), // To satisfy the type checker
},
polygon: {
main: cloneDeep(emptyPolygonBaseState),
goerli: cloneDeep(emptyPolygonBaseState),
mumbai: cloneDeep(emptyPolygonBaseState),
},
},
iden3: {
eth: {
main: cloneDeep(emptyPolygonBaseState),
goerli: cloneDeep(emptyPolygonBaseState),
mumbai: cloneDeep(emptyPolygonBaseState), // To satisfy the type checker
},
polygon: {
main: cloneDeep(emptyPolygonBaseState),
goerli: cloneDeep(emptyPolygonBaseState),
mumbai: cloneDeep(emptyPolygonBaseState),
},
},
Expand Down
5 changes: 4 additions & 1 deletion packages/types/src/legacy/stateV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export type PolygonLegacyStateV1 = Record<
DidMethod.Iden3 | DidMethod.PolygonId,
Record<
Blockchain.Ethereum | Blockchain.Polygon,
Record<NetworkId.Main | NetworkId.Mumbai, PolygonLegacyBaseStateV1>
Record<
NetworkId.Main | NetworkId.Goerli | NetworkId.Mumbai,
PolygonLegacyBaseStateV1
>
>
>;

0 comments on commit ce8a6d5

Please sign in to comment.