import { Inject, Component, OnInit, ViewEncapsulation} from '@angular/core'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog'; import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; var QRCode = require('easyqrcodejs'); var URLSafeBase64 = require('urlsafe-base64'); var Buffer = require('buffer/').Buffer; @Component({ selector: 'app-checkout', templateUrl: './checkout.component.html', styleUrls: ['./checkout.component.css'] }) export class CheckoutComponent implements OnInit{ address: string; total: number; orderId: string; codeString: string = ''; zcashUrl: SafeUrl; constructor( private dialogRef: MatDialogRef, private sanitizer: DomSanitizer, @Inject(MAT_DIALOG_DATA) public data: { totalZec: number, addr: string, orderId: string} ) { this.address = data.addr; this.total = data.totalZec; this.orderId = data.orderId; this.codeString = `zcash:${this.address}?amount=${this.total.toFixed(6)}&memo=${URLSafeBase64.encode(Buffer.from('Z-Go Order '.concat(this.orderId)))}`; this.zcashUrl = this.sanitizer.bypassSecurityTrustUrl(this.codeString); } ngOnInit() { var qrcode = new QRCode(document.getElementById("checkout-qr"), { text: this.codeString, logo: "/assets/zcash.png", logoWidth: 80, logoHeight: 80 }); } confirm() { this.dialogRef.close(true); } close() { this.dialogRef.close(false); } }