mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
* Added billing account profile state service
* Update usages after removing state service functions
* Added migrator
* Updated bw.ts and main.background.ts
* Removed comment
* Updated state service dependencies to include billing service
* Added missing mv3 factory and updated MainContextMenuHandler
* updated autofill service and tests
* Updated the remaining extensions usages
* Updated desktop
* Removed subjects where they weren't needed
* Refactored billing service to have a single setter to avoid unecessary emissions
* Refactored has premium guard to return an observable
* Renamed services to match ADR
f633f2cdd8/docs/architecture/clients/presentation/angular.md (abstract--default-implementations)
* Updated property names to be a smidgen more descriptive and added jsdocs
* Updated setting of canAccessPremium to automatically update when the underlying observable emits
* Fixed build error after merge conflicts
* Another build error from conflict
* Removed autofill unit test changes from conflict
* Updated login strategy to not set premium field using state service
* Updated CLI to use billing state provider
* Shortened names a bit
* Fixed build
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import { Directive } from "@angular/core";
|
|
import { Observable, Subject } from "rxjs";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.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 { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
|
import { DialogService } from "@bitwarden/components";
|
|
|
|
@Directive()
|
|
export class PremiumComponent {
|
|
isPremium$: Observable<boolean>;
|
|
price = 10;
|
|
refreshPromise: Promise<any>;
|
|
cloudWebVaultUrl: string;
|
|
private directiveIsDestroyed$ = new Subject<boolean>();
|
|
|
|
constructor(
|
|
protected i18nService: I18nService,
|
|
protected platformUtilsService: PlatformUtilsService,
|
|
protected apiService: ApiService,
|
|
private logService: LogService,
|
|
protected stateService: StateService,
|
|
protected dialogService: DialogService,
|
|
environmentService: EnvironmentService,
|
|
billingAccountProfileStateService: BillingAccountProfileStateService,
|
|
) {
|
|
this.cloudWebVaultUrl = environmentService.getCloudWebVaultUrl();
|
|
this.isPremium$ = billingAccountProfileStateService.hasPremiumFromAnySource$;
|
|
}
|
|
|
|
async refresh() {
|
|
try {
|
|
this.refreshPromise = this.apiService.refreshIdentityToken();
|
|
await this.refreshPromise;
|
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("refreshComplete"));
|
|
} catch (e) {
|
|
this.logService.error(e);
|
|
}
|
|
}
|
|
|
|
async purchase() {
|
|
const confirmed = await this.dialogService.openSimpleDialog({
|
|
title: { key: "premiumPurchase" },
|
|
content: { key: "premiumPurchaseAlert" },
|
|
type: "info",
|
|
});
|
|
|
|
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`,
|
|
);
|
|
}
|
|
}
|
|
}
|