Skip to content

Commit

Permalink
Merge pull request #507 from blockchain/feature/qr-code
Browse files Browse the repository at this point in the history
validate addresses from qr
  • Loading branch information
schnogz committed Jun 7, 2018
2 parents ddd3e8b + a982972 commit 5040e38
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ const selectMessage = (message, data = undefined) => {
case C.YUBIKEY_VERIFY_ERROR: return <FormattedMessage id='components.alerts.yubikey_verify_error' defaultMessage='Failed to verify Yubikey' />
case C.YUBIKEY_VERIFY_SUCCESS: return <FormattedMessage id='components.alerts.yubikey_verify_success' defaultMessage='Yubikey verified' />
case C.CAPTCHA_CODE_INCORRECT: return <FormattedMessage id='components.alerts.captcha_code_incorrect' defaultMessage='The captcha you provided was incorrect, please try again' />
case C.BTC_ADDRESS_INVALID: return <FormattedMessage id='components.alerts.btc_address_incorrect' defaultMessage='Invalid Bitcoin Address.' />
case C.BCH_ADDRESS_INVALID: return <FormattedMessage id='components.alerts.bch_address_incorrect' defaultMessage='Invalid Bitcoin Cash Address.' />
case C.ETH_ADDRESS_INVALID: return <FormattedMessage id='components.alerts.eth_address_incorrect' defaultMessage='Invalid Ethereum Address.' />
case C.PRIVATE_KEY_INVALID: return <FormattedMessage id='components.alerts.private_key_incorrect' defaultMessage='Invalid Private Key.' />
default: return <FormattedMessage id='components.alerts.unknown_error' defaultMessage='An error has occurred.' />
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import bip21 from 'bip21'

import { actions } from 'data'
import QRCodeCapture from './template.js'
import * as C from 'services/AlertService'
import {utils} from 'blockchain-wallet-v4/src'

class QRCodeCaptureContainer extends React.PureComponent {
constructor (props) {
Expand All @@ -27,31 +29,51 @@ class QRCodeCaptureContainer extends React.PureComponent {
}

handleScanBtcAddress (data) {
const { address, options } = bip21.decode(data)
const { amount, message } = options
this.props.formActions.change('sendBtc', 'to', address)
this.props.formActions.change('sendBtc', 'amount', amount)
this.props.formActions.change('sendBtc', 'message', message)
this.props.updateUI({ btcAddress: { toggled: false } })
try {
const { address, options } = bip21.decode(data)
const { amount, message } = options
this.props.formActions.change('sendBtc', 'to', address)
this.props.formActions.change('sendBtc', 'amount', amount)
this.props.formActions.change('sendBtc', 'message', message)
this.props.updateUI({ btcAddress: { toggled: false } })
} catch (e) {
this.props.alertActions.displayError(C.BTC_ADDRESS_INVALID)
this.props.updateUI({ btcAddress: { toggled: false } })
}
}

handleScanBchAddress (data) {
const { address, options } = bip21.decode(data, 'bitcoincash')
const { amount, message } = options
this.props.formActions.change('sendBch', 'to', address)
this.props.formActions.change('sendBch', 'amount', amount)
this.props.formActions.change('sendBch', 'message', message)
this.props.updateUI({ bchAddress: { toggled: false } })
try {
const {address, options} = bip21.decode(data, 'bitcoincash')
const {amount, message} = options
this.props.formActions.change('sendBch', 'to', address)
this.props.formActions.change('sendBch', 'amount', amount)
this.props.formActions.change('sendBch', 'message', message)
this.props.updateUI({ bchAddress: { toggled: false } })
} catch (e) {
this.props.alertActions.displayError(C.BCH_ADDRESS_INVALID)
this.props.updateUI({ bchAddress: { toggled: false } })
}
}

handleScanEthAddress (data) {
this.props.formActions.change('sendEth', 'to', data)
this.props.updateUI({ ethAddress: { toggled: false } })
if (utils.ethereum.isValidAddress(data)) {
this.props.formActions.change('sendEth', 'to', data)
this.props.updateUI({ ethAddress: { toggled: false } })
} else {
this.props.alertActions.displayError(C.ETH_ADDRESS_INVALID)
this.props.updateUI({ ethAddress: { toggled: false } })
}
}

handleScanBtcPriv (data) {
this.props.formActions.change('sendBtc', 'priv', data)
this.props.updateUI({ btcPriv: { toggled: false } })
try {
this.props.formActions.change('sendBtc', 'priv', data)
this.props.updateUI({ btcPriv: { toggled: false } })
} catch (e) {
this.props.alertActions.displayError(C.PRIVATE_KEY_INVALID)
this.props.updateUI({ btcPriv: { toggled: false } })
}
}

handleScan (data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ export const YUBIKEY_VERIFY_SUCCESS = 'yubikey_verify_success'
export const UPDATE_ADDRESS_LABEL_SUCCESS = 'update_address_label_success'
export const UPDATE_ADDRESS_LABEL_ERROR = 'update_address_label_error'
export const CAPTCHA_CODE_INCORRECT = 'captcha_code_incorrect'
export const BTC_ADDRESS_INVALID = 'btc_address_invalid'
export const BCH_ADDRESS_INVALID = 'bch_address_invalid'
export const ETH_ADDRESS_INVALID = 'eth_address_invalid'
export const PRIVATE_KEY_INVALID = 'private_key_invalid'

0 comments on commit 5040e38

Please sign in to comment.