Skip to content

Commit

Permalink
feat(app): Google Play Billing library 7
Browse files Browse the repository at this point in the history
Upgrade library cordova-plugin-purchase to version 13.11.1 to support
Google Play Billing library 7.0.0.
Fix wallet credits not refreshing after a purchase.
Fix toast error display when canceling a purchase.
  • Loading branch information
olgahaha committed Oct 28, 2024
1 parent c07f1d0 commit 09df7c0
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 17 deletions.
2 changes: 1 addition & 1 deletion android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation project(':appsflyer-capacitor-plugin')
implementation project(':capacitor-blob-writer')
implementation project(':capacitor-native-settings')
implementation "com.android.billingclient:billing:5.2.1"
implementation "com.android.billingclient:billing:7.0.0"
}


Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"capacitor-blob-writer": "^1.0.4",
"capacitor-native-settings": "^4.0.3",
"compressorjs": "^1.0.7",
"cordova-plugin-purchase": "^13.9.0",
"cordova-plugin-purchase": "^13.11.1",
"ethers": "^6.8.1",
"hammerjs": "^2.0.8",
"immutable": "^4.0.0-rc.14",
Expand Down
23 changes: 23 additions & 0 deletions src/app/features/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class HomePage {
readonly initialTabIndex = 0;
private readonly afterCaptureTabIndex = 0;
private readonly collectionTabIndex = 2;
private shouldReloadWallet = false;
selectedTabIndex = this.initialTabIndex;

readonly username$ = this.diaBackendAuthService.username$;
Expand Down Expand Up @@ -112,6 +113,28 @@ export class HomePage {
this.downloadExpiredPostCaptures();
this.overrideAndroidBackButtonBehavior();
this.encourageUserToTakePhoto();
this.reloadWalletPage();
}

private reloadWalletPage() {
this.diaBackendWalletService.reloadWallet$
.pipe(
tap(reload => {
if (reload) {
this.shouldReloadWallet = true;
this.diaBackendWalletService.reloadWallet$.next(false);
}
}),
untilDestroyed(this)
)
.subscribe();
}

ionViewWillEnter() {
if (this.shouldReloadWallet) {
this.shouldReloadWallet = false;
this.router.navigate(['wallets']);
}
}

ionViewDidEnter() {
Expand Down
5 changes: 4 additions & 1 deletion src/app/features/wallets/buy-num/buy-num.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { UntilDestroy } from '@ngneat/until-destroy';
import { combineLatest } from 'rxjs';
import { filter, first, map, tap } from 'rxjs/operators';
import { BlockingActionService } from '../../../shared/blocking-action/blocking-action.service';
import { DiaBackendWalletService } from '../../../shared/dia-backend/wallet/dia-backend-wallet.service';
import { InAppStoreService } from '../../../shared/in-app-store/in-app-store.service';

@UntilDestroy()
Expand Down Expand Up @@ -43,14 +44,16 @@ export class BuyNumPage implements OnInit {
private readonly ref: ChangeDetectorRef,
private readonly alertController: AlertController,
private readonly translocoService: TranslocoService,
private readonly blockingActionService: BlockingActionService
private readonly blockingActionService: BlockingActionService,
private readonly diaBackendWalletService: DiaBackendWalletService
) {}

ngOnInit() {
this.store.refreshNumPointsPricing();
}

purchase(product: CdvPurchase.Product) {
this.diaBackendWalletService.reloadWallet$.next(true);
this.showLoadingIndicatorUntillOrderIsProcessed();
this.store.purchase(product);
}
Expand Down
13 changes: 8 additions & 5 deletions src/app/features/wallets/wallets.page.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<ng-container *ngIf="(networkConnected$ | async) === false; else bubbleIframe">
<mat-toolbar>
<app-capture-back-button></app-capture-back-button>
<span>{{ 'wallets.walets' | transloco }}</span>
<span>{{ 'wallets.wallets' | transloco }}</span>
</mat-toolbar>
<div class="no-network-text">
{{ 'message.networkNotConnected' | transloco }}
</div>
</ng-container>

<ng-template #bubbleIframe>
<ng-container *ngIf="(iframeLoaded$ | ngrxPush) !== true">
<mat-toolbar>
<app-capture-back-button></app-capture-back-button>
<span>{{ 'wallets.wallets' | transloco }}</span>
</mat-toolbar>
<ion-spinner name="lines-sharp"></ion-spinner>
</ng-container>
<iframe
[src]="iframeUrl$ | async | safeResourceUrl"
class="bubble-iframe"
></iframe>
<ion-spinner
*ngIf="(iframeLoaded$ | async) !== true"
name="lines-sharp"
></ion-spinner>
</ng-template>
22 changes: 22 additions & 0 deletions src/app/features/wallets/wallets.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class WalletsPage {

elementType = NgxQrcodeElementTypes.URL;
shouldHideDepositButton = false;
private reload = false;

constructor(
private readonly diaBackendWalletService: DiaBackendWalletService,
Expand All @@ -48,6 +49,14 @@ export class WalletsPage {
private readonly navController: NavController
) {
this.processIframeEvents();
this.reloadPage();
}

ionViewWillEnter() {
if (this.reload) {
this.reload = false;
this.navController.back({ animated: false });
}
}

private processIframeEvents() {
Expand Down Expand Up @@ -84,6 +93,19 @@ export class WalletsPage {
.subscribe();
}

private reloadPage() {
this.diaBackendWalletService.reloadWallet$
.pipe(
tap(reload => {
if (reload) {
this.reload = true;
}
}),
untilDestroyed(this)
)
.subscribe();
}

private copyToClipboardAssetWallet() {
this.assetWalletAddr$
.pipe(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { combineLatest, defer, forkJoin } from 'rxjs';
import { BehaviorSubject, combineLatest, defer, forkJoin } from 'rxjs';
import { catchError, concatMap, first } from 'rxjs/operators';
import { ErrorService } from '../../error/error.service';
import { NetworkService } from '../../network/network.service';
Expand Down Expand Up @@ -36,6 +36,8 @@ export class DiaBackendWalletService {

// For integrity wallet addr, use WebCryptoApiSignatureProvider.publicKey$

readonly reloadWallet$ = new BehaviorSubject(false);

readonly networkConnected$ = this.networkService.connected$;

constructor(
Expand Down
6 changes: 5 additions & 1 deletion src/app/shared/in-app-store/in-app-store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ export class InAppStoreService implements OnDestroy {
private readonly onStoreError = (error: CdvPurchase.IError) => {
this.isProcessingOrder$.next(false);

if (error.message === 'The user cancelled the order.') return;
if (
error.code === CdvPurchase.ErrorCode.PAYMENT_CANCELLED ||
error.message === 'The user cancelled the order.'
)
return;

const errorMessage = this.translocoService.translate(
'inAppPurchase.inAppPurchaseErrorOcurred'
Expand Down

0 comments on commit 09df7c0

Please sign in to comment.