From b29f2e1fdf9f283aab6ad25e987ef2baa2fd1efc Mon Sep 17 00:00:00 2001 From: nikolay Date: Fri, 9 Jun 2023 12:18:09 +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 | 44 ++++++++++++++++--- .../src/app/services/apple-wallet.service.ts | 2 +- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/angular/src/app/directives/download-app.directive.ts b/angular/src/app/directives/download-app.directive.ts index 40eaa18..502bf27 100644 --- a/angular/src/app/directives/download-app.directive.ts +++ b/angular/src/app/directives/download-app.directive.ts @@ -4,9 +4,15 @@ import { HostListener, OnInit, Renderer2, + Inject, } from '@angular/core'; +import { lastValueFrom } from 'rxjs'; import { MatSnackBar } from '@angular/material/snack-bar'; import { MessageService } from 'primeng/api'; +import { CookiesService } from 'src/app/services/cookies.service'; +import { RpcService, JsonrpcService } from 'src/app/services/jsonrpc.service'; +import { DOCUMENT } from '@angular/common'; +import { AppleWalletService } from 'src/app/services/apple-wallet.service'; @Directive({ selector: '[appDownloadApp]', @@ -20,6 +26,10 @@ 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, ) {} ngOnInit(): void { @@ -54,15 +64,13 @@ export class DownloadAppDirective implements OnInit { } @HostListener('click', ['$event']) - downloadApp(event: MouseEvent) { + async downloadApp(event: MouseEvent) { if (event) { event.preventDefault(); } if (this.deviceType === 'ios') { - this._snackBar.open(`Для установки нажмите на кнопку поделиться в Вашем браузере и выберите пункт 'На экран «Домой»'`, '', { - duration: 5000, - }); - return; + await this.addCardToWallet(); + return; } if (!this.deferredPrompt) { this.messageService.add({ @@ -83,5 +91,31 @@ export class DownloadAppDirective implements OnInit { } this.deferredPrompt = null; }); + } + + async addCardToWallet() { + const token = this.cookiesService.getItem('token'); + 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); + }, + }); + } } } diff --git a/angular/src/app/services/apple-wallet.service.ts b/angular/src/app/services/apple-wallet.service.ts index e184003..0c4e5c5 100644 --- a/angular/src/app/services/apple-wallet.service.ts +++ b/angular/src/app/services/apple-wallet.service.ts @@ -6,7 +6,7 @@ import { environment } from 'src/environments/environment'; providedIn: 'root', }) export class AppleWalletService { - private url: string = environment.appleWalletEndpoint; + private url: string = environment.appleWalletEndpoint; constructor( private http: HttpClient, ) {}