From 3857d0f94e8279af07d78c8210f2a28835f1a771 Mon Sep 17 00:00:00 2001 From: jaasen-livefront Date: Fri, 31 Jan 2025 09:15:29 -0800 Subject: [PATCH] favor subscription over firstValueFrom in desktop cipher view --- .../src/vault/components/view.component.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/angular/src/vault/components/view.component.ts b/libs/angular/src/vault/components/view.component.ts index abbedf13078..efa7055b723 100644 --- a/libs/angular/src/vault/components/view.component.ts +++ b/libs/angular/src/vault/components/view.component.ts @@ -11,7 +11,7 @@ import { OnInit, Output, } from "@angular/core"; -import { filter, firstValueFrom, map, Observable } from "rxjs"; +import { filter, firstValueFrom, map, Observable, Subject, takeUntil } from "rxjs"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { AuditService } from "@bitwarden/common/abstractions/audit.service"; @@ -81,6 +81,7 @@ export class ViewComponent implements OnDestroy, OnInit { private passwordReprompted = false; private activeUserId$ = this.accountService.activeAccount$.pipe(map((a) => a?.id)); + private destroyed$ = new Subject(); get fido2CredentialCreationDateValue(): string { const dateCreated = this.i18nService.t("dateCreated"); @@ -146,12 +147,15 @@ export class ViewComponent implements OnDestroy, OnInit { const activeUserId = await firstValueFrom(this.activeUserId$); // Grab individual cipher from `cipherViews$` for the most up-to-date information - this.cipher = await firstValueFrom( - this.cipherService.cipherViews$.pipe( - map((ciphers) => ciphers.find((c) => c.id === this.cipherId)), + this.cipherService.cipherViews$ + .pipe( + map((ciphers) => ciphers?.find((c) => c.id === this.cipherId)), filter((cipher) => !!cipher), - ), - ); + takeUntil(this.destroyed$), + ) + .subscribe((cipher) => { + this.cipher = cipher; + }); this.canAccessPremium = await firstValueFrom( this.billingAccountProfileStateService.hasPremiumFromAnySource$(activeUserId),