diff options
author | Jonathan Smirnoff <7558841+jonathansmirnoff@users.noreply.github.com> | 2019-02-14 04:30:46 +0800 |
---|---|---|
committer | Frankie <frankie.diamond@gmail.com> | 2019-02-14 04:30:46 +0800 |
commit | 8dddf48904323d47685516ccc76f9e267dbd188a (patch) | |
tree | 3e1c11920da2be888271e4bc48d8dce61e64b944 | |
parent | f7ab4577f637dd9e96cec0f08848bc70c489f9d3 (diff) | |
download | tangerine-wallet-browser-8dddf48904323d47685516ccc76f9e267dbd188a.tar tangerine-wallet-browser-8dddf48904323d47685516ccc76f9e267dbd188a.tar.gz tangerine-wallet-browser-8dddf48904323d47685516ccc76f9e267dbd188a.tar.bz2 tangerine-wallet-browser-8dddf48904323d47685516ccc76f9e267dbd188a.tar.lz tangerine-wallet-browser-8dddf48904323d47685516ccc76f9e267dbd188a.tar.xz tangerine-wallet-browser-8dddf48904323d47685516ccc76f9e267dbd188a.tar.zst tangerine-wallet-browser-8dddf48904323d47685516ccc76f9e267dbd188a.zip |
Fixed issue #5838 (#6001)
Update changelog file
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | app/_locales/en/messages.json | 3 | ||||
-rw-r--r-- | app/_locales/es/messages.json | 3 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | ui/app/components/modals/account-details-modal.js | 1 | ||||
-rw-r--r-- | ui/app/components/qr-code.js | 6 | ||||
-rw-r--r-- | ui/app/components/selected-account/selected-account.component.js | 5 | ||||
-rw-r--r-- | ui/app/components/selected-account/selected-account.container.js | 1 | ||||
-rw-r--r-- | ui/app/components/send/send-content/send-to-row/send-to-row.component.js | 6 | ||||
-rw-r--r-- | ui/app/components/send/send-content/send-to-row/send-to-row.utils.js | 9 | ||||
-rw-r--r-- | ui/app/components/send/send-content/send-to-row/tests/send-to-row-component.test.js | 2 | ||||
-rw-r--r-- | ui/app/components/send/send.constants.js | 2 | ||||
-rw-r--r-- | ui/app/components/wallet-view.js | 3 | ||||
-rw-r--r-- | ui/app/util.js | 19 |
14 files changed, 46 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a5b6c05fd..c8fb53cd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Develop Branch +-[#5973] (https://github.com/MetaMask/metamask-extension/pull/5973): Fix incorrectly showing checksums on non-ETH blockchains (issue 5838) + ## 6.0.1 Tue Feb 12 2019 - [#6139](https://github.com/MetaMask/metamask-extension/pull/6139) Fix advanced gas controls on the confirm screen diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 2ace2c2a8..662ab8548 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -678,6 +678,9 @@ "knownAddressRecipient": { "message": "Known contract address." }, + "invalidAddressRecipientNotEthNetwork": { + "message": "Not ETH network, set to lowercase" + }, "invalidGasParams": { "message": "Invalid Gas Parameters" }, diff --git a/app/_locales/es/messages.json b/app/_locales/es/messages.json index 15910c871..04e0c9f05 100644 --- a/app/_locales/es/messages.json +++ b/app/_locales/es/messages.json @@ -453,6 +453,9 @@ "invalidAddressRecipient": { "message": "Dirección del destinatario invalida" }, + "invalidAddressRecipientNotEthNetwork": { + "message": "No es una red ETH, convertirlo a minúscula" + }, "invalidGasParams": { "message": "Parametros de gas inválidos" }, diff --git a/package.json b/package.json index a2c308979..02dc3278c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "test:mascara:build:locales": "mkdirp dist/chrome && cp -R app/_locales dist/chrome/_locales", "test:mascara:build:background": "browserify mascara/src/background.js -o dist/mascara/background.js", "test:mascara:build:tests": "browserify test/integration/lib/first-time.js -o dist/mascara/tests.js", - "ganache:start": "ganache-cli --noVMErrorsOnRPCResponse -m 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent'", + "ganache:start": "ganache-cli --noVMErrorsOnRPCResponse -i 5777 -m 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent'", "sentry:publish": "node ./development/sentry-publish.js", "lint": "eslint .", "lint:fix": "eslint . --fix", 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 ( <div className="selected-account"> 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 = '') { |