From 977abbe5727e14b26c12bb0836e355f5a0dac012 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 20 Sep 2019 00:00:26 -0400 Subject: [PATCH] fix promises on makePremium --- src/app/accounts/premium.component.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/accounts/premium.component.ts b/src/app/accounts/premium.component.ts index 39a7836a..ba94ac8d 100644 --- a/src/app/accounts/premium.component.ts +++ b/src/app/accounts/premium.component.ts @@ -81,7 +81,7 @@ export class PremiumComponent extends BasePremiumComponent { if (payment.productIdentifier !== AppStorePremiumPlan) { return; } - await this.makePremium(this.purchasePromise); + await this.makePremium(false); // Finish the transaction. remote.inAppPurchase.finishTransactionByDate(transaction.transactionDate); break; @@ -142,7 +142,7 @@ export class PremiumComponent extends BasePremiumComponent { makePremium = true; } catch { } if (makePremium) { - await this.makePremium(this.restorePromise); + await this.makePremium(true); } } @@ -158,7 +158,7 @@ export class PremiumComponent extends BasePremiumComponent { } } - private async makePremium(promise: Promise) { + private async makePremium(restore: boolean) { const receiptUrl = remote.inAppPurchase.getReceiptURL(); const receiptBuffer = fs.readFileSync(receiptUrl); const receiptB64 = Utils.fromBufferToB64(receiptBuffer); @@ -167,12 +167,18 @@ export class PremiumComponent extends BasePremiumComponent { fd.append('paymentToken', receiptB64); fd.append('additionalStorageGb', '0'); try { - promise = this.apiService.postPremium(fd).then((paymentResponse) => { + const p = this.apiService.postPremium(fd).then((paymentResponse) => { if (paymentResponse.success) { return this.finalizePremium(); } }); - await promise; + if (restore) { + this.restorePromise = p; + await this.restorePromise; + } else { + this.purchasePromise = p; + await this.purchasePromise; + } } catch { } }