dev #14490 WPA CoffeeLike добавление в wallet вместо установки для iOS
This commit is contained in:
parent
5c3e4a0368
commit
b29f2e1fdf
@ -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);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
) {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user