forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan-qr.js
30 lines (27 loc) · 901 Bytes
/
scan-qr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Helper function that navigates to ScanQR screen, and returns promise that will resolve with the result of a scan,
* and then navigates back. If QRCode scan was closed, promise resolves to null.
*
* @param navigateFunc {function}
* @param currentScreenName {string}
* @param showFileImportButton {boolean}
*
* @return {Promise<string>}
*/
module.exports = function scanQrHelper(navigateFunc, currentScreenName, showFileImportButton = true) {
return new Promise(resolve => {
const params = {};
params.showFileImportButton = !!showFileImportButton;
params.onBarScanned = function (data) {
setTimeout(() => resolve(data.data || data), 1);
navigateFunc(currentScreenName);
};
params.onDismiss = function () {
setTimeout(() => resolve(null), 1);
};
navigateFunc('ScanQRCodeRoot', {
screen: 'ScanQRCode',
params,
});
});
};