diff options
author | Bruno Barbieri <bruno.barbieri@consensys.net> | 2018-08-11 01:40:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-11 01:40:06 +0800 |
commit | e2be22a4b722df608cb764042cc8ade6664414d8 (patch) | |
tree | 6a0c48ea06401ea8e06c14630edc7c0157f6e25c /ui/app/actions.js | |
parent | be1d5a7dd959f061b52f475bf8500b943ade786c (diff) | |
parent | d0ccc59e459ecb41742b6e55a1875dfa2a2f9f87 (diff) | |
download | tangerine-wallet-browser-e2be22a4b722df608cb764042cc8ade6664414d8.tar tangerine-wallet-browser-e2be22a4b722df608cb764042cc8ade6664414d8.tar.gz tangerine-wallet-browser-e2be22a4b722df608cb764042cc8ade6664414d8.tar.bz2 tangerine-wallet-browser-e2be22a4b722df608cb764042cc8ade6664414d8.tar.lz tangerine-wallet-browser-e2be22a4b722df608cb764042cc8ade6664414d8.tar.xz tangerine-wallet-browser-e2be22a4b722df608cb764042cc8ade6664414d8.tar.zst tangerine-wallet-browser-e2be22a4b722df608cb764042cc8ade6664414d8.zip |
Merge pull request #4897 from MetaMask/qr-code-scan
QR Code Scanner
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r-- | ui/app/actions.js | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 9edb3511a..bd5d25327 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -12,6 +12,7 @@ const { fetchLocale } = require('../i18n-helper') const log = require('loglevel') const { ENVIRONMENT_TYPE_NOTIFICATION } = require('../../app/scripts/lib/enums') const { hasUnconfirmedTransactions } = require('./helpers/confirm-transaction/util') +const WebcamUtils = require('../lib/webcam-utils') var actions = { _setBackgroundConnection: _setBackgroundConnection, @@ -33,6 +34,8 @@ var actions = { ALERT_CLOSE: 'UI_ALERT_CLOSE', showAlert: showAlert, hideAlert: hideAlert, + QR_CODE_DETECTED: 'UI_QR_CODE_DETECTED', + qrCodeDetected, // network dropdown open NETWORK_DROPDOWN_OPEN: 'UI_NETWORK_DROPDOWN_OPEN', NETWORK_DROPDOWN_CLOSE: 'UI_NETWORK_DROPDOWN_CLOSE', @@ -125,7 +128,8 @@ var actions = { SHOW_CONF_TX_PAGE: 'SHOW_CONF_TX_PAGE', SHOW_CONF_MSG_PAGE: 'SHOW_CONF_MSG_PAGE', SET_CURRENT_FIAT: 'SET_CURRENT_FIAT', - setCurrentCurrency: setCurrentCurrency, + showQrScanner, + setCurrentCurrency, setCurrentAccountTab, // account detail screen SHOW_SEND_PAGE: 'SHOW_SEND_PAGE', @@ -723,6 +727,28 @@ function showInfoPage () { } } +function showQrScanner (ROUTE) { + return (dispatch, getState) => { + return WebcamUtils.checkStatus() + .then(status => { + if (!status.environmentReady) { + // We need to switch to fullscreen mode to ask for permission + global.platform.openExtensionInBrowser(`${ROUTE}`, `scan=true`) + } else { + dispatch(actions.showModal({ + name: 'QR_SCANNER', + })) + } + }).catch(e => { + dispatch(actions.showModal({ + name: 'QR_SCANNER', + error: true, + errorType: e.type, + })) + }) + } +} + function setCurrentCurrency (currencyCode) { return (dispatch) => { dispatch(actions.showLoadingIndication()) @@ -1809,6 +1835,17 @@ function hideAlert () { } } +/** + * This action will receive two types of values via qrCodeData + * an object with the following structure {type, values} + * or null (used to clear the previous value) + */ +function qrCodeDetected (qrCodeData) { + return { + type: actions.QR_CODE_DETECTED, + value: qrCodeData, + } +} function showLoadingIndication (message) { return { |