Skip to content

Commit

Permalink
Resolved typescript strict errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cturnbull-bitwarden committed Dec 17, 2024
1 parent 85af1e6 commit a9d072c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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";

Check warning on line 4 in apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts#L4

Added line #L4 was not covered by tests

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
Expand Down Expand Up @@ -45,7 +45,9 @@ export class MoreFromBitwardenPageV2Component {
) {
this.canAccessPremium$ = this.accountService.activeAccount$.pipe(

Check warning on line 46 in apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/tools/popup/settings/about-page/more-from-bitwarden-page-v2.component.ts#L46

Added line #L46 was not covered by tests
switchMap((account) =>
this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id),
account
? this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id)
: of(false),
),
);
this.familySponsorshipAvailable$ = this.organizationService.familySponsorshipAvailable$;
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/app/core/guards/has-premium.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check warning on line 10 in apps/web/src/app/core/guards/has-premium.guard.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/core/guards/has-premium.guard.ts#L9-L10

Added lines #L9 - L10 were not covered by tests

import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";

Check warning on line 12 in apps/web/src/app/core/guards/has-premium.guard.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/core/guards/has-premium.guard.ts#L12

Added line #L12 was not covered by tests
Expand All @@ -29,7 +29,9 @@ export function hasPremiumGuard(): CanActivateFn {

return accountService.activeAccount$.pipe(

Check warning on line 30 in apps/web/src/app/core/guards/has-premium.guard.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/core/guards/has-premium.guard.ts#L30

Added line #L30 was not covered by tests
switchMap((account) =>
billingAccountProfileStateService.hasPremiumFromAnySource$(account.id),
account
? billingAccountProfileStateService.hasPremiumFromAnySource$(account.id)
: of(false),
),
tap((userHasPremium: boolean) => {
if (!userHasPremium) {
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/app/layouts/user-layout.component.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -57,7 +66,6 @@ export class VaultBannersService {

private premiumBannerState: ActiveUserState<PremiumBannerReprompt>;
private sessionBannerState: ActiveUserState<SessionBanners[]>;
private activeUserId: UserId;

/**
* Emits when the sync service has completed a sync
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions libs/angular/src/directives/not-premium.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export class NotPremiumDirective implements OnInit {

async ngOnInit(): Promise<void> {
const account = await firstValueFrom(this.accountService.activeAccount$);

Check warning on line 22 in libs/angular/src/directives/not-premium.directive.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/directives/not-premium.directive.ts#L22

Added line #L22 was not covered by tests

if (!account) {
this.viewContainer.createEmbeddedView(this.templateRef);
return;

Check warning on line 26 in libs/angular/src/directives/not-premium.directive.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/directives/not-premium.directive.ts#L25-L26

Added lines #L25 - L26 were not covered by tests
}

const premium = await firstValueFrom(
this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id),
);
Expand Down
6 changes: 4 additions & 2 deletions libs/angular/src/directives/premium.directive.ts
Original file line number Diff line number Diff line change
@@ -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";

Check warning on line 2 in libs/angular/src/directives/premium.directive.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/directives/premium.directive.ts#L2

Added line #L2 was not covered by tests

import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";

Check warning on line 4 in libs/angular/src/directives/premium.directive.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/directives/premium.directive.ts#L4

Added line #L4 was not covered by tests
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
Expand All @@ -24,7 +24,9 @@ export class PremiumDirective implements OnInit, OnDestroy {
this.accountService.activeAccount$

Check warning on line 24 in libs/angular/src/directives/premium.directive.ts

View check run for this annotation

Codecov / codecov/patch

libs/angular/src/directives/premium.directive.ts#L24

Added line #L24 was not covered by tests
.pipe(
switchMap((account) =>
this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id),
account
? this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id)
: of(false),
),
takeUntil(this.directiveIsDestroyed$),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export class NewSendDropdownComponent implements OnInit {

async ngOnInit() {
const account = await firstValueFrom(this.accountService.activeAccount$);

Check warning on line 32 in libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts#L32

Added line #L32 was not covered by tests
if (!account) {
this.hasNoPremium = true;
return;

Check warning on line 35 in libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/tools/send/send-ui/src/new-send-dropdown/new-send-dropdown.component.ts#L34-L35

Added lines #L34 - L35 were not covered by tests
}

this.hasNoPremium = !(await firstValueFrom(
this.billingAccountProfileStateService.hasPremiumFromAnySource$(account.id),
));
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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),
),
);
}
Expand Down

0 comments on commit a9d072c

Please sign in to comment.