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

View File

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

View File

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

View File

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