On send screen amount change, updateGas call now includes current to address.

feature/default_network_editable
Dan 7 years ago
parent 70abe54c94
commit ac7c0277b5
  1. 6
      ui/app/components/send_/send.component.js
  2. 2
      ui/app/components/send_/send.container.js
  3. 5
      ui/app/components/send_/send.utils.js
  4. 14
      ui/app/components/send_/tests/send-component.test.js
  5. 2
      ui/app/components/send_/tests/send-container.test.js
  6. 12
      ui/app/components/send_/tests/send-utils.test.js

@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import PersistentForm from '../../../lib/persistent-form' import PersistentForm from '../../../lib/persistent-form'
import { import {
getAmountErrorObject, getAmountErrorObject,
getToAddressForGasUpdate,
doesAmountErrorRequireUpdate, doesAmountErrorRequireUpdate,
} from './send.utils' } from './send.utils'
@ -38,7 +39,7 @@ export default class SendTransactionScreen extends PersistentForm {
updateSendTokenBalance: PropTypes.func, updateSendTokenBalance: PropTypes.func,
}; };
updateGas ({ to, amount: value } = {}) { updateGas ({ to: updatedToAddress, amount: value } = {}) {
const { const {
amount, amount,
blockGasLimit, blockGasLimit,
@ -48,6 +49,7 @@ export default class SendTransactionScreen extends PersistentForm {
recentBlocks, recentBlocks,
selectedAddress, selectedAddress,
selectedToken = {}, selectedToken = {},
to: currentToAddress,
updateAndSetGasTotal, updateAndSetGasTotal,
} = this.props } = this.props
@ -59,7 +61,7 @@ export default class SendTransactionScreen extends PersistentForm {
recentBlocks, recentBlocks,
selectedAddress, selectedAddress,
selectedToken, selectedToken,
to: to && to.toLowerCase(), to: getToAddressForGasUpdate(updatedToAddress, currentToAddress),
value: value || amount, value: value || amount,
}) })
} }

