mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 00:03:56 +00:00
* migrate vault toasts to CL toastService * update component args * add missing toastService deps * add missing i18 key * remove moved files * remove duplicate args
102 lines
3.5 KiB
TypeScript
102 lines
3.5 KiB
TypeScript
// 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 { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.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;
|
|
extensionRefreshFlagEnabled: boolean;
|
|
|
|
constructor(
|
|
protected i18nService: I18nService,
|
|
protected platformUtilsService: PlatformUtilsService,
|
|
protected apiService: ApiService,
|
|
protected configService: ConfigService,
|
|
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$);
|
|
this.extensionRefreshFlagEnabled = await this.configService.getFeatureFlag(
|
|
FeatureFlag.ExtensionRefresh,
|
|
);
|
|
}
|
|
|
|
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: this.extensionRefreshFlagEnabled ? "premiumPurchaseAlertV2" : "premiumPurchaseAlert",
|
|
},
|
|
type: "info",
|
|
};
|
|
|
|
if (this.extensionRefreshFlagEnabled) {
|
|
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`,
|
|
);
|
|
}
|
|
}
|
|
}
|