File tree Expand file tree Collapse file tree
infrastructure/eid-wallet/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ import {
1313} from " @hugeicons/core-free-icons" ;
1414import { 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
1821let isDeleteConfirmationOpen = $state (false );
1922let 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
Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ let globalDeepLinkHandler: ((event: Event) => void) | undefined;
2020let mainWrapper: HTMLElement | undefined = $state (undefined );
2121
2222setContext (" globalState" , () => globalState );
23+ setContext (" setGlobalState" , (value : GlobalState | undefined ) => {
24+ globalState = value ;
25+ });
2326
2427// replace with actual data loading logic
2528async function loadData() {
You can’t perform that action at this time.
0 commit comments