|
1 | 1 | import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
2 |
| -import { IAPProduct } from '@awesome-cordova-plugins/in-app-purchase-2/ngx'; |
3 | 2 | import { AlertController } from '@ionic/angular';
|
4 | 3 | import { TranslocoService } from '@ngneat/transloco';
|
| 4 | +import { UntilDestroy } from '@ngneat/until-destroy'; |
5 | 5 | import { combineLatest } from 'rxjs';
|
6 |
| -import { map, tap } from 'rxjs/operators'; |
| 6 | +import { filter, first, map, tap } from 'rxjs/operators'; |
| 7 | +import { BlockingActionService } from '../../../shared/blocking-action/blocking-action.service'; |
7 | 8 | import { InAppStoreService } from '../../../shared/in-app-store/in-app-store.service';
|
8 | 9 |
|
| 10 | +@UntilDestroy() |
9 | 11 | @Component({
|
10 | 12 | selector: 'app-buy-num',
|
11 | 13 | templateUrl: './buy-num.page.html',
|
@@ -34,21 +36,33 @@ export class BuyNumPage implements OnInit {
|
34 | 36 | tap(_ => this.ref.detectChanges())
|
35 | 37 | );
|
36 | 38 |
|
| 39 | + readonly isProcessingOrder$ = this.store.isProcessingOrder$; |
| 40 | + |
37 | 41 | constructor(
|
38 | 42 | private readonly store: InAppStoreService,
|
39 | 43 | private readonly ref: ChangeDetectorRef,
|
40 | 44 | private readonly alertController: AlertController,
|
41 |
| - private readonly translocoService: TranslocoService |
| 45 | + private readonly translocoService: TranslocoService, |
| 46 | + private readonly blockingActionService: BlockingActionService |
42 | 47 | ) {}
|
43 | 48 |
|
44 | 49 | ngOnInit() {
|
45 | 50 | this.store.refreshNumPointsPricing();
|
46 | 51 | }
|
47 | 52 |
|
48 |
| - purchase(product: IAPProduct) { |
| 53 | + purchase(product: CdvPurchase.Product) { |
| 54 | + this.showLoadingIndicatorUntillOrderIsProcessed(); |
49 | 55 | this.store.purchase(product);
|
50 | 56 | }
|
51 | 57 |
|
| 58 | + private showLoadingIndicatorUntillOrderIsProcessed() { |
| 59 | + const action$ = this.isProcessingOrder$.pipe( |
| 60 | + filter(isProcessing => isProcessing === false), |
| 61 | + first() |
| 62 | + ); |
| 63 | + this.blockingActionService.run$(action$).subscribe(); |
| 64 | + } |
| 65 | + |
52 | 66 | async showNumPointsQuantity(numPoints: number) {
|
53 | 67 | const info = this.translocoService.translate(
|
54 | 68 | 'wallets.buyCredits.thisPackageIncludeXCredits',
|
|
0 commit comments