1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 05:00:10 +00:00

code cleanup

This commit is contained in:
✨ Audrey ✨
2025-04-24 11:15:32 -04:00
parent a990419502
commit 69857a057a
3 changed files with 14 additions and 11 deletions

View File

@@ -23,7 +23,6 @@ import {
ReplaySubject,
Subject,
takeUntil,
tap,
withLatestFrom,
} from "rxjs";
@@ -234,9 +233,7 @@ export class CredentialGeneratorComponent implements OnInit, OnChanges, OnDestro
// wire up the generator
this.generatorService
.generate$({
on$: this.generate$.pipe(
tap((g) => this.log.debug(g, "generate request issued by component")),
),
on$: this.generate$,
account$: this.account$,
})
.pipe(

View File

@@ -44,6 +44,7 @@ describe("DefaultCredentialGeneratorService", () => {
beforeEach(() => {
mockLogger = {
info: jest.fn(),
debug: jest.fn(),
panic: jest.fn().mockImplementationOnce((c, m) => {
throw new Error(m ?? c);
}),

View File

@@ -1,5 +1,6 @@
import {
EMPTY,
combineLatest,
concatMap,
distinctUntilChanged,
filter,
@@ -54,7 +55,7 @@ export class DefaultCredentialGeneratorService implements CredentialGeneratorSer
const account$ = dependencies.account$.pipe(shareReplay({ refCount: true, bufferSize: 1 }));
// load algorithm metadata
const algorithm$ = on$.pipe(
const metadata$ = on$.pipe(
switchMap((requested) => {
if (isAlgorithmRequest(requested)) {
return of(requested.algorithm);
@@ -71,17 +72,21 @@ export class DefaultCredentialGeneratorService implements CredentialGeneratorSer
shareReplay({ refCount: true, bufferSize: 1 }),
);
// load the active profile's algorithm settings
const settings$ = on$.pipe(
// load the active profile's settings
const profile$ = on$.pipe(
map((request) => request.profile ?? Profile.account),
distinctUntilChanged(),
withLatestReady(algorithm$),
switchMap(([profile, meta]) => this.settings(meta, { account$ }, profile)),
);
const settings$ = combineLatest([metadata$, profile$]).pipe(
tap(([metadata, profile]) =>
this.log.debug({ algorithm: metadata.id, profile }, "settings loaded"),
),
switchMap(([metadata, profile]) => this.settings(metadata, { account$ }, profile)),
);
// load the algorithm's engine
const engine$ = algorithm$.pipe(
tap((meta) => this.log.info({ algorithm: meta.id }, "engine selected")),
const engine$ = metadata$.pipe(
tap((metadata) => this.log.debug({ algorithm: metadata.id }, "engine selected")),
map((meta) => meta.engine.create(this.provide.generator)),
);