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

Recipient not required on send screen when hex data present

This commit is contained in:
Whymarrh Whitby 2018-10-01 10:20:33 -02:30
parent c9f22916dd
commit ce2e068b43
5 changed files with 17 additions and 4 deletions

View File

@ -8,6 +8,7 @@ export default class SendToRow extends Component {
static propTypes = { static propTypes = {
closeToDropdown: PropTypes.func, closeToDropdown: PropTypes.func,
hasHexData: PropTypes.bool.isRequired,
inError: PropTypes.bool, inError: PropTypes.bool,
network: PropTypes.string, network: PropTypes.string,
openToDropdown: PropTypes.func, openToDropdown: PropTypes.func,
@ -25,8 +26,8 @@ export default class SendToRow extends Component {
}; };
handleToChange (to, nickname = '', toError) { handleToChange (to, nickname = '', toError) {
const { updateSendTo, updateSendToError, updateGas } = this.props const { hasHexData, updateSendTo, updateSendToError, updateGas } = this.props
const toErrorObject = getToErrorObject(to, toError) const toErrorObject = getToErrorObject(to, toError, hasHexData)
updateSendTo(to, nickname) updateSendTo(to, nickname)
updateSendToError(toErrorObject) updateSendToError(toErrorObject)
if (toErrorObject.to === null) { if (toErrorObject.to === null) {

View File

@ -3,6 +3,7 @@ import {
getCurrentNetwork, getCurrentNetwork,
getSendTo, getSendTo,
getSendToAccounts, getSendToAccounts,
getSendHexData,
} from '../../send.selectors.js' } from '../../send.selectors.js'
import { import {
getToDropdownOpen, getToDropdownOpen,
@ -22,6 +23,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(SendToRow)
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
hasHexData: Boolean(getSendHexData(state)),
inError: sendToIsInError(state), inError: sendToIsInError(state),
network: getCurrentNetwork(state), network: getCurrentNetwork(state),
to: getSendTo(state), to: getSendTo(state),

View File

@ -4,9 +4,11 @@ const {
} = require('../../send.constants') } = require('../../send.constants')
const { isValidAddress } = require('../../../../util') const { isValidAddress } = require('../../../../util')
function getToErrorObject (to, toError = null) { function getToErrorObject (to, toError = null, hasHexData = false) {
if (!to) { if (!to) {
toError = REQUIRED_ERROR if (!hasHexData) {
toError = REQUIRED_ERROR
}
} else if (!isValidAddress(to) && !toError) { } else if (!isValidAddress(to) && !toError) {
toError = INVALID_RECIPIENT_ADDRESS_ERROR toError = INVALID_RECIPIENT_ADDRESS_ERROR
} }

View File

@ -24,6 +24,7 @@ proxyquire('../send-to-row.container.js', {
}, },
'../../send.selectors.js': { '../../send.selectors.js': {
getCurrentNetwork: (s) => `mockNetwork:${s}`, getCurrentNetwork: (s) => `mockNetwork:${s}`,
getSendHexData: (s) => s,
getSendTo: (s) => `mockTo:${s}`, getSendTo: (s) => `mockTo:${s}`,
getSendToAccounts: (s) => `mockToAccounts:${s}`, getSendToAccounts: (s) => `mockToAccounts:${s}`,
}, },
@ -41,6 +42,7 @@ describe('send-to-row container', () => {
it('should map the correct properties to props', () => { it('should map the correct properties to props', () => {
assert.deepEqual(mapStateToProps('mockState'), { assert.deepEqual(mapStateToProps('mockState'), {
hasHexData: true,
inError: 'mockInError:mockState', inError: 'mockInError:mockState',
network: 'mockNetwork:mockState', network: 'mockNetwork:mockState',
to: 'mockTo:mockState', to: 'mockTo:mockState',

View File

@ -29,6 +29,12 @@ describe('send-to-row utils', () => {
}) })
}) })
it('should return null if to is falsy and hexData is truthy', () => {
assert.deepEqual(getToErrorObject(null, undefined, true), {
to: null,
})
})
it('should return an invalid recipient error if to is truthy but invalid', () => { it('should return an invalid recipient error if to is truthy but invalid', () => {
assert.deepEqual(getToErrorObject('mockInvalidTo'), { assert.deepEqual(getToErrorObject('mockInvalidTo'), {
to: INVALID_RECIPIENT_ADDRESS_ERROR, to: INVALID_RECIPIENT_ADDRESS_ERROR,