1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

added qr code scanner icon in send transaction

This commit is contained in:
brunobar79 2018-07-23 22:10:57 -04:00
parent f7ad978474
commit d5929e5c42
10 changed files with 29 additions and 20 deletions

View File

@ -205,7 +205,7 @@ function initQrCodeScanner () {
// Append preview div // Append preview div
const preview = document.createElement('div') const preview = document.createElement('div')
preview.id = 'metamask-preview-wrapper' preview.id = 'metamask-preview-wrapper'
preview.style = 'position:absolute; top: 20px; left: 20px; width: 300px; height: 300px; overflow: hidden; z-index: 999999999;' preview.style = 'position:fixed; top: 20px; left: 20px; width: 300px; height: 300px; overflow: hidden; z-index: 999999999;'
const previewVideo = document.createElement('video') const previewVideo = document.createElement('video')
previewVideo.id = 'metamask-preview-video' previewVideo.id = 'metamask-preview-video'
previewVideo.style = 'width: 100%; height: 100%; object-fit: none; margin-left: -10%; margin-top: 10%;' previewVideo.style = 'width: 100%; height: 100%; object-fit: none; margin-left: -10%; margin-top: 10%;'
@ -218,14 +218,11 @@ function initQrCodeScanner () {
continuous: true, continuous: true,
}) })
scanner.addListener('scan', function (content) { scanner.addListener('scan', function (content) {
console.log('QR-SCANNER: got code (IN-PAGE)', content)
scanner.stop().then(_ => { scanner.stop().then(_ => {
console.log('QR-SCANNER: stopped scanner and sending msg (IN-PAGE)', content)
extension.runtime.sendMessage({ extension.runtime.sendMessage({
action: 'qr-code-scanner-data', action: 'qr-code-scanner-data',
data: content, data: content,
}) })
console.log('QR-SCANNER: message sent (IN-PAGE)', content)
document.getElementById('metamask-preview-wrapper').parentElement.removeChild(document.getElementById('metamask-preview-wrapper')) document.getElementById('metamask-preview-wrapper').parentElement.removeChild(document.getElementById('metamask-preview-wrapper'))
}) })
}) })
@ -241,8 +238,6 @@ function initQrCodeScanner () {
} }
extension.runtime.onMessage.addListener(({ action }) => { extension.runtime.onMessage.addListener(({ action }) => {
console.log('QR-SCANNER: message received (IN-PAGE)', action)
initQrCodeScanner() initQrCodeScanner()
}) })
console.log('QR-SCANNER: now listening (IN-PAGE)')

View File

@ -660,20 +660,15 @@ module.exports = class MetamaskController extends EventEmitter {
scanQrCode () { scanQrCode () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log('QR-SCANNER: intializing QR code scanner feature (MM controller)')
// Tell contentscript to inject the QR reader // Tell contentscript to inject the QR reader
this.platform.sendMessage('qr-code-scanner-init') this.platform.sendMessageToActiveTab('qr-code-scanner-init')
console.log('QR-SCANNER: message to initialize has been sent (MM controller)')
// Wait for the scanner to send something back // Wait for the scanner to send something back
this.platform.addMessageListener(({ action, data }) => { this.platform.addMessageListener(({ action, data }) => {
console.log('QR-SCANNER: message received (MM controller)', action, data)
if (action && action === 'qr-code-scanner-data') { if (action && action === 'qr-code-scanner-data') {
const normalizedAddress = data.replace('ethereum:', '') const normalizedAddress = data.replace('ethereum:', '')
console.log('QR-SCANNER: resolving promise!', normalizedAddress) resolve(normalizedAddress)
return Promise.resolve(normalizedAddress)
} }
}) })
console.log('QR-SCANNER: now listening (MM controller)')
}) })
} }

View File

@ -36,11 +36,10 @@ class ExtensionPlatform {
extension.runtime.onMessage.addListener(cb) extension.runtime.onMessage.addListener(cb)
} }
sendMessage (message, query = {}) { sendMessageToActiveTab (message, query = {}) {
extension.tabs.query(query, tabs => { extension.tabs.query(query, tabs => {
const activeTab = tabs.filter(tab => tab.active)[0] const activeTab = tabs.filter(tab => tab.active)[0]
extension.tabs.sendMessage(activeTab.id, message) extension.tabs.sendMessage(activeTab.id, message)
console.log('QR-SCANNER: message sent to tab', message, activeTab)
}) })
} }
} }

View File

