bitwarden-estensione-browser/libs/angular/src/components/premium.component.ts

62 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-12-16 13:36:21 +01:00
import { Directive, OnInit } from "@angular/core";
2018-04-13 19:19:14 +02:00
2021-12-16 13:36:21 +01:00
import { ApiService } from "jslib-common/abstractions/api.service";
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { LogService } from "jslib-common/abstractions/log.service";
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
import { StateService } from "jslib-common/abstractions/state.service";
2018-04-13 19:19:14 +02:00
@Directive()
2018-04-13 19:19:14 +02:00
export class PremiumComponent implements OnInit {
2022-02-22 15:39:11 +01:00
isPremium = false;
price = 10;
2021-12-16 13:36:21 +01:00
refreshPromise: Promise<any>;
2018-04-13 19:19:14 +02:00
2021-12-16 13:36:21 +01:00
constructor(
protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService,
protected apiService: ApiService,
private logService: LogService,
protected stateService: StateService
) {}
2018-04-13 19:19:14 +02:00
2021-12-16 13:36:21 +01:00
async ngOnInit() {
this.isPremium = await this.stateService.getCanAccessPremium();
}
2018-04-13 19:19:14 +02:00
2021-12-16 13:36:21 +01:00
async refresh() {
try {
this.refreshPromise = this.apiService.refreshIdentityToken();
await this.refreshPromise;
this.platformUtilsService.showToast("success", null, this.i18nService.t("refreshComplete"));
this.isPremium = await this.stateService.getCanAccessPremium();
} catch (e) {
this.logService.error(e);
2018-04-13 19:19:14 +02:00
}
2021-12-16 13:36:21 +01:00
}
2018-04-13 19:19:14 +02:00
2021-12-16 13:36:21 +01:00
async purchase() {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t("premiumPurchaseAlert"),
this.i18nService.t("premiumPurchase"),
this.i18nService.t("yes"),
this.i18nService.t("cancel")
);
if (confirmed) {
this.platformUtilsService.launchUri("https://vault.bitwarden.com/#/?premium=purchase");
2018-04-13 19:19:14 +02:00
}
2021-12-16 13:36:21 +01:00
}
2018-04-13 19:19:14 +02:00
2021-12-16 13:36:21 +01:00
async manage() {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t("premiumManageAlert"),
this.i18nService.t("premiumManage"),
this.i18nService.t("yes"),
this.i18nService.t("cancel")
);
if (confirmed) {
this.platformUtilsService.launchUri("https://vault.bitwarden.com/#/?premium=manage");
2018-04-13 19:19:14 +02:00
}
2021-12-16 13:36:21 +01:00
}
2018-04-13 19:19:14 +02:00
}