From 8dddf48904323d47685516ccc76f9e267dbd188a Mon Sep 17 00:00:00 2001
From: Jonathan Smirnoff <7558841+jonathansmirnoff@users.noreply.github.com>
Date: Wed, 13 Feb 2019 17:30:46 -0300
Subject: Fixed issue #5838 (#6001)
Update changelog file
---
ui/app/components/modals/account-details-modal.js | 1 +
ui/app/components/qr-code.js | 6 +++---
.../selected-account/selected-account.component.js | 5 +++--
.../selected-account/selected-account.container.js | 1 +
.../send-content/send-to-row/send-to-row.component.js | 6 +++---
.../send-content/send-to-row/send-to-row.utils.js | 9 +++++----
.../send-to-row/tests/send-to-row-component.test.js | 2 +-
ui/app/components/send/send.constants.js | 2 ++
ui/app/components/wallet-view.js | 3 ++-
ui/app/util.js | 19 ++++++++++++++++---
10 files changed, 37 insertions(+), 17 deletions(-)
(limited to 'ui')
diff --git a/ui/app/components/modals/account-details-modal.js b/ui/app/components/modals/account-details-modal.js
index 248ffe008..67d8eb0fd 100644
--- a/ui/app/components/modals/account-details-modal.js
+++ b/ui/app/components/modals/account-details-modal.js
@@ -77,6 +77,7 @@ AccountDetailsModal.prototype.render = function () {
h(QrView, {
Qr: {
data: address,
+ network: network,
},
}),
diff --git a/ui/app/components/qr-code.js b/ui/app/components/qr-code.js
index d3242ddf5..1c07e244c 100644
--- a/ui/app/components/qr-code.js
+++ b/ui/app/components/qr-code.js
@@ -25,8 +25,8 @@ function QrCodeView () {
QrCodeView.prototype.render = function () {
const props = this.props
- const { message, data } = props.Qr
- const address = `${isHexPrefixed(data) ? 'ethereum:' : ''}${checksumAddress(data)}`
+ const { message, data, network } = props.Qr
+ const address = `${isHexPrefixed(data) ? 'ethereum:' : ''}${checksumAddress(data, network)}`
const qrImage = qrCode(4, 'M')
qrImage.addData(address)
qrImage.make()
@@ -51,7 +51,7 @@ QrCodeView.prototype.render = function () {
h(ReadOnlyInput, {
wrapperClass: 'ellip-address-wrapper',
inputClass: 'qr-ellip-address',
- value: checksumAddress(data),
+ value: checksumAddress(data, network),
}),
])
}
diff --git a/ui/app/components/selected-account/selected-account.component.js b/ui/app/components/selected-account/selected-account.component.js
index 4f98df9b6..47c56e312 100644
--- a/ui/app/components/selected-account/selected-account.component.js
+++ b/ui/app/components/selected-account/selected-account.component.js
@@ -17,12 +17,13 @@ class SelectedAccount extends Component {
static propTypes = {
selectedAddress: PropTypes.string,
selectedIdentity: PropTypes.object,
+ network: PropTypes.string,
}
render () {
const { t } = this.context
- const { selectedAddress, selectedIdentity } = this.props
- const checksummedAddress = checksumAddress(selectedAddress)
+ const { selectedAddress, selectedIdentity, network } = this.props
+ const checksummedAddress = checksumAddress(selectedAddress, network)
return (
diff --git a/ui/app/components/selected-account/selected-account.container.js b/ui/app/components/selected-account/selected-account.container.js
index f9e061d15..1c8d17d8d 100644
--- a/ui/app/components/selected-account/selected-account.container.js
+++ b/ui/app/components/selected-account/selected-account.container.js
@@ -7,6 +7,7 @@ const mapStateToProps = state => {
return {
selectedAddress: selectors.getSelectedAddress(state),
selectedIdentity: selectors.getSelectedIdentity(state),
+ network: state.metamask.network,
}
}
diff --git a/ui/app/components/send/send-content/send-to-row/send-to-row.component.js b/ui/app/components/send/send-content/send-to-row/send-to-row.component.js
index 0f26dd55c..3fbf9a76b 100644
--- a/ui/app/components/send/send-content/send-to-row/send-to-row.component.js
+++ b/ui/app/components/send/send-content/send-to-row/send-to-row.component.js
@@ -29,9 +29,9 @@ export default class SendToRow extends Component {
t: PropTypes.func,
}
- handleToChange (to, nickname = '', toError, toWarning) {
+ handleToChange (to, nickname = '', toError, toWarning, network) {
const { hasHexData, updateSendTo, updateSendToError, updateGas, tokens, selectedToken, updateSendToWarning } = this.props
- const toErrorObject = getToErrorObject(to, toError, hasHexData)
+ const toErrorObject = getToErrorObject(to, toError, hasHexData, tokens, selectedToken, network)
const toWarningObject = getToWarningObject(to, toWarning, tokens, selectedToken)
updateSendTo(to, nickname)
updateSendToError(toErrorObject)
@@ -69,7 +69,7 @@ export default class SendToRow extends Component {
inError={inError}
name={'address'}
network={network}
- onChange={({ toAddress, nickname, toError, toWarning }) => this.handleToChange(toAddress, nickname, toError, toWarning)}
+ onChange={({ toAddress, nickname, toError, toWarning }) => this.handleToChange(toAddress, nickname, toError, toWarning, this.props.network)}
openDropdown={() => openToDropdown()}
placeholder={this.context.t('recipientAddress')}
to={to}
diff --git a/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js b/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js
index 4a8add42e..2bd3ea45e 100644
--- a/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js
+++ b/ui/app/components/send/send-content/send-to-row/send-to-row.utils.js
@@ -2,20 +2,21 @@ const {
REQUIRED_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
KNOWN_RECIPIENT_ADDRESS_ERROR,
+ INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
} = require('../../send.constants')
-const { isValidAddress } = require('../../../../util')
+const { isValidAddress, isEthNetwork } = require('../../../../util')
import { checkExistingAddresses } from '../../../pages/add-token/util'
const ethUtil = require('ethereumjs-util')
const contractMap = require('eth-contract-metadata')
-function getToErrorObject (to, toError = null, hasHexData = false, tokens = [], selectedToken = null) {
+function getToErrorObject (to, toError = null, hasHexData = false, tokens = [], selectedToken = null, network) {
if (!to) {
if (!hasHexData) {
toError = REQUIRED_ERROR
}
- } else if (!isValidAddress(to) && !toError) {
- toError = INVALID_RECIPIENT_ADDRESS_ERROR
+ } else if (!isValidAddress(to, network) && !toError) {
+ toError = isEthNetwork(network) ? INVALID_RECIPIENT_ADDRESS_ERROR : INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR
} else if (selectedToken && (ethUtil.toChecksumAddress(to) in contractMap || checkExistingAddresses(to, tokens))) {
toError = KNOWN_RECIPIENT_ADDRESS_ERROR
}
diff --git a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-component.test.js b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-component.test.js
index d3732307f..d4d054057 100644
--- a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-component.test.js
+++ b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-component.test.js
@@ -159,7 +159,7 @@ describe('SendToRow Component', function () {
assert.equal(SendToRow.prototype.handleToChange.callCount, 1)
assert.deepEqual(
SendToRow.prototype.handleToChange.getCall(0).args,
- ['mockNewTo', 'mockNewNickname', 'mockToError', 'mockToWarning']
+ ['mockNewTo', 'mockNewNickname', 'mockToError', 'mockToWarning', 'mockNetwork' ]
)
})
})
diff --git a/ui/app/components/send/send.constants.js b/ui/app/components/send/send.constants.js
index e79734a54..490bc6fd2 100644
--- a/ui/app/components/send/send.constants.js
+++ b/ui/app/components/send/send.constants.js
@@ -26,6 +26,7 @@ const INSUFFICIENT_FUNDS_ERROR = 'insufficientFunds'
const INSUFFICIENT_TOKENS_ERROR = 'insufficientTokens'
const NEGATIVE_ETH_ERROR = 'negativeETH'
const INVALID_RECIPIENT_ADDRESS_ERROR = 'invalidAddressRecipient'
+const INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR = 'invalidAddressRecipientNotEthNetwork'
const REQUIRED_ERROR = 'required'
const KNOWN_RECIPIENT_ADDRESS_ERROR = 'knownAddressRecipient'
@@ -44,6 +45,7 @@ module.exports = {
INSUFFICIENT_TOKENS_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
KNOWN_RECIPIENT_ADDRESS_ERROR,
+ INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
MIN_GAS_LIMIT_DEC,
MIN_GAS_LIMIT_HEX,
MIN_GAS_PRICE_DEC,
diff --git a/ui/app/components/wallet-view.js b/ui/app/components/wallet-view.js
index 6732010a3..4566cb390 100644
--- a/ui/app/components/wallet-view.js
+++ b/ui/app/components/wallet-view.js
@@ -125,10 +125,11 @@ WalletView.prototype.render = function () {
showAccountDetailModal,
hideSidebar,
identities,
+ network,
} = this.props
// temporary logs + fake extra wallets
- const checksummedAddress = checksumAddress(selectedAddress)
+ const checksummedAddress = checksumAddress(selectedAddress, network)
if (!selectedAddress) {
throw new Error('selectedAddress should not be ' + String(selectedAddress))
diff --git a/ui/app/util.js b/ui/app/util.js
index 31757e7c3..e27956a45 100644
--- a/ui/app/util.js
+++ b/ui/app/util.js
@@ -60,6 +60,15 @@ module.exports = {
getTokenAddressFromTokenObject,
checksumAddress,
addressSlicer,
+ isEthNetwork,
+}
+
+function isEthNetwork (netId) {
+ if (!netId || netId === '1' || netId === '3' || netId === '4' || netId === '42' || netId === '5777') {
+ return true
+ }
+
+ return false
}
function valuesFor (obj) {
@@ -83,9 +92,10 @@ function miniAddressSummary (address) {
return checked ? checked.slice(0, 4) + '...' + checked.slice(-4) : '...'
}
-function isValidAddress (address) {
+function isValidAddress (address, network) {
var prefixed = ethUtil.addHexPrefix(address)
if (address === '0x0000000000000000000000000000000000000000') return false
+ if (!isEthNetwork(network)) return (ethUtil.isValidAddress(prefixed) && address === address.toLowerCase())
return (isAllOneCase(prefixed) && ethUtil.isValidAddress(prefixed)) || ethUtil.isValidChecksumAddress(prefixed)
}
@@ -299,10 +309,13 @@ function getTokenAddressFromTokenObject (token) {
* Safely checksumms a potentially-null address
*
* @param {String} [address] - address to checksum
+ * @param {String} [network] - network id
* @returns {String} - checksummed address
+ *
*/
-function checksumAddress (address) {
- return address ? ethUtil.toChecksumAddress(address) : ''
+function checksumAddress (address, network) {
+ const checksummed = address ? ethUtil.toChecksumAddress(address) : ''
+ return checksummed && network && !isEthNetwork(network) ? checksummed.toLowerCase() : checksummed
}
function addressSlicer (address = '') {
--
cgit v1.2.3