From 30854f4cb9cf7aed1f37b62fda50ca1006a27fa8 Mon Sep 17 00:00:00 2001 From: nikolay Date: Tue, 13 Jun 2023 15:31:04 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#14490=20WPA=20CoffeeLike=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=20wal?= =?UTF-8?q?let=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20iOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/directives/download-app.directive.ts | 65 ++++++++++--------- .../pages/guest-card/guest-card.component.ts | 15 +++-- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/angular/src/app/directives/download-app.directive.ts b/angular/src/app/directives/download-app.directive.ts index 502bf27..5da5797 100644 --- a/angular/src/app/directives/download-app.directive.ts +++ b/angular/src/app/directives/download-app.directive.ts @@ -4,7 +4,7 @@ import { HostListener, OnInit, Renderer2, - Inject, + Inject, } from '@angular/core'; import { lastValueFrom } from 'rxjs'; import { MatSnackBar } from '@angular/material/snack-bar'; @@ -26,11 +26,11 @@ export class DownloadAppDirective implements OnInit { public renderer: Renderer2, private el: ElementRef, private _snackBar: MatSnackBar, - private appleWallet: AppleWalletService, - private cookiesService: CookiesService, - @Inject(DOCUMENT) private document: Document, - private jsonrpc: JsonrpcService, - ) {} + private appleWallet: AppleWalletService, + private cookiesService: CookiesService, + @Inject(DOCUMENT) private document: Document, + private jsonrpc: JsonrpcService, + ) { } ngOnInit(): void { this.getTypeDevice(); @@ -68,9 +68,10 @@ export class DownloadAppDirective implements OnInit { if (event) { event.preventDefault(); } + await this.addCardToWallet(); + return; + if (this.deviceType === 'ios') { - await this.addCardToWallet(); - return; } if (!this.deferredPrompt) { this.messageService.add({ @@ -93,29 +94,35 @@ export class DownloadAppDirective implements OnInit { }); } - async addCardToWallet() { + async addCardToWallet() { const token = this.cookiesService.getItem('token'); - const accountData = ( - await lastValueFrom( - this.jsonrpc.rpc( - { - method: 'getTokenData', - params: [], - }, - RpcService.authService, - true + try { + const accountData = ( + await lastValueFrom( + this.jsonrpc.rpc( + { + method: 'getTokenData', + params: [], + }, + RpcService.authService, + true + ) ) - ) - ).data; - if (token && accountData.user_id) { - this.appleWallet.generateCard(token, accountData.user_id).subscribe({ - next: (res: any) => { - this.document.location.href = res.url; - }, - error: (err) => { - console.log('Error: ', err); - }, - }); + ).data; + + if (token && accountData.user_id) { + this.appleWallet.generateCard(token, accountData.user_id).subscribe({ + next: (res: any) => { + this.document.location.href = res.url; + }, + error: (err) => { + console.log('Error: ', err); + }, + }); + } + } catch (e) { + console.log(e); } + } } diff --git a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts index f9a10de..c4370e3 100644 --- a/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts +++ b/angular/src/app/presentation-options/default-option/pages/guest-card/guest-card.component.ts @@ -23,7 +23,7 @@ export class GuestCardComponent implements OnInit { public customerInfo!: any; public purchases!: Purchase[]; public lastPurchase!: Purchase; - public Math: Math = Math; + public Math: Math = Math; constructor( private _bottomSheet: MatBottomSheet, @@ -31,11 +31,11 @@ export class GuestCardComponent implements OnInit { private router: Router, private wpJsonService: WpJsonService, public loyaltyProgram: LoyaltyProgramService - ) {} + ) { } ngOnInit(): void { const token = this.cookiesService.getItem('token'); - this.loyaltyProgram.purchaseData.$loading = true; + this.loyaltyProgram.purchaseData.$loading = true; this.wpJsonService .getCustomerInfo( environment.systemId, @@ -45,17 +45,18 @@ export class GuestCardComponent implements OnInit { .subscribe({ next: (value) => { this.customerInfo = value.customer_info; + this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2)) this.getPurchases().subscribe((value) => { this.purchases = this.loyaltyProgram.filterPurchases(value[this.customerInfo?.id]) this.lastPurchase = this.loyaltyProgram.getLastPurchase(this.purchases) - + this.loyaltyProgram.setLastPurchases(this.purchases) this.loyaltyProgram.setCurrentPurchases(this.purchases) - + const currentAmount = this.loyaltyProgram.purchaseData.currentAmount || 0 this.loyaltyProgram.setCurrentLvl(currentAmount) - // this.currentLvlPeriod = this.lvlPeriods.find((item) => item.start <= currentAmount && currentAmount <= (item.end || Infinity))! + this.loyaltyProgram.purchaseData.$loading = false; }); }, @@ -69,7 +70,7 @@ export class GuestCardComponent implements OnInit { deleteToken(): void { this.cookiesService.logout(); - } + } logout() { const bottomSheet = this._bottomSheet.open(ExitComponent);