(ret: { data: string })
| 155 | }; |
| 156 | |
| 157 | const onBarCodeRead = (ret: { data: string }) => { |
| 158 | const h = HashIt(ret.data); |
| 159 | if (scannedCache[h]) { |
| 160 | // this QR was already scanned by this ScanQRCode, lets prevent firing duplicate callbacks |
| 161 | return; |
| 162 | } |
| 163 | scannedCache[h] = +new Date(); |
| 164 | |
| 165 | if (ret.data.toUpperCase().startsWith('UR:CRYPTO-ACCOUNT')) { |
| 166 | return _onReadUniformResourceV2(ret.data); |
| 167 | } |
| 168 | |
| 169 | if (ret.data.toUpperCase().startsWith('UR:CRYPTO-PSBT')) { |
| 170 | return _onReadUniformResourceV2(ret.data); |
| 171 | } |
| 172 | |
| 173 | if (ret.data.toUpperCase().startsWith('UR:CRYPTO-OUTPUT')) { |
| 174 | return _onReadUniformResourceV2(ret.data); |
| 175 | } |
| 176 | |
| 177 | if (ret.data.toUpperCase().startsWith('B$')) { |
| 178 | useBBQRRef.current = true; |
| 179 | return _onReadUniformResourceV2(ret.data); |
| 180 | } |
| 181 | |
| 182 | if (ret.data.toUpperCase().startsWith('UR:BYTES')) { |
| 183 | const splitted = ret.data.split('/'); |
| 184 | if (splitted.length === 3 && splitted[1].includes('-')) { |
| 185 | return _onReadUniformResourceV2(ret.data); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if (ret.data.toUpperCase().startsWith('UR')) { |
| 190 | return _onReadUniformResource(ret.data); |
| 191 | } |
| 192 | |
| 193 | // is it base43? stupid electrum desktop |
| 194 | try { |
| 195 | const hex = Base43.decode(ret.data); |
| 196 | bitcoin.Psbt.fromHex(hex); // if it doesnt throw - all good |
| 197 | const data = uint8ArrayToBase64(hexToUint8Array(hex)); |
| 198 | |
| 199 | if (onBarScanned) { |
| 200 | onBarScanned(data, useBBQRRef.current); |
| 201 | navigation.goBack(); |
| 202 | } else if (launchedBy) { |
| 203 | navigation.dispatch(StackActions.popTo(launchedBy, { onBarScanned: data }, { merge: true })); |
| 204 | } |
| 205 | return; |
| 206 | } catch (_) { |
| 207 | if (!isLoading) { |
| 208 | setIsLoading(true); |
| 209 | try { |
| 210 | if (onBarScanned) { |
| 211 | onBarScanned(ret.data, useBBQRRef.current); |
| 212 | navigation.goBack(); |
| 213 | } else if (launchedBy) { |
| 214 | navigation.dispatch(StackActions.popTo(launchedBy, { onBarScanned: ret.data }, { merge: true })); |
no test coverage detected