import { IACHandlerStatus , IACMessageTransport , PermissionsService , QrScannerService } from '@airgap/angular-core' ; import { PercentPipe } from '@angular/common' ; import { Component , Inject , NgZone , ViewChild } from '@angular/core' ; import { Platform } from '@ionic/angular' ; import { ZXingScannerComponent } from '@zxing/ngx-scanner' ; import { SecurityUtilsPlugin } from 'src/app/capacitor-plugins/definitions' ; import { SECURITY_UTILS_PLUGIN } from 'src/app/capacitor-plugins/injection-tokens' ; import { IACService } from 'src/app/services/iac/iac.service' ; import { ErrorCategory , handleErrorLocal } from '../../services/error-handler/error-handler.service' ; import { ScanBasePage } from '../scan-base/scan-base' ; @ Component ( { selector : 'airgap-tab-scan' , templateUrl : './tab-scan.page.html' , styleUrls : [ './tab-scan.page.scss' ] , providers : [ PercentPipe ] } ) export class TabScanPage extends ScanBasePage { @ ViewChild ( 'scanner' ) public zxingScanner ? : ZXingScannerComponent ; public percentageScanned : number = 0 ; private parts : Set < string > = new Set ( ) ; public isMultiQr : boolean = false ; constructor ( platform , scanner , permissionsProvider , @ Inject ( SECURITY_UTILS_PLUGIN ) securityUtils , private readonly iacService , private readonly ngZone ) { super ( platform , scanner , permissionsProvider , securityUtils ) ; } public async ionViewWillEnter ( ) { await super . ionViewWillEnter ( ) ; this . resetScannerPage ( ) ; this . iacService . resetHandlers ( ) ; } private resetScannerPage ( ) { this . parts = new Set ( ) ; this . percentageScanned = 0 ; this . isMultiQr = false ; this . iacService . resetHandlers ( ) ; } public async checkScan ( data ) { const sizeBefore = this . parts . size ; this . parts . add ( data ) ; if ( sizeBefore === this . parts . size ) { console . log ( `[SCAN:checkScan]: Already scanned string skipping ${ data }` ) ; this . startScan ( ) ; return undefined ; } console . log ( `[SCAN:checkScan]: Trying to decode string ${ data }` ) ; this . ngZone . run ( ( ) => { this . iacService . handleRequest ( data , IACMessageTransport . QR_SCANNER , ( progress ) => { console . log ( 'scan result' , progress ) ; this . isMultiQr = true ; this . percentageScanned = progress ?? 0 ; this . startScan ( ) ; } ) . then ( ( result ) => { if ( result === IACHandlerStatus . SUCCESS ) { this . resetScannerPage ( ) ; } } ) . catch ( handleErrorLocal ( ErrorCategory . SCHEME_ROUTING ) ) ; } ) ; } }