2021-04-22 21:17:14 +02:00
|
|
|
import { Directive, OnInit } from '@angular/core';
|
2018-04-13 19:19:14 +02:00
|
|
|
|
2021-06-03 18:58:57 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2021-10-19 10:32:14 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2021-06-03 18:58:57 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
|
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
2018-04-13 19:19:14 +02:00
|
|
|
|
2021-04-22 21:17:14 +02:00
|
|
|
@Directive()
|
2018-04-13 19:19:14 +02:00
|
|
|
export class PremiumComponent implements OnInit {
|
|
|
|
isPremium: boolean = false;
|
2018-08-31 21:38:40 +02:00
|
|
|
price: number = 10;
|
2018-04-13 19:19:14 +02:00
|
|
|
refreshPromise: Promise<any>;
|
|
|
|
|
2018-10-03 06:03:49 +02:00
|
|
|
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
|
2021-10-19 10:32:14 +02:00
|
|
|
protected apiService: ApiService, protected userService: UserService, private logService: LogService) { }
|
2018-04-13 19:19:14 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2021-03-24 17:15:51 +01:00
|
|
|
this.isPremium = await this.userService.canAccessPremium();
|
2018-04-13 19:19:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async refresh() {
|
|
|
|
try {
|
|
|
|
this.refreshPromise = this.apiService.refreshIdentityToken();
|
|
|
|
await this.refreshPromise;
|
2018-10-03 05:09:19 +02:00
|
|
|
this.platformUtilsService.showToast('success', null, this.i18nService.t('refreshComplete'));
|
2021-03-24 17:15:51 +01:00
|
|
|
this.isPremium = await this.userService.canAccessPremium();
|
2021-10-19 10:32:14 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
2018-04-13 19:19:14 +02: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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|