dev #14490 WPA CoffeeLike добавление в wallet вместо установки для iOS
This commit is contained in:
parent
5c3e4a0368
commit
b29f2e1fdf
@ -4,9 +4,15 @@ import {
|
|||||||
HostListener,
|
HostListener,
|
||||||
OnInit,
|
OnInit,
|
||||||
Renderer2,
|
Renderer2,
|
||||||
|
Inject,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
import { lastValueFrom } from 'rxjs';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
import { MessageService } from 'primeng/api';
|
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({
|
@Directive({
|
||||||
selector: '[appDownloadApp]',
|
selector: '[appDownloadApp]',
|
||||||
@ -20,6 +26,10 @@ export class DownloadAppDirective implements OnInit {
|
|||||||
public renderer: Renderer2,
|
public renderer: Renderer2,
|
||||||
private el: ElementRef,
|
private el: ElementRef,
|
||||||
private _snackBar: MatSnackBar,
|
private _snackBar: MatSnackBar,
|
||||||
|
private appleWallet: AppleWalletService,
|
||||||
|
private cookiesService: CookiesService,
|
||||||
|
@Inject(DOCUMENT) private document: Document,
|
||||||
|
private jsonrpc: JsonrpcService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -54,15 +64,13 @@ export class DownloadAppDirective implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('click', ['$event'])
|
@HostListener('click', ['$event'])
|
||||||
downloadApp(event: MouseEvent) {
|
async downloadApp(event: MouseEvent) {
|
||||||
if (event) {
|
if (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
if (this.deviceType === 'ios') {
|
if (this.deviceType === 'ios') {
|
||||||
this._snackBar.open(`Для установки нажмите на кнопку поделиться в Вашем браузере и выберите пункт 'На экран «Домой»'`, '', {
|
await this.addCardToWallet();
|
||||||
duration: 5000,
|
return;
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (!this.deferredPrompt) {
|
if (!this.deferredPrompt) {
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
@ -83,5 +91,31 @@ export class DownloadAppDirective implements OnInit {
|
|||||||
}
|
}
|
||||||
this.deferredPrompt = null;
|
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);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { environment } from 'src/environments/environment';
|
|||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AppleWalletService {
|
export class AppleWalletService {
|
||||||
private url: string = environment.appleWalletEndpoint;
|
private url: string = environment.appleWalletEndpoint;
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
) {}
|
) {}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user