1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

getReceiptUrl only when receipt available

This commit is contained in:
Kyle Spearrin 2019-09-23 22:59:40 -04:00
parent 7e01fcba2b
commit dff1bb8144

View File

@ -43,11 +43,11 @@ export class PremiumComponent extends BasePremiumComponent {
async ngOnInit() { async ngOnInit() {
await super.ngOnInit(); await super.ngOnInit();
if (this.isPremium || !this.platformUtilsService.isMacAppStore()) { const isMacAppStore = this.platformUtilsService.isMacAppStore();
return; if (isMacAppStore) {
}
this.canMakeMacAppStorePayments = remote.inAppPurchase.canMakePayments(); this.canMakeMacAppStorePayments = remote.inAppPurchase.canMakePayments();
if (!this.canMakeMacAppStorePayments) { }
if (this.isPremium || !isMacAppStore || !this.canMakeMacAppStorePayments) {
return; return;
} }
const pricePromise = new Promise((resolve) => { const pricePromise = new Promise((resolve) => {
@ -147,7 +147,7 @@ export class PremiumComponent extends BasePremiumComponent {
} }
async manage() { async manage() {
if (!this.canMakeMacAppStorePayments || remote.inAppPurchase.getReceiptURL() == null) { if (!this.canMakeMacAppStorePayments || this.getReceiptUrl() == null) {
await super.manage(); await super.manage();
return; return;
} }
@ -159,7 +159,7 @@ export class PremiumComponent extends BasePremiumComponent {
} }
private async makePremium(restore: boolean) { private async makePremium(restore: boolean) {
const receiptUrl = remote.inAppPurchase.getReceiptURL(); const receiptUrl = this.getReceiptUrl();
const receiptBuffer = fs.readFileSync(receiptUrl); const receiptBuffer = fs.readFileSync(receiptUrl);
const receiptB64 = Utils.fromBufferToB64(receiptBuffer); const receiptB64 = Utils.fromBufferToB64(receiptBuffer);
const fd = new FormData(); const fd = new FormData();
@ -193,10 +193,18 @@ export class PremiumComponent extends BasePremiumComponent {
private setCanRestorePurchase() { private setCanRestorePurchase() {
if (!this.isPremium && this.canMakeMacAppStorePayments) { if (!this.isPremium && this.canMakeMacAppStorePayments) {
const receiptUrl = remote.inAppPurchase.getReceiptURL(); const receiptUrl = this.getReceiptUrl();
this.canRestorePurchase = receiptUrl != null; this.canRestorePurchase = receiptUrl != null;
} else { } else {
this.canRestorePurchase = false; this.canRestorePurchase = false;
} }
} }
private getReceiptUrl(): string {
const receiptUrl = remote.inAppPurchase.getReceiptURL();
if (receiptUrl != null) {
return fs.existsSync(receiptUrl) ? receiptUrl : null;
}
return null;
}
} }