@ -54,6 +54,7 @@ EnsInput.prototype.render = function () {
const opts = extend(props, { const opts = extend(props, {
list: 'addresses', list: 'addresses',
onChange: this.onChange.bind(this), onChange: this.onChange.bind(this),
qrScanner: true,
}) })
return h('div', { return h('div', {
style: { width: '100%', position: 'relative' }, style: { width: '100%', position: 'relative' },

View File

@ -19,8 +19,10 @@ export default class SendContent extends Component {
<PageContainerContent> <PageContainerContent>
<div className="send-v2__form"> <div className="send-v2__form">
<SendFromRow /> <SendFromRow />
<SendToRow updateGas={(updateData) => this.props.updateGas(updateData)} /> <SendToRow
<button onClick={_ => this.props.scanQrCode() }>or scan a QR code</button> updateGas={(updateData) => this.props.updateGas(updateData)}
scanQrCode={ _ => this.props.scanQrCode()}
/>
<SendAmountRow updateGas={(updateData) => this.props.updateGas(updateData)} /> <SendAmountRow updateGas={(updateData) => this.props.updateGas(updateData)} />
<SendGasRow /> <SendGasRow />
<SendHexDataRow /> <SendHexDataRow />

View File

@ -51,6 +51,7 @@ export default class SendToRow extends Component {
showError={inError} showError={inError}
> >
<EnsInput <EnsInput
scanQrCode={_ => this.props.scanQrCode()}
accounts={toAccounts} accounts={toAccounts}
closeDropdown={() => closeToDropdown()} closeDropdown={() => closeToDropdown()}
dropdownOpen={toDropdownOpen} dropdownOpen={toDropdownOpen}

View File

@ -47,7 +47,7 @@ export default class SendTransactionScreen extends PersistentForm {
scanQrCode = async () => { scanQrCode = async () => {
const scannedAddress = await this.props.scanQrCode() const scannedAddress = await this.props.scanQrCode()
console.log('QR-SCANNER: Got address (UI)', scannedAddress) this.props.updateSendTo(scannedAddress)
this.updateGas({ to: scannedAddress }) this.updateGas({ to: scannedAddress })
} }

View File

@ -23,6 +23,7 @@ import {
getTokenBalance, getTokenBalance,
} from './send.selectors' } from './send.selectors'
import { import {
updateSendTo,
updateSendTokenBalance, updateSendTokenBalance,
updateGasData, updateGasData,
setGasTotal, setGasTotal,
@ -91,5 +92,6 @@ function mapDispatchToProps (dispatch) {
updateSendErrors: newError => dispatch(updateSendErrors(newError)), updateSendErrors: newError => dispatch(updateSendErrors(newError)),
resetSendState: () => dispatch(resetSendState()), resetSendState: () => dispatch(resetSendState()),
scanQrCode: () => dispatch(scanQrCode()), scanQrCode: () => dispatch(scanQrCode()),
updateSendTo: (to, nickname) => dispatch(updateSendTo(to, nickname)),
} }
} }

View File

@ -94,11 +94,12 @@ ToAutoComplete.prototype.render = function () {
dropdownOpen, dropdownOpen,
onChange, onChange,
inError, inError,
qrScanner,
} = this.props } = this.props
return h('div.send-v2__to-autocomplete', {}, [ return h('div.send-v2__to-autocomplete', {}, [
h('input.send-v2__to-autocomplete__input', { h(`input.send-v2__to-autocomplete__input${qrScanner?'.with-qr':''}`, {
placeholder: this.context.t('recipientAddress'), placeholder: this.context.t('recipientAddress'),
className: inError ? `send-v2__error-border` : '', className: inError ? `send-v2__error-border` : '',
value: to, value: to,
@ -108,7 +109,10 @@ ToAutoComplete.prototype.render = function () {
borderColor: inError ? 'red' : null, borderColor: inError ? 'red' : null,
}, },
}), }),
qrScanner && h(`i.fa.fa-qrcode.fa-lg.send-v2__to-autocomplete__qr-code`, {
style: { color: '#33333' },
onClick: () => this.props.scanQrCode(),
}),
!to && h(`i.fa.fa-caret-down.fa-lg.send-v2__to-autocomplete__down-caret`, { !to && h(`i.fa.fa-caret-down.fa-lg.send-v2__to-autocomplete__down-caret`, {
style: { color: '#dedede' }, style: { color: '#dedede' },
onClick: () => this.handleInputEvent(), onClick: () => this.handleInputEvent(),

View File

@ -626,6 +626,16 @@
top: 18px; top: 18px;
right: 12px; right: 12px;
} }
&__qr-code {
position: absolute;
top: 21px;
left: 13px;
}
&__input.with-qr {
padding-left: 40px;
}
} }
&__to-autocomplete, &__memo-text-area, &__hex-data { &__to-autocomplete, &__memo-text-area, &__hex-data {