@@ -11,6 +11,10 @@ import {importSHC} from '../utils/ImportSHC';
1111import { importDCC } from '../utils/ImportDCC' ;
1212import { importVDS } from '../utils/ImportVDS' ;
1313
14+ import { decode } from './QRDecoder/index.js'
15+ import JSZip from 'jszip' ;
16+
17+
1418const screenHeight = Math . round ( Dimensions . get ( 'window' ) . height ) ;
1519
1620function QRReader ( { navigation } ) {
@@ -34,8 +38,33 @@ function QRReader({ navigation }) {
3438 }
3539 }
3640
37- const fromHexString = hexString =>
38- new Uint8Array ( hexString . substring ( 1 ) . match ( / .{ 1 , 2 } / g) . map ( byte => parseInt ( byte , 16 ) ) ) ;
41+ const fromHexQR = async hexString => {
42+ const byteArray = new Uint8Array ( hexString . match ( / .{ 1 , 2 } / g) . map ( byte => parseInt ( byte , 16 ) ) ) ;
43+
44+ // Manually decode the array
45+ const str0 = decode ( byteArray , 28 ) . text ;
46+
47+ const byteArray2 = new Uint8Array ( hexString . substring ( 1 ) . match ( / .{ 1 , 2 } / g) . map ( byte => parseInt ( byte , 16 ) ) ) ;
48+
49+ // invalid QRs have existed for the deployment in India. These two lines help solve it.
50+ const str1 = new TextDecoder ( ) . decode ( byteArray2 ) ;
51+ const str2 = String . fromCharCode . apply ( null , byteArray2 ) ;
52+
53+ try {
54+ await new JSZip ( ) . loadAsync ( str0 ) ;
55+ return str0 ;
56+ } catch {
57+ try {
58+ await new JSZip ( ) . loadAsync ( str1 ) ;
59+ return str1 ;
60+ } catch {
61+ return str2 ;
62+ }
63+ }
64+ }
65+
66+ const toHexString = binaryString =>
67+ Array . from ( new TextEncoder ( ) . encode ( binaryString ) ) . map ( c => c . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ;
3968
4069 const onQRRead = async ( e ) => {
4170 console . log ( e ) ;
@@ -60,8 +89,8 @@ function QRReader({ navigation }) {
6089 return ;
6190 }
6291
63- let string = "PK" + String . fromCharCode . apply ( null , fromHexString ( e . rawData ) )
64- await checkResult ( await importDivoc ( string ) ) ;
92+ // Removing the first byte because it's the QR mode
93+ await checkResult ( await importDivoc ( await fromHexQR ( e . rawData ) ) ) ;
6594 return ;
6695 }
6796
0 commit comments