aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-05-25 08:53:54 +0800
committerDan <danjm.com@gmail.com>2018-05-25 08:53:54 +0800
commitdc2b5d0ef47be2125e58018470539d65d0d64c75 (patch)
treed672bbc0ef62f3c4bb7f100812cac294fe905640
parent3a87d9221d7ae1d0d7cb526e5fb22ea528498105 (diff)
downloadtangerine-wallet-browser-dc2b5d0ef47be2125e58018470539d65d0d64c75.tar
tangerine-wallet-browser-dc2b5d0ef47be2125e58018470539d65d0d64c75.tar.gz
tangerine-wallet-browser-dc2b5d0ef47be2125e58018470539d65d0d64c75.tar.bz2
tangerine-wallet-browser-dc2b5d0ef47be2125e58018470539d65d0d64c75.tar.lz
tangerine-wallet-browser-dc2b5d0ef47be2125e58018470539d65d0d64c75.tar.xz
tangerine-wallet-browser-dc2b5d0ef47be2125e58018470539d65d0d64c75.tar.zst
tangerine-wallet-browser-dc2b5d0ef47be2125e58018470539d65d0d64c75.zip
Move formShouldBeDisabled from send-footer util to component.
-rw-r--r--ui/app/components/send_/send-footer/send-footer.component.js9
-rw-r--r--ui/app/components/send_/send-footer/send-footer.utils.js6
-rw-r--r--ui/app/components/send_/send-footer/tests/send-footer-component.test.js65
-rw-r--r--ui/app/components/send_/send-footer/tests/send-footer-utils.test.js32
4 files changed, 72 insertions, 40 deletions
diff --git a/ui/app/components/send_/send-footer/send-footer.component.js b/ui/app/components/send_/send-footer/send-footer.component.js
index de2a885f0..7ff44c9d5 100644
--- a/ui/app/components/send_/send-footer/send-footer.component.js
+++ b/ui/app/components/send_/send-footer/send-footer.component.js
@@ -17,6 +17,7 @@ export default class SendFooter extends Component {
gasPrice: PropTypes.string,
gasTotal: PropTypes.string,
history: PropTypes.object,
+ inError: PropTypes.bool,
selectedToken: PropTypes.object,
sign: PropTypes.func,
to: PropTypes.string,
@@ -75,12 +76,18 @@ export default class SendFooter extends Component {
this.props.history.push(CONFIRM_TRANSACTION_ROUTE)
}
+ formShouldBeDisabled () {
+ const { inError, selectedToken, tokenBalance, gasTotal } = this.props
+ const missingTokenBalance = selectedToken && !tokenBalance
+ return inError || !gasTotal || missingTokenBalance
+ }
+
render () {
return (
<PageContainerFooter
onCancel={() => this.onCancel()}
onSubmit={e => this.onSubmit(e)}
- disabled={this.props.disabled}
+ disabled={this.formShouldBeDisabled()}
/>
)
}
diff --git a/ui/app/components/send_/send-footer/send-footer.utils.js b/ui/app/components/send_/send-footer/send-footer.utils.js
index 149d9e357..d5639629d 100644
--- a/ui/app/components/send_/send-footer/send-footer.utils.js
+++ b/ui/app/components/send_/send-footer/send-footer.utils.js
@@ -2,11 +2,6 @@ const ethAbi = require('ethereumjs-abi')
const ethUtil = require('ethereumjs-util')
const { TOKEN_TRANSFER_FUNCTION_SIGNATURE } = require('../send.constants')
-function formShouldBeDisabled ({ inError, selectedToken, tokenBalance, gasTotal }) {
- const missingTokenBalance = selectedToken && !tokenBalance
- return inError || !gasTotal || missingTokenBalance
-}
-
function addHexPrefixToObjectValues (obj) {
return Object.keys(obj).reduce((newObj, key) => {
return { ...newObj, [key]: ethUtil.addHexPrefix(obj[key]) }
@@ -81,7 +76,6 @@ function addressIsNew (toAccounts, newAddress) {
module.exports = {
addressIsNew,
- formShouldBeDisabled,
constructTxParams,
constructUpdatedTx,
addHexPrefixToObjectValues,
diff --git a/ui/app/components/send_/send-footer/tests/send-footer-component.test.js b/ui/app/components/send_/send-footer/tests/send-footer-component.test.js
index c0b8f956f..a74b6195c 100644
--- a/ui/app/components/send_/send-footer/tests/send-footer-component.test.js
+++ b/ui/app/components/send_/send-footer/tests/send-footer-component.test.js
@@ -37,6 +37,7 @@ describe('SendFooter Component', function () {
gasPrice={'mockGasPrice'}
gasTotal={'mockGasTotal'}
history={historySpies}
+ inError={false}
selectedToken={{ mockProp: 'mockSelectedTokenProp' }}
sign={propsMethodSpies.sign}
to={'mockTo'}
@@ -73,6 +74,39 @@ describe('SendFooter Component', function () {
})
})
+
+ describe('formShouldBeDisabled()', () => {
+ const config = {
+ 'should return true if inError is truthy': {
+ inError: true,
+ expectedResult: true,
+ },
+ 'should return true if gasTotal is falsy': {
+ inError: false,
+ gasTotal: false,
+ expectedResult: true,
+ },
+ 'should return true if selectedToken is truthy and tokenBalance is falsy': {
+ selectedToken: true,
+ tokenBalance: null,
+ expectedResult: true,
+ },
+ 'should return false if inError is false and all other params are truthy': {
+ inError: false,
+ gasTotal: '0x123',
+ selectedToken: true,
+ tokenBalance: 123,
+ expectedResult: false,
+ },
+ }
+ Object.entries(config).map(([description, obj]) => {
+ it(description, () => {
+ wrapper.setProps(obj)
+ assert.equal(wrapper.instance().formShouldBeDisabled(), obj.expectedResult)
+ })
+ })
+ })
+
describe('onSubmit', () => {
it('should call addToAddressBookIfNew with the correct params', () => {
wrapper.instance().onSubmit(MOCK_EVENT)
@@ -134,6 +168,35 @@ describe('SendFooter Component', function () {
})
describe('render', () => {
+ beforeEach(() => {
+ sinon.stub(SendFooter.prototype, 'formShouldBeDisabled').returns('formShouldBeDisabledReturn')
+ wrapper = shallow(<SendFooter
+ addToAddressBookIfNew={propsMethodSpies.addToAddressBookIfNew}
+ amount={'mockAmount'}
+ clearSend={propsMethodSpies.clearSend}
+ disabled={true}
+ editingTransactionId={'mockEditingTransactionId'}
+ errors={{}}
+ from={ { address: 'mockAddress', balance: 'mockBalance' } }
+ gasLimit={'mockGasLimit'}
+ gasPrice={'mockGasPrice'}
+ gasTotal={'mockGasTotal'}
+ history={historySpies}
+ inError={false}
+ selectedToken={{ mockProp: 'mockSelectedTokenProp' }}
+ sign={propsMethodSpies.sign}
+ to={'mockTo'}
+ toAccounts={['mockAccount']}
+ tokenBalance={'mockTokenBalance'}
+ unapprovedTxs={['mockTx']}
+ update={propsMethodSpies.update}
+ />, { context: { t: str => str } })
+ })
+
+ afterEach(() => {
+ SendFooter.prototype.formShouldBeDisabled.restore()
+ })
+
it('should render a PageContainerFooter component', () => {
assert.equal(wrapper.find(PageContainerFooter).length, 1)
})
@@ -144,7 +207,7 @@ describe('SendFooter Component', function () {
onSubmit,
disabled,
} = wrapper.find(PageContainerFooter).props()
- assert.equal(disabled, true)
+ assert.equal(disabled, 'formShouldBeDisabledReturn')
assert.equal(SendFooter.prototype.onSubmit.callCount, 0)
onSubmit(MOCK_EVENT)
diff --git a/ui/app/components/send_/send-footer/tests/send-footer-utils.test.js b/ui/app/components/send_/send-footer/tests/send-footer-utils.test.js
index b235ea5e5..2d3135995 100644
--- a/ui/app/components/send_/send-footer/tests/send-footer-utils.test.js
+++ b/ui/app/components/send_/send-footer/tests/send-footer-utils.test.js
@@ -16,7 +16,6 @@ const sendUtils = proxyquire('../send-footer.utils.js', {
})
const {
addressIsNew,
- formShouldBeDisabled,
constructTxParams,
constructUpdatedTx,
addHexPrefixToObjectValues,
@@ -65,37 +64,6 @@ describe('send-footer utils', () => {
})
})
- describe('formShouldBeDisabled()', () => {
- const config = {
- 'should return true if inError is truthy': {
- inError: true,
- expectedResult: true,
- },
- 'should return true if gasTotal is falsy': {
- inError: false,
- gasTotal: false,
- expectedResult: true,
- },
- 'should return true if selectedToken is truthy and tokenBalance is falsy': {
- selectedToken: true,
- tokenBalance: null,
- expectedResult: true,
- },
- 'should return false if inError is false and all other params are truthy': {
- inError: false,
- gasTotal: '0x123',
- selectedToken: true,
- tokenBalance: 123,
- expectedResult: false,
- },
- }
- Object.entries(config).map(([description, obj]) => {
- it(description, () => {
- assert.equal(formShouldBeDisabled(obj), obj.expectedResult)
- })
- })
- })
-
describe('constructTxParams()', () => {
it('should return a new txParams object with value and to properties if there is no selectedToken', () => {
assert.deepEqual(