Skip to content

Commit 328bc79

Browse files
authored
Fix/wallet restoration not syncing to graphql due to messy state (#432)
* fix: nuke wallet logic * fix: clearing logic * fix: format * fix: missing awaits * fix: nuke call duplicate * fix: state reinitialization logic * fix: format
1 parent 6c27f9c commit 328bc79

7 files changed

Lines changed: 49 additions & 6 deletions

File tree

infrastructure/eid-wallet/src/lib/global/controllers/evault.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,8 @@ export class VaultController {
368368
getendpoint() {
369369
return this.#endpoint;
370370
}
371+
372+
async clear() {
373+
await this.#store.delete("vault");
374+
}
371375
}

infrastructure/eid-wallet/src/lib/global/controllers/key.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,12 @@ export class KeyService {
212212
keyId: rest.join(":"),
213213
};
214214
}
215+
216+
async clear() {
217+
this.#managerCache.clear();
218+
this.#contexts.clear();
219+
await this.#store.delete(CONTEXTS_KEY);
220+
await this.#store.delete(READY_KEY);
221+
this.#ready = false;
222+
}
215223
}

infrastructure/eid-wallet/src/lib/global/controllers/security.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,9 @@ export class SecurityController {
216216
return biometric;
217217
});
218218
}
219+
220+
async clear() {
221+
await this.#store.delete("pin");
222+
await this.#store.delete("biometrics");
223+
}
219224
}

infrastructure/eid-wallet/src/lib/global/controllers/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,10 @@ export class UserController {
143143
return undefined;
144144
});
145145
}
146+
147+
async clear() {
148+
await this.#store.delete("user");
149+
await this.#store.delete("fake");
150+
await this.#store.delete("doc");
151+
}
146152
}

infrastructure/eid-wallet/src/lib/global/state.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,19 @@ export class GlobalState {
109109
});
110110
}
111111
}
112+
113+
async reset() {
114+
try {
115+
await this.securityController.clear();
116+
await this.userController.clear();
117+
await this.vaultController.clear();
118+
await this.keyService.clear();
119+
await this.#store.delete("initialized");
120+
await this.#store.delete("isOnboardingComplete");
121+
} catch (error) {
122+
console.error("Failed to reset global state:", error);
123+
}
124+
const newGlobalState = await GlobalState.create();
125+
return newGlobalState;
126+
}
112127
}

infrastructure/eid-wallet/src/routes/(app)/settings/+page.svelte

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
} from "@hugeicons/core-free-icons";
1414
import { getContext } from "svelte";
1515
16-
const globalState = getContext<() => GlobalState>("globalState")();
16+
const getGlobalState = getContext<() => GlobalState>("globalState");
17+
const setGlobalState =
18+
getContext<(value: GlobalState) => void>("setGlobalState");
19+
let globalState = getGlobalState();
1720
1821
let isDeleteConfirmationOpen = $state(false);
1922
let isFinalConfirmationOpen = $state(false);
@@ -33,11 +36,10 @@ function confirmDelete() {
3336
isFinalConfirmationOpen = true;
3437
}
3538
36-
function nukeWallet() {
37-
globalState.userController.user = undefined;
38-
globalState.securityController.clearPin();
39-
globalState.isOnboardingComplete = false;
40-
isFinalConfirmationOpen = false;
39+
async function nukeWallet() {
40+
const newGlobalState = await globalState.reset();
41+
setGlobalState(newGlobalState);
42+
globalState = newGlobalState;
4143
goto("/onboarding");
4244
}
4345

infrastructure/eid-wallet/src/routes/+layout.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ let globalDeepLinkHandler: ((event: Event) => void) | undefined;
2020
let mainWrapper: HTMLElement | undefined = $state(undefined);
2121
2222
setContext("globalState", () => globalState);
23+
setContext("setGlobalState", (value: GlobalState | undefined) => {
24+
globalState = value;
25+
});
2326
2427
// replace with actual data loading logic
2528
async function loadData() {

0 commit comments

Comments
 (0)