mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-24 11:55:50 +01:00
fix promises on makePremium
This commit is contained in:
parent
1fed3a2440
commit
977abbe572
@ -81,7 +81,7 @@ export class PremiumComponent extends BasePremiumComponent {
|
|||||||
if (payment.productIdentifier !== AppStorePremiumPlan) {
|
if (payment.productIdentifier !== AppStorePremiumPlan) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.makePremium(this.purchasePromise);
|
await this.makePremium(false);
|
||||||
// Finish the transaction.
|
// Finish the transaction.
|
||||||
remote.inAppPurchase.finishTransactionByDate(transaction.transactionDate);
|
remote.inAppPurchase.finishTransactionByDate(transaction.transactionDate);
|
||||||
break;
|
break;
|
||||||
@ -142,7 +142,7 @@ export class PremiumComponent extends BasePremiumComponent {
|
|||||||
makePremium = true;
|
makePremium = true;
|
||||||
} catch { }
|
} catch { }
|
||||||
if (makePremium) {
|
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<any>) {
|
private async makePremium(restore: boolean) {
|
||||||
const receiptUrl = remote.inAppPurchase.getReceiptURL();
|
const receiptUrl = remote.inAppPurchase.getReceiptURL();
|
||||||
const receiptBuffer = fs.readFileSync(receiptUrl);
|
const receiptBuffer = fs.readFileSync(receiptUrl);
|
||||||
const receiptB64 = Utils.fromBufferToB64(receiptBuffer);
|
const receiptB64 = Utils.fromBufferToB64(receiptBuffer);
|
||||||
@ -167,12 +167,18 @@ export class PremiumComponent extends BasePremiumComponent {
|
|||||||
fd.append('paymentToken', receiptB64);
|
fd.append('paymentToken', receiptB64);
|
||||||
fd.append('additionalStorageGb', '0');
|
fd.append('additionalStorageGb', '0');
|
||||||
try {
|
try {
|
||||||
promise = this.apiService.postPremium(fd).then((paymentResponse) => {
|
const p = this.apiService.postPremium(fd).then((paymentResponse) => {
|
||||||
if (paymentResponse.success) {
|
if (paymentResponse.success) {
|
||||||
return this.finalizePremium();
|
return this.finalizePremium();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await promise;
|
if (restore) {
|
||||||
|
this.restorePromise = p;
|
||||||
|
await this.restorePromise;
|
||||||
|
} else {
|
||||||
|
this.purchasePromise = p;
|
||||||
|
await this.purchasePromise;
|
||||||
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user