2021-12-08 20:24:33 +04:00
|
|
|
import { Component, Input, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
|
|
|
|
import * as QRCode from 'qrcode';
|
2020-11-22 23:47:27 +07:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
@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;
|
2020-10-26 18:29:25 +07:00
|
|
|
@Input() size = 125;
|
2020-10-27 15:26:37 +07:00
|
|
|
@Input() imageUrl: string;
|
2020-02-16 22:15:07 +07:00
|
|
|
@ViewChild('canvas') canvas: ElementRef;
|
|
|
|
|
|
|
|
qrcodeObject: any;
|
|
|
|
|
2020-11-22 23:47:27 +07:00
|
|
|
constructor(
|
|
|
|
private stateService: StateService,
|
|
|
|
) { }
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2020-11-22 23:47:27 +07:00
|
|
|
if (!this.stateService.isBrowser) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-08 20:24:33 +04:00
|
|
|
const opts: QRCode.QRCodeRenderersOptions = {
|
2022-06-29 17:08:47 +02:00
|
|
|
errorCorrectionLevel: 'L',
|
2020-02-16 22:15:07 +07:00
|
|
|
margin: 0,
|
|
|
|
color: {
|
|
|
|
dark: '#000',
|
|
|
|
light: '#fff'
|
|
|
|
},
|
2020-10-26 18:29:25 +07:00
|
|
|
width: this.size,
|
2020-02-16 22:15:07 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!this.data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-26 21:11:43 +07:00
|
|
|
const address = this.data;
|
2022-06-29 17:08:47 +02:00
|
|
|
if (
|
|
|
|
this.data.indexOf('bc1') === 0 ||
|
|
|
|
this.data.indexOf('tb1') === 0 ||
|
|
|
|
this.data.indexOf('bcrt1') === 0
|
|
|
|
) {
|
2020-02-26 21:11:43 +07:00
|
|
|
address.toUpperCase();
|
|
|
|
}
|
|
|
|
|
2020-07-14 14:38:52 +07:00
|
|
|
QRCode.toCanvas(this.canvas.nativeElement, address, opts, (error: any) => {
|
2020-02-16 22:15:07 +07:00
|
|
|
if (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|