1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-18 16:33:47 +00:00

Build Account from a StateService provided AccountDeserializer

This commit is contained in:
Matt Gibson
2022-11-16 18:52:38 -05:00
parent 20e748a4b9
commit 04f5e6a144
3 changed files with 22 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
import { BehaviorSubject, concatMap } from "rxjs";
import { Jsonify } from "type-fest";
import { LogService } from "../abstractions/log.service";
import { StateService as StateServiceAbstraction } from "../abstractions/state.service";
@@ -80,6 +81,9 @@ export class StateService<
private accountDiskCache = new Map<string, TAccount>();
// default account serializer, must be overridden by child class
protected accountDeserializer = Account.fromJSON as (json: Jsonify<TAccount>) => TAccount;
constructor(
protected storageService: AbstractStorageService,
protected secureStorageService: AbstractStorageService,
@@ -2745,7 +2749,7 @@ export class StateService<
protected async state(): Promise<State<TGlobalState, TAccount>> {
const state = await this.memoryStorageService.get<State<TGlobalState, TAccount>>(keys.state, {
deserializer: (s) => State.fromJSON(s),
deserializer: (s) => State.fromJSON(s, this.accountDeserializer),
});
return state;
}