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

Fix incorrectly showing checksums on non-ETH blockchains #5973

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [#5932](https://github.com/MetaMask/metamask-extension/pull/5932): Fix displayed time and date in the activity log. Remove vreme library, add luxon library.
- [#5924](https://github.com/MetaMask/metamask-extension/pull/5924): transactions - throw an error if a transaction is generated while the network is loading
- [#5893](https://github.com/MetaMask/metamask-extension/pull/5893): Add loading network screen
- [#5973] (https://github.com/MetaMask/metamask-extension/pull/5973): Fix incorrectly showing checksums on non-ETH blockchains (issue 5838)

## 5.2.2 Wed Dec 12 2018

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/beta/run-drizzle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ fi
! kill -15 $npm_run_ganache_start_pid
! kill -15 $npm_start_pid
! wait $npm_run_ganache_start_pid $npm_start_pid
exit ${test_status:-}
exit ${test_status:-}
1 change: 1 addition & 0 deletions ui/app/components/modals/account-details-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ AccountDetailsModal.prototype.render = function () {
h(QrView, {
Qr: {
data: address,
network: network,
},
}),

Expand Down
8 changes: 5 additions & 3 deletions ui/app/components/qr-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { checksumAddress } = require('../util')
module.exports = connect(mapStateToProps)(QrCodeView)

function mapStateToProps (state) {

return {
// Qr code is not fetched from state. 'message' and 'data' props are passed instead.
buyView: state.appState.buyView,
Expand All @@ -25,9 +26,10 @@ 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()

Expand All @@ -51,7 +53,7 @@ QrCodeView.prototype.render = function () {
h(ReadOnlyInput, {
wrapperClass: 'ellip-address-wrapper',
inputClass: 'qr-ellip-address',
value: checksumAddress(data),
value: checksumAddress(data, network),
}),
])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const mapStateToProps = state => {
return {
selectedAddress: selectors.getSelectedAddress(state),
selectedIdentity: selectors.getSelectedIdentity(state),
network: state.metamask.network,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import SendRowWrapper from '../send-row-wrapper/'
import EnsInput from '../../../ens-input'
import { getToErrorObject } from './send-to-row.utils.js'
import { checksumAddress } from '../../../../util'

export default class SendToRow extends Component {

Expand All @@ -25,7 +26,8 @@ export default class SendToRow extends Component {
t: PropTypes.func,
}

handleToChange (to, nickname = '', toError) {
handleToChange (to, nickname = '', toError, network) {
to = checksumAddress(to, network)
const { hasHexData, updateSendTo, updateSendToError, updateGas } = this.props
const toErrorObject = getToErrorObject(to, toError, hasHexData)
updateSendTo(to, nickname)
Expand Down Expand Up @@ -60,7 +62,7 @@ export default class SendToRow extends Component {
inError={inError}
name={'address'}
network={network}
onChange={({ toAddress, nickname, toError }) => this.handleToChange(toAddress, nickname, toError)}
onChange={({ toAddress, nickname, toError }) => this.handleToChange(toAddress, nickname, toError, this.props.network)}
openDropdown={() => openToDropdown()}
placeholder={this.context.t('recipientAddress')}
to={to}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('SendToRow Component', function () {
assert.equal(SendToRow.prototype.handleToChange.callCount, 1)
assert.deepEqual(
SendToRow.prototype.handleToChange.getCall(0).args,
['mockNewTo', 'mockNewNickname', 'mockToError']
['mockNewTo', 'mockNewNickname', 'mockToError', 'mockNetwork' ]
)
})
})
Expand Down
4 changes: 2 additions & 2 deletions ui/app/components/wallet-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ 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))
Expand Down
17 changes: 15 additions & 2 deletions ui/app/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ module.exports = {
getTokenAddressFromTokenObject,
checksumAddress,
addressSlicer,
isEthNetwork,
}

function isEthNetwork (netId) {
if (!netId) return false

if (netId === '1' || netId === '3' || netId === '4' || netId === '42') {
return true
}

return false
}

function valuesFor (obj) {
Expand Down Expand Up @@ -299,10 +310,12 @@ 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 = '') {
Expand Down