2020-02-16 22:15:07 +07:00
|
|
|
import { Component, Input, AfterViewInit, OnDestroy, ViewChild, ElementRef } from '@angular/core';
|
|
|
|
import * as QRCode from 'qrcode/build/qrcode.js';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-qrcode',
|
|
|
|
templateUrl: './qrcode.component.html',
|
|
|
|
styleUrls: ['./qrcode.component.scss']
|
|
|
|
})
|
2020-02-26 21:11:43 +07:00
|
|
|
export class QrcodeComponent implements AfterViewInit {
|
2020-02-16 22:15:07 +07:00
|
|
|
@Input() data: string;
|
|
|
|
@ViewChild('canvas') canvas: ElementRef;
|
|
|
|
|
|
|
|
qrcodeObject: any;
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
const opts = {
|
|
|
|
errorCorrectionLevel: 'H',
|
|
|
|
margin: 0,
|
|
|
|
color: {
|
|
|
|
dark: '#000',
|
|
|
|
light: '#fff'
|
|
|
|
},
|
|
|
|
width: 125,
|
|
|
|
height: 125,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!this.data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-26 21:11:43 +07:00
|
|
|
const address = this.data;
|
|
|
|
if (this.data.indexOf('bc1') === 0 || this.data.indexOf('tb1') === 0) {
|
|
|
|
address.toUpperCase();
|
|
|
|
}
|
|
|
|
|
2020-02-26 23:21:16 +07:00
|
|
|
QRCode.toCanvas(this.canvas.nativeElement, 'bitcoin:' + address, opts, (error: any) => {
|
2020-02-16 22:15:07 +07:00
|
|
|
if (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|