Ensure that initialization and migration only run once (#631)

This commit is contained in:
Daniel James Smith 2022-01-24 20:37:52 +01:00 committed by GitHub
parent e5cc3de46d
commit af7da0e942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -58,6 +58,8 @@ export class StateService<TAccount extends Account = Account>
protected state: State<TAccount> = new State<TAccount>();
private hasBeenInited: boolean = false;
constructor(
protected storageService: StorageService,
protected secureStorageService: StorageService,
@ -67,11 +69,16 @@ export class StateService<TAccount extends Account = Account>
) {}
async init(): Promise<void> {
if (this.hasBeenInited) {
return;
}
if (await this.stateMigrationService.needsMigration()) {
await this.stateMigrationService.migrate();
}
await this.initAccountState();
this.hasBeenInited = true;
}
async initAccountState() {