1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

Move premium component into billing ownership (#12927)

* Move premium component into billing ownership

Update CODEOWNERS
Move files within libs/angular
Move files within desktop
Adjust import paths

* Remove configService

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith
2025-01-29 17:09:19 +01:00
committed by GitHub
parent ab197049f5
commit e73cb3e3ff
10 changed files with 9 additions and 28 deletions

View File

@@ -2,3 +2,4 @@ export * from "./add-account-credit-dialog/add-account-credit-dialog.component";
export * from "./invoices/invoices.component";
export * from "./invoices/no-invoices.component";
export * from "./manage-tax-information/manage-tax-information.component";
export * from "./premium.component";

View File

@@ -0,0 +1,92 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { OnInit, Directive } from "@angular/core";
import { firstValueFrom, Observable, switchMap } from "rxjs";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DialogService, SimpleDialogOptions, ToastService } from "@bitwarden/components";
@Directive()
export class PremiumComponent implements OnInit {
isPremium$: Observable<boolean>;
price = 10;
refreshPromise: Promise<any>;
cloudWebVaultUrl: string;
constructor(
protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService,
protected apiService: ApiService,
private logService: LogService,
protected dialogService: DialogService,
private environmentService: EnvironmentService,
billingAccountProfileStateService: BillingAccountProfileStateService,
private toastService: ToastService,
accountService: AccountService,
) {
this.isPremium$ = accountService.activeAccount$.pipe(
switchMap((account) =>
billingAccountProfileStateService.hasPremiumFromAnySource$(account.id),
),
);
}
async ngOnInit() {
this.cloudWebVaultUrl = await firstValueFrom(this.environmentService.cloudWebVaultUrl$);
}
async refresh() {
try {
this.refreshPromise = this.apiService.refreshIdentityToken();
await this.refreshPromise;
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("refreshComplete"),
});
} catch (e) {
this.logService.error(e);
}
}
async purchase() {
const dialogOpts: SimpleDialogOptions = {
title: { key: "continueToBitwardenDotCom" },
content: {
key: "premiumPurchaseAlertV2",
},
type: "info",
};
dialogOpts.acceptButtonText = { key: "continue" };
dialogOpts.cancelButtonText = { key: "close" };
const confirmed = await this.dialogService.openSimpleDialog(dialogOpts);
if (confirmed) {
this.platformUtilsService.launchUri(
`${this.cloudWebVaultUrl}/#/settings/subscription/premium`,
);
}
}
async manage() {
const confirmed = await this.dialogService.openSimpleDialog({
title: { key: "premiumManage" },
content: { key: "premiumManageAlert" },
type: "info",
});
if (confirmed) {
this.platformUtilsService.launchUri(
`${this.cloudWebVaultUrl}/#/settings/subscription/premium`,
);
}
}
}