From a9d072c2a186fcd6cb6335e1aa04291b7163b66f Mon Sep 17 00:00:00 2001 From: Conner Turnbull Date: Tue, 17 Dec 2024 13:14:17 -0500 Subject: [PATCH] Resolved typescript strict errors --- .../more-from-bitwarden-page-v2.component.ts | 6 ++-- .../src/app/core/guards/has-premium.guard.ts | 6 ++-- .../src/app/layouts/user-layout.component.ts | 2 ++ .../services/vault-banners.service.ts | 33 ++++++++++++------- .../src/directives/not-premium.directive.ts | 6 ++++ .../src/directives/premium.directive.ts | 6 ++-- .../new-send-dropdown.component.ts | 5 +++ .../send-list-filters.component.ts | 6 ++-- 8 files changed, 51 insertions(+), 19 deletions(-) diff --git a/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts b/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts index d0e9a52e4ec..8b880e88671 100644 --- a/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts +++ b/apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts @@ -1,7 +1,7 @@ import { CommonModule } from "@angular/common"; import { Component } from "@angular/core"; import { RouterModule } from "@angular/router"; -import { Observable, firstValueFrom, switchMap } from "rxjs"; +import { Observable, firstValueFrom, of, switchMap } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; @@ -45,7 +45,9 @@ export class MoreFromBitwardenPageV2Component { ) { this.canAccessPremium$ = this.accountService.activeAccount$.pipe( switchMap((account) => - this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id), + account + ? this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id) + : of(false), ), ); this.familySponsorshipAvailable$ = this.organizationService.familySponsorshipAvailable$; diff --git a/apps/web/src/app/core/guards/has-premium.guard.ts b/apps/web/src/app/core/guards/has-premium.guard.ts index c4f84d15f60..61853b25cb8 100644 --- a/apps/web/src/app/core/guards/has-premium.guard.ts +++ b/apps/web/src/app/core/guards/has-premium.guard.ts @@ -6,7 +6,7 @@ import { CanActivateFn, UrlTree, } from "@angular/router"; -import { Observable } from "rxjs"; +import { Observable, of } from "rxjs"; import { switchMap, tap } from "rxjs/operators"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; @@ -29,7 +29,9 @@ export function hasPremiumGuard(): CanActivateFn { return accountService.activeAccount$.pipe( switchMap((account) => - billingAccountProfileStateService.hasPremiumFromAnySource$(account.id), + account + ? billingAccountProfileStateService.hasPremiumFromAnySource$(account.id) + : of(false), ), tap((userHasPremium: boolean) => { if (!userHasPremium) { diff --git a/apps/web/src/app/layouts/user-layout.component.ts b/apps/web/src/app/layouts/user-layout.component.ts index de110ab5f51..f0ac3ef9b48 100644 --- a/apps/web/src/app/layouts/user-layout.component.ts +++ b/apps/web/src/app/layouts/user-layout.component.ts @@ -1,3 +1,5 @@ +// FIXME: Update this file to be type safe and remove this and next line +// @ts-strict-ignore import { CommonModule } from "@angular/common"; import { Component, OnInit } from "@angular/core"; import { RouterModule } from "@angular/router"; diff --git a/apps/web/src/app/vault/individual-vault/vault-banners/services/vault-banners.service.ts b/apps/web/src/app/vault/individual-vault/vault-banners/services/vault-banners.service.ts index dfb72f7de81..c18b046e35e 100644 --- a/apps/web/src/app/vault/individual-vault/vault-banners/services/vault-banners.service.ts +++ b/apps/web/src/app/vault/individual-vault/vault-banners/services/vault-banners.service.ts @@ -1,5 +1,15 @@ import { Injectable } from "@angular/core"; -import { Subject, Observable, combineLatest, firstValueFrom, map, mergeMap, take } from "rxjs"; +import { + Subject, + Observable, + combineLatest, + firstValueFrom, + map, + mergeMap, + take, + switchMap, + of, +} from "rxjs"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { TokenService } from "@bitwarden/common/auth/abstractions/token.service"; @@ -13,7 +23,6 @@ import { BANNERS_DISMISSED_DISK, UserKeyDefinition, } from "@bitwarden/common/platform/state"; -import { UserId } from "@bitwarden/common/types/guid"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { PBKDF2KdfConfig, KdfConfigService, KdfType } from "@bitwarden/key-management"; @@ -57,7 +66,6 @@ export class VaultBannersService { private premiumBannerState: ActiveUserState; private sessionBannerState: ActiveUserState; - private activeUserId: UserId; /** * Emits when the sync service has completed a sync @@ -82,14 +90,17 @@ export class VaultBannersService { this.premiumBannerState = this.stateProvider.getActive(PREMIUM_BANNER_REPROMPT_KEY); this.sessionBannerState = this.stateProvider.getActive(BANNERS_DISMISSED_DISK_KEY); - this.accountService.activeAccount$.pipe(take(1)).subscribe((account) => { - this.activeUserId = account?.id; - }); - - const premiumSources$ = combineLatest([ - this.billingAccountProfileStateService.hasPremiumFromAnySource$(this.activeUserId), - this.premiumBannerState.state$, - ]); + const premiumSources$ = this.accountService.activeAccount$.pipe( + take(1), + switchMap((account) => { + return combineLatest([ + account + ? this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id) + : of(false), + this.premiumBannerState.state$, + ]); + }), + ); this.shouldShowPremiumBanner$ = this.syncCompleted$.pipe( take(1), // Wait until the first sync is complete before considering the premium status diff --git a/libs/angular/src/directives/not-premium.directive.ts b/libs/angular/src/directives/not-premium.directive.ts index cc2af5a767a..5a1c636c009 100644 --- a/libs/angular/src/directives/not-premium.directive.ts +++ b/libs/angular/src/directives/not-premium.directive.ts @@ -20,6 +20,12 @@ export class NotPremiumDirective implements OnInit { async ngOnInit(): Promise { const account = await firstValueFrom(this.accountService.activeAccount$); + + if (!account) { + this.viewContainer.createEmbeddedView(this.templateRef); + return; + } + const premium = await firstValueFrom( this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id), ); diff --git a/libs/angular/src/directives/premium.directive.ts b/libs/angular/src/directives/premium.directive.ts index 7a4a3a24d35..2188205ba65 100644 --- a/libs/angular/src/directives/premium.directive.ts +++ b/libs/angular/src/directives/premium.directive.ts @@ -1,5 +1,5 @@ import { Directive, OnDestroy, OnInit, TemplateRef, ViewContainerRef } from "@angular/core"; -import { Subject, switchMap, takeUntil } from "rxjs"; +import { of, Subject, switchMap, takeUntil } from "rxjs"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; @@ -24,7 +24,9 @@ export class PremiumDirective implements OnInit, OnDestroy { this.accountService.activeAccount$ .pipe( switchMap((account) => - this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id), + account + ? this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id) + : of(false), ), takeUntil(this.directiveIsDestroyed$), ) diff --git a/libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts b/libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts index 8a529fc034b..19f9d3a174a 100644 --- a/libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts +++ b/libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts @@ -30,6 +30,11 @@ export class NewSendDropdownComponent implements OnInit { async ngOnInit() { const account = await firstValueFrom(this.accountService.activeAccount$); + if (!account) { + this.hasNoPremium = true; + return; + } + this.hasNoPremium = !(await firstValueFrom( this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id), )); diff --git a/libs/tools/send/send-ui/src/send-list-filters/send-list-filters.component.ts b/libs/tools/send/send-ui/src/send-list-filters/send-list-filters.component.ts index 2fe37c5a789..d42eab382e9 100644 --- a/libs/tools/send/send-ui/src/send-list-filters/send-list-filters.component.ts +++ b/libs/tools/send/send-ui/src/send-list-filters/send-list-filters.component.ts @@ -1,7 +1,7 @@ import { CommonModule } from "@angular/common"; import { Component, OnDestroy } from "@angular/core"; import { ReactiveFormsModule } from "@angular/forms"; -import { Observable, switchMap } from "rxjs"; +import { Observable, of, switchMap } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; @@ -28,7 +28,9 @@ export class SendListFiltersComponent implements OnDestroy { ) { this.canAccessPremium$ = accountService.activeAccount$.pipe( switchMap((account) => - billingAccountProfileStateService.hasPremiumFromAnySource$(account.id), + account + ? billingAccountProfileStateService.hasPremiumFromAnySource$(account.id) + : of(false), ), ); }