@ -19,6 +19,7 @@ import {
getSendAmount, getSendAmount,
getSendEditingTransactionId, getSendEditingTransactionId,
getSendFromObject, getSendFromObject,
getSendTo,
getTokenBalance, getTokenBalance,
} from './send.selectors' } from './send.selectors'
import { import {
@ -54,6 +55,7 @@ function mapStateToProps (state) {
recentBlocks: getRecentBlocks(state), recentBlocks: getRecentBlocks(state),
selectedAddress: getSelectedAddress(state), selectedAddress: getSelectedAddress(state),
selectedToken: getSelectedToken(state), selectedToken: getSelectedToken(state),
to: getSendTo(state),
tokenBalance: getTokenBalance(state), tokenBalance: getTokenBalance(state),
tokenContract: getSelectedTokenContract(state), tokenContract: getSelectedTokenContract(state),
tokenToFiatRate: getSelectedTokenToFiatRate(state), tokenToFiatRate: getSelectedTokenToFiatRate(state),

@ -29,6 +29,7 @@ module.exports = {
estimateGasPriceFromRecentBlocks, estimateGasPriceFromRecentBlocks,
generateTokenTransferData, generateTokenTransferData,
getAmountErrorObject, getAmountErrorObject,
getToAddressForGasUpdate,
isBalanceSufficient, isBalanceSufficient,
isTokenBalanceSufficient, isTokenBalanceSufficient,
} }
@ -268,3 +269,7 @@ function estimateGasPriceFromRecentBlocks (recentBlocks) {
return lowestPrices[Math.floor(lowestPrices.length / 2)] return lowestPrices[Math.floor(lowestPrices.length / 2)]
} }
function getToAddressForGasUpdate (...addresses) {
return [...addresses, ''].find(str => str !== undefined && str !== null).toLowerCase()
}

@ -201,7 +201,7 @@ describe('Send Component', function () {
}) })
describe('updateGas', () => { describe('updateGas', () => {
it('should call updateAndSetGasTotal with the correct params', () => { it('should call updateAndSetGasTotal with the correct params if no to prop is passed', () => {
propsMethodSpies.updateAndSetGasTotal.resetHistory() propsMethodSpies.updateAndSetGasTotal.resetHistory()
wrapper.instance().updateGas() wrapper.instance().updateGas()
assert.equal(propsMethodSpies.updateAndSetGasTotal.callCount, 1) assert.equal(propsMethodSpies.updateAndSetGasTotal.callCount, 1)
@ -215,12 +215,22 @@ describe('Send Component', function () {
recentBlocks: ['mockBlock'], recentBlocks: ['mockBlock'],
selectedAddress: 'mockSelectedAddress', selectedAddress: 'mockSelectedAddress',
selectedToken: 'mockSelectedToken', selectedToken: 'mockSelectedToken',
to: undefined, to: '',
value: 'mockAmount', value: 'mockAmount',
} }
) )
}) })
it('should call updateAndSetGasTotal with the correct params if a to prop is passed', () => {
propsMethodSpies.updateAndSetGasTotal.resetHistory()
wrapper.setProps({ to: 'someAddress' })
wrapper.instance().updateGas()
assert.equal(
propsMethodSpies.updateAndSetGasTotal.getCall(0).args[0].to,
'someaddress',
)
})
it('should call updateAndSetGasTotal with to set to lowercase if passed', () => { it('should call updateAndSetGasTotal with to set to lowercase if passed', () => {
propsMethodSpies.updateAndSetGasTotal.resetHistory() propsMethodSpies.updateAndSetGasTotal.resetHistory()
wrapper.instance().updateGas({ to: '0xABC' }) wrapper.instance().updateGas({ to: '0xABC' })

@ -39,6 +39,7 @@ proxyquire('../send.container.js', {
getSelectedTokenContract: (s) => `mockTokenContract:${s}`, getSelectedTokenContract: (s) => `mockTokenContract:${s}`,
getSelectedTokenToFiatRate: (s) => `mockTokenToFiatRate:${s}`, getSelectedTokenToFiatRate: (s) => `mockTokenToFiatRate:${s}`,
getSendAmount: (s) => `mockAmount:${s}`, getSendAmount: (s) => `mockAmount:${s}`,
getSendTo: (s) => `mockTo:${s}`,
getSendEditingTransactionId: (s) => `mockEditingTransactionId:${s}`, getSendEditingTransactionId: (s) => `mockEditingTransactionId:${s}`,
getSendFromObject: (s) => `mockFrom:${s}`, getSendFromObject: (s) => `mockFrom:${s}`,
getTokenBalance: (s) => `mockTokenBalance:${s}`, getTokenBalance: (s) => `mockTokenBalance:${s}`,
@ -70,6 +71,7 @@ describe('send container', () => {
recentBlocks: 'mockRecentBlocks:mockState', recentBlocks: 'mockRecentBlocks:mockState',
selectedAddress: 'mockSelectedAddress:mockState', selectedAddress: 'mockSelectedAddress:mockState',
selectedToken: 'mockSelectedToken:mockState', selectedToken: 'mockSelectedToken:mockState',
to: 'mockTo:mockState',
tokenBalance: 'mockTokenBalance:mockState', tokenBalance: 'mockTokenBalance:mockState',
tokenContract: 'mockTokenContract:mockState', tokenContract: 'mockTokenContract:mockState',
tokenToFiatRate: 'mockTokenToFiatRate:mockState', tokenToFiatRate: 'mockTokenToFiatRate:mockState',

@ -48,6 +48,7 @@ const {
estimateGasPriceFromRecentBlocks, estimateGasPriceFromRecentBlocks,
generateTokenTransferData, generateTokenTransferData,
getAmountErrorObject, getAmountErrorObject,
getToAddressForGasUpdate,
calcTokenBalance, calcTokenBalance,
isBalanceSufficient, isBalanceSufficient,
isTokenBalanceSufficient, isTokenBalanceSufficient,
@ -421,4 +422,15 @@ describe('send utils', () => {
assert.equal(estimateGasPriceFromRecentBlocks(mockRecentBlocks), '0x5') assert.equal(estimateGasPriceFromRecentBlocks(mockRecentBlocks), '0x5')
}) })
}) })
describe('getToAddressForGasUpdate()', () => {
it('should return empty string if all params are undefined or null', () => {
assert.equal(getToAddressForGasUpdate(undefined, null), '')
})
it('should return the first string that is not defined or null in lower case', () => {
assert.equal(getToAddressForGasUpdate('A', null), 'a')
assert.equal(getToAddressForGasUpdate(undefined, 'B'), 'b')
})
})
}) })

Loading…
Cancel
Save