Send refactor: fix error handling and form disabling in send form.

feature/default_network_editable
Dan 7 years ago
parent 0de765aa25
commit e712336189
  1. 4
      ui/app/components/send_/send-footer/send-footer.component.js
  2. 4
      ui/app/components/send_/send-footer/send-footer.container.js
  3. 3
      ui/app/components/send_/send-footer/send-footer.selectors.js
  4. 6
      ui/app/components/send_/send-footer/tests/send-footer-component.test.js
  5. 3
      ui/app/components/send_/send-footer/tests/send-footer-container.test.js
  6. 24
      ui/app/components/send_/send-footer/tests/send-footer-selectors.test.js
  7. 6
      ui/app/components/send_/send.selectors.js
  8. 34
      ui/app/components/send_/tests/send-selectors.test.js

@ -77,9 +77,9 @@ export default class SendFooter extends Component {
}
formShouldBeDisabled () {
const { inError, selectedToken, tokenBalance, gasTotal } = this.props
const { inError, selectedToken, tokenBalance, gasTotal, to } = this.props
const missingTokenBalance = selectedToken && !tokenBalance
return inError || !gasTotal || missingTokenBalance
return inError || !gasTotal || missingTokenBalance || !to
}
render () {

@ -20,8 +20,10 @@ import {
getSendToAccounts,
getTokenBalance,
getUnapprovedTxs,
isSendFormInError,
} from '../send.selectors'
import {
isSendFormInError,
} from './send-footer.selectors'
import {
addressIsNew,
constructTxParams,

@ -7,6 +7,5 @@ const selectors = {
module.exports = selectors
function isSendFormInError (state) {
const { amount, to } = getSendErrors(state)
return Boolean(amount || to !== null)
return Object.values(getSendErrors(state)).some(n => n)
}

@ -86,6 +86,12 @@ describe('SendFooter Component', function () {
gasTotal: false,
expectedResult: true,
},
'should return true if to is truthy': {
to: '0xsomevalidAddress',
inError: false,
gasTotal: false,
expectedResult: true,
},
'should return true if selectedToken is truthy and tokenBalance is falsy': {
selectedToken: true,
tokenBalance: null,

@ -39,9 +39,8 @@ proxyquire('../send-footer.container.js', {
getSendToAccounts: (s) => `mockToAccounts:${s}`,
getTokenBalance: (s) => `mockTokenBalance:${s}`,
getUnapprovedTxs: (s) => `mockUnapprovedTxs:${s}`,
isSendFormInError: (s) => `mockInError:${s}`,
},
'./send-footer.selectors': { isSendFormInError: () => {} },
'./send-footer.selectors': { isSendFormInError: (s) => `mockInError:${s}` },
'./send-footer.utils': utilsStubs,
})

@ -0,0 +1,24 @@
import assert from 'assert'
import proxyquire from 'proxyquire'
const {
isSendFormInError,
} = proxyquire('../send-footer.selectors', {
'../send.selectors': {
getSendErrors: (mockState) => mockState.errors,
},
})
describe('send-footer selectors', () => {
describe('getTitleKey()', () => {
it('should return true if any of the values of the object returned by getSendErrors are truthy', () => {
assert.equal(isSendFormInError({ errors: { a: 'abc', b: false} }), true)
})
it('should return false if all of the values of the object returned by getSendErrors are falsy', () => {
assert.equal(isSendFormInError({ errors: { a: false, b: null} }), false)
})
})
})

@ -39,7 +39,6 @@ const selectors = {
getTokenBalance,
getTokenExchangeRate,
getUnapprovedTxs,
isSendFormInError,
transactionsSelector,
}
@ -251,11 +250,6 @@ function getUnapprovedTxs (state) {
return state.metamask.unapprovedTxs
}
function isSendFormInError (state) {
const { amount, to } = getSendErrors(state)
return Boolean(amount || to !== null)
}
function transactionsSelector (state) {
const { network, selectedTokenAddress } = state.metamask
const unapprovedMsgs = valuesFor(state.metamask.unapprovedMsgs)

@ -36,7 +36,6 @@ const {
getTokenBalance,
getTokenExchangeRate,
getUnapprovedTxs,
isSendFormInError,
transactionsSelector,
} = selectors
import mockState from './send-selectors-test-data'
@ -546,39 +545,6 @@ describe('send selectors', () => {
})
})
describe('isSendFormInError()', () => {
it('should return true if amount or to errors are truthy', () => {
const editedMockState1 = {
send: Object.assign({}, mockState.send, {
errors: { amount: true },
}),
}
assert.deepEqual(
isSendFormInError(editedMockState1),
true
)
const editedMockState2 = {
send: Object.assign({}, mockState.send, {
errors: { to: true },
}),
}
assert.deepEqual(
isSendFormInError(editedMockState2),
true
)
})
it('should return false if amount is falsy and to is null', () => {
const editedMockState = {
send: Object.assign({}, mockState.send, { errors: { amount: false, to: null } }),
}
assert.deepEqual(
isSendFormInError(editedMockState),
false
)
})
})
describe('transactionsSelector()', () => {
it('should return the selected addresses selected token transactions', () => {
assert.deepEqual(

Loading…
Cancel
Save