Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QR Code Scanner #4897

Merged
merged 39 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2e50348
added instascan pkg
brunobar79 Jul 23, 2018
0940ecd
added camera snippet injection to inpage.js
brunobar79 Jul 23, 2018
0209148
fixes
brunobar79 Jul 23, 2018
f7ad978
camera working back and forth
brunobar79 Jul 24, 2018
d5929e5
added qr code scanner icon in send transaction
brunobar79 Jul 24, 2018
74fd6d1
working without injection
brunobar79 Jul 25, 2018
eeb902d
decent UI
brunobar79 Jul 25, 2018
4759915
fix spinner and qr icon
brunobar79 Jul 25, 2018
6cd4bc9
working without permission issues
brunobar79 Jul 27, 2018
ea028e7
fully working without tweaking ext. permission
brunobar79 Jul 27, 2018
d4a15f2
added webrtc-adapter for browser compat
brunobar79 Jul 27, 2018
69f4c8c
fix merge conflicts
brunobar79 Jul 27, 2018
d65d018
restore platform/extension.js
brunobar79 Jul 27, 2018
bea1cf3
clean up
brunobar79 Jul 27, 2018
6886429
fix linting errors
brunobar79 Jul 27, 2018
4de8f5b
fix dependencies
brunobar79 Jul 27, 2018
acfcdf5
fix unit tests
brunobar79 Jul 27, 2018
b6592ba
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
brunobar79 Jul 30, 2018
4339f04
use existing modals
brunobar79 Jul 30, 2018
d2368d6
clean up css
brunobar79 Jul 30, 2018
34617a2
copy
brunobar79 Jul 30, 2018
b673a7a
kill camera stream when unmouting
brunobar79 Jul 30, 2018
edb1547
send to fullscreen if no permission from popup
brunobar79 Jul 31, 2018
710b4e2
added crossbrowser support and error handling
brunobar79 Jul 31, 2018
caa9e20
lint
brunobar79 Jul 31, 2018
7a40072
lint
brunobar79 Jul 31, 2018
94a8979
fix
brunobar79 Jul 31, 2018
71ef4d8
design complete
brunobar79 Aug 3, 2018
af97ba1
clear qr code data before scanning
brunobar79 Aug 3, 2018
e9a0feb
fixed issue with input
brunobar79 Aug 4, 2018
b1ddaaf
lint
brunobar79 Aug 4, 2018
ef9435e
restore qr
brunobar79 Aug 4, 2018
2e0916d
fix merge conflicts
brunobar79 Aug 8, 2018
c6b7e46
code review changes
brunobar79 Aug 8, 2018
a46cf39
update package-lock.json
brunobar79 Aug 8, 2018
cbbd0d3
lint
brunobar79 Aug 8, 2018
f269021
add submit button type
brunobar79 Aug 8, 2018
656afee
fix merge conflicts
brunobar79 Aug 8, 2018
d0ccc59
add comment
brunobar79 Aug 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"accept": {
"message": "Accept"
},
"accessingYourCamera": {
"message": "Accesing your camera..."
},
"account": {
"message": "Account"
},
Expand Down Expand Up @@ -653,6 +656,12 @@
"notStarted": {
"message": "Not Started"
},
"noWebcamFoundTitle": {
"message": "Webcam not found"
},
"noWebcamFound": {
"message": "Your computer's webcam was not found. Please try again."
},
"oldUI": {
"message": "Old UI"
},
Expand Down Expand Up @@ -937,6 +946,12 @@
"info": {
"message": "Info"
},
"scanInstructions": {
"message": "Place the QR code in front of your camera"
},
"scanQrCode": {
"message": "Scan QR Code"
},
"shapeshiftBuy": {
"message": "Buy with Shapeshift"
},
Expand Down Expand Up @@ -1086,6 +1101,15 @@
"unknownNetworkId": {
"message": "Unknown network ID"
},
"unknownQrCode": {
"message": "Error: We couldn't identify that QR code"
},
"unknownCameraErrorTitle": {
"message": "Ooops! Something went wrong...."
},
"unknownCameraError": {
"message": "There was an error while trying to access you camera. Please try again..."
},
"unlock": {
"message": "Unlock"
},
Expand Down Expand Up @@ -1132,6 +1156,9 @@
"whatsThis": {
"message": "What's this?"
},
"youNeedToAllowCameraAccess": {
"message": "You need to allow camera access to use this feature."
},
"yourSigRequested": {
"message": "Your signature is being requested"
},
Expand Down
18 changes: 18 additions & 0 deletions app/images/webcam.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ function blacklistedDomainCheck () {
*/
function redirectToPhishingWarning () {
console.log('MetaMask - routing to Phishing Warning component')
let extensionURL = extension.runtime.getURL('phishing.html')
const extensionURL = extension.runtime.getURL('phishing.html')
window.location.href = extensionURL
}
7 changes: 6 additions & 1 deletion app/scripts/platforms/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ class ExtensionPlatform {
return extension.runtime.getManifest().version
}

openExtensionInBrowser (route = null) {
openExtensionInBrowser (route = null, queryString = null) {
let extensionURL = extension.runtime.getURL('home.html')

if (queryString) {
extensionURL += `?${queryString}`
}

if (route) {
extensionURL += `#${route}`
}
Expand Down
2 changes: 1 addition & 1 deletion old-ui/app/components/transaction-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TransactionListItem.prototype.showRetryButton = function () {
const currentNonce = txParams.nonce
const currentNonceTxs = transactions.filter(tx => tx.txParams.nonce === currentNonce)
const currentNonceSubmittedTxs = currentNonceTxs.filter(tx => tx.status === 'submitted')
const currentSubmittedTxs = transactions.filter(tx => tx.status === 'submitted')
const currentSubmittedTxs = transactions.filter(tx => tx.status === 'submitted')
const lastSubmittedTxWithCurrentNonce = currentNonceSubmittedTxs[0]
const currentTxIsLatestWithNonce = lastSubmittedTxWithCurrentNonce &&
lastSubmittedTxWithCurrentNonce.id === transaction.id
Expand Down
47 changes: 44 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
},
"dependencies": {
"@material-ui/core": "^1.0.0",
"@zxing/library": "^0.7.0",
"abi-decoder": "^1.0.9",
"asmcrypto.js": "0.22.0",
"async": "^2.5.0",
Expand All @@ -97,6 +98,7 @@
"debounce-stream": "^2.0.0",
"deep-extend": "^0.5.1",
"detect-node": "^2.0.3",
"detectrtc": "^1.3.6",
"disc": "^1.3.2",
"dnode": "^1.2.2",
"end-of-stream": "^1.1.0",
Expand Down Expand Up @@ -207,6 +209,7 @@
"web3": "^0.20.1",
"web3-provider-engine": "^14.0.5",
"web3-stream-provider": "^3.0.1",
"webrtc-adapter": "^6.3.0",
"xtend": "^4.0.1"
},
"devDependencies": {
Expand Down
34 changes: 33 additions & 1 deletion ui/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -721,6 +725,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())
Expand Down Expand Up @@ -1806,6 +1832,12 @@ function hideAlert () {
}
}

function qrCodeDetected (qrCodeData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty small, nit-picky request, but could you make it explicit what properties are in qrCodeData? In the absence of both tests and formal documentation for this file, make properties explicit makes the code a bit more self documenting. See, for example, the showQrView, updateSendTo or setCurrentCurrency functions in this file.

In this case I am thinking of some variation of:

function qrCodeDetected ({ type, values }) {
  return {
    type: actions.QR_CODE_DETECTED,
    value: { type, values },
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @danjm this is a good suggestion. The main reason why I can't do that it's because I have 2 types of values: {type, values} and also null.

I need to set it to null once the view handled the code. If you have any other suggestion / workaround for that I'm happy to do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option might be to add a docblock to the function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up following @whymarrh's suggestion. Thanks!

return {
type: actions.QR_CODE_DETECTED,
value: qrCodeData,
}
}

function showLoadingIndication (message) {
return {
Expand Down
2 changes: 2 additions & 0 deletions ui/app/components/ens-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function EnsInput () {
}

EnsInput.prototype.onChange = function (recipient) {

const network = this.props.network
const networkHasEnsSupport = getNetworkEnsSupport(network)

Expand Down Expand Up @@ -54,6 +55,7 @@ EnsInput.prototype.render = function () {
const opts = extend(props, {
list: 'addresses',
onChange: this.onChange.bind(this),
qrScanner: true,
})
return h('div', {
style: { width: '100%', position: 'relative' },
Expand Down
2 changes: 2 additions & 0 deletions ui/app/components/modals/index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import './customize-gas/index';

@import './qr-scanner/index';

.modal-container {
width: 100%;
height: 100%;
Expand Down
13 changes: 13 additions & 0 deletions ui/app/components/modals/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const CustomizeGasModal = require('../customize-gas-modal')
const NotifcationModal = require('./notification-modal')
const ConfirmResetAccount = require('./confirm-reset-account')
const ConfirmRemoveAccount = require('./confirm-remove-account')
const QRScanner = require('./qr-scanner')
const TransactionConfirmed = require('./transaction-confirmed')
const WelcomeBeta = require('./welcome-beta')
const Notification = require('./notification')
Expand Down Expand Up @@ -346,6 +347,18 @@ const MODALS = {
borderRadius: '8px',
},
},
QR_SCANNER: {
contents: h(QRScanner),
mobileModalStyle: {
...modalContainerMobileStyle,
},
laptopModalStyle: {
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
},
},

DEFAULT: {
contents: [],
Expand Down
2 changes: 2 additions & 0 deletions ui/app/components/modals/qr-scanner/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import QrScanner from './qr-scanner.container'
module.exports = QrScanner
Loading