Move all of send state to metamask state.

feature/default_network_editable
Dan 7 years ago committed by Chi Kei Chan
parent 4f9ac1c4fe
commit f81226fbe9
  1. 46
      ui/app/actions.js
  2. 11
      ui/app/components/customize-gas-modal/index.js
  3. 2
      ui/app/components/send/from-dropdown.js
  4. 17
      ui/app/components/send/gas-fee-display-v2.js
  5. 13
      ui/app/components/send/send-v2-container.js
  6. 46
      ui/app/reducers/metamask.js
  7. 5
      ui/app/selectors.js
  8. 76
      ui/app/send-v2.js

@ -135,8 +135,18 @@ var actions = {
getGasPrice, getGasPrice,
UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT', UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT',
UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE', UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE',
UPDATE_GAS_TOTAL: 'UPDATE_GAS_TOTAL',
UPDATE_SEND_FROM: 'UPDATE_SEND_FROM',
UPDATE_SEND_TO: 'UPDATE_SEND_TO',
UPDATE_SEND_AMOUNT: 'UPDATE_SEND_AMOUNT',
UPDATE_SEND_MEMO: 'UPDATE_SEND_MEMO',
updateGasLimit, updateGasLimit,
updateGasPrice, updateGasPrice,
updateGasTotal,
updateSendFrom,
updateSendTo,
updateSendAmount,
updateSendMemo,
setSelectedAddress, setSelectedAddress,
// app messages // app messages
confirmSeedWords: confirmSeedWords, confirmSeedWords: confirmSeedWords,
@ -508,6 +518,42 @@ function updateGasPrice (gasPrice) {
} }
} }
function updateGasTotal (gasTotal) {
return {
type: actions.UPDATE_GAS_TOTAL,
value: gasTotal,
}
}
function updateSendFrom (from) {
return {
type: actions.UPDATE_SEND_FROM,
value: from,
}
}
function updateSendTo (to) {
return {
type: actions.UPDATE_SEND_TO,
value: to,
}
}
function updateSendAmount (amount) {
return {
type: actions.UPDATE_SEND_AMOUNT,
value: amount,
}
}
function updateSendMemo (memo) {
return {
type: actions.UPDATE_SEND_MEMO,
value: memo,
}
}
function sendTx (txData) { function sendTx (txData) {
log.info(`actions - sendTx: ${JSON.stringify(txData.txParams)}`) log.info(`actions - sendTx: ${JSON.stringify(txData.txParams)}`)
return (dispatch) => { return (dispatch) => {

@ -5,7 +5,7 @@ const connect = require('react-redux').connect
const actions = require('../../actions') const actions = require('../../actions')
const GasModalCard = require('./gas-modal-card') const GasModalCard = require('./gas-modal-card')
const { conversionUtil } = require('../../conversion-util') const { conversionUtil, multiplyCurrencies } = require('../../conversion-util')
const { const {
getGasPrice, getGasPrice,
@ -26,6 +26,7 @@ function mapDispatchToProps (dispatch) {
hideModal: () => dispatch(actions.hideModal()), hideModal: () => dispatch(actions.hideModal()),
updateGasPrice: newGasPrice => dispatch(actions.updateGasPrice(newGasPrice)), updateGasPrice: newGasPrice => dispatch(actions.updateGasPrice(newGasPrice)),
updateGasLimit: newGasLimit => dispatch(actions.updateGasLimit(newGasLimit)), updateGasLimit: newGasLimit => dispatch(actions.updateGasLimit(newGasLimit)),
updateGasTotal: newGasTotal => dispatch(actions.updateGasTotal(newGasTotal)),
} }
} }
@ -46,10 +47,18 @@ CustomizeGasModal.prototype.save = function (gasPrice, gasLimit) {
updateGasPrice, updateGasPrice,
updateGasLimit, updateGasLimit,
hideModal, hideModal,
updateGasTotal
} = this.props } = this.props
const newGasTotal = multiplyCurrencies(gasLimit, gasPrice, {
toNumericBase: 'hex',
multiplicandBase: 16,
multiplierBase: 16,
})
updateGasPrice(gasPrice) updateGasPrice(gasPrice)
updateGasLimit(gasLimit) updateGasLimit(gasLimit)
updateGasTotal(newGasTotal)
hideModal() hideModal()
} }

@ -38,7 +38,7 @@ FromDropdown.prototype.renderDropdown = function () {
...accounts.map(account => h(AccountListItem, { ...accounts.map(account => h(AccountListItem, {
account, account,
handleClick: () => { handleClick: () => {
onSelect(account.address) onSelect(account)
closeDropdown() closeDropdown()
}, },
icon: this.getListItemIcon(account, selectedAccount), icon: this.getListItemIcon(account, selectedAccount),

@ -1,9 +1,7 @@
const Component = require('react').Component const Component = require('react').Component
const h = require('react-hyperscript') const h = require('react-hyperscript')
const inherits = require('util').inherits const inherits = require('util').inherits
const CurrencyDisplay = require('./currency-display'); const CurrencyDisplay = require('./currency-display')
const { multiplyCurrencies } = require('../../conversion-util')
module.exports = GasFeeDisplay module.exports = GasFeeDisplay
@ -15,24 +13,17 @@ function GasFeeDisplay () {
GasFeeDisplay.prototype.render = function () { GasFeeDisplay.prototype.render = function () {
const { const {
conversionRate, conversionRate,
gasLimit, gasTotal,
gasPrice,
onClick, onClick,
} = this.props } = this.props
const readyToRender = Boolean(gasLimit && gasPrice)
return h('div', [ return h('div', [
readyToRender gasTotal
? h(CurrencyDisplay, { ? h(CurrencyDisplay, {
primaryCurrency: 'ETH', primaryCurrency: 'ETH',
convertedCurrency: 'USD', convertedCurrency: 'USD',
value: multiplyCurrencies(gasLimit, gasPrice, { value: gasTotal,
toNumericBase: 'hex',
multiplicandBase: 16,
multiplierBase: 16,
}),
conversionRate, conversionRate,
convertedPrefix: '$', convertedPrefix: '$',
readOnly: true, readOnly: true,

@ -15,6 +15,7 @@ const {
getGasPrice, getGasPrice,
getGasLimit, getGasLimit,
getAddressBook, getAddressBook,
getSendFrom,
} = require('../../selectors') } = require('../../selectors')
module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther) module.exports = connect(mapStateToProps, mapDispatchToProps)(SendEther)
@ -46,16 +47,15 @@ function mapStateToProps (state) {
} }
return { return {
selectedAccount: getCurrentAccountWithSendEtherInfo(state), ...state.metamask.send,
from: getSendFrom(state) || getCurrentAccountWithSendEtherInfo(state),
fromAccounts, fromAccounts,
toAccounts: [...fromAccounts, ...getAddressBook(state)], toAccounts: [...fromAccounts, ...getAddressBook(state)],
conversionRate, conversionRate,
selectedToken, selectedToken,
primaryCurrency, primaryCurrency,
data, data,
tokenToUSDRate, amountConversionRate: selectedToken ? tokenToUSDRate : conversionRate,
gasPrice: getGasPrice(state),
gasLimit: getGasLimit(state),
} }
} }
@ -71,5 +71,10 @@ function mapDispatchToProps (dispatch) {
signTx: txParams => dispatch(actions.signTx(txParams)), signTx: txParams => dispatch(actions.signTx(txParams)),
setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)), setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)),
addToAddressBook: address => dispatch(actions.addToAddressBook(address)), addToAddressBook: address => dispatch(actions.addToAddressBook(address)),
updateGasTotal: newTotal => dispatch(actions.updateGasTotal(newTotal)),
updateSendFrom: newFrom => dispatch(actions.updateSendFrom(newFrom)),
updateSendTo: newTo => dispatch(actions.updateSendTo(newTo)),
updateSendAmount: newAmount => dispatch(actions.updateSendAmount(newAmount)),
updateSendMemo: newMemo => dispatch(actions.updateSendMemo(newMemo)),
} }
} }

@ -24,6 +24,11 @@ function reduceMetamask (state, action) {
send: { send: {
gasLimit: null, gasLimit: null,
gasPrice: null, gasPrice: null,
gasTotal: null,
from: '',
to: '',
amount: '0x0',
memo: '',
}, },
}, state.metamask) }, state.metamask)
@ -157,6 +162,7 @@ function reduceMetamask (state, action) {
tokens: action.newTokens, tokens: action.newTokens,
}) })
// metamask.send
case actions.UPDATE_GAS_LIMIT: case actions.UPDATE_GAS_LIMIT:
return extend(metamaskState, { return extend(metamaskState, {
send: { send: {
@ -178,6 +184,46 @@ function reduceMetamask (state, action) {
isAccountMenuOpen: !metamaskState.isAccountMenuOpen, isAccountMenuOpen: !metamaskState.isAccountMenuOpen,
}) })
case actions.UPDATE_GAS_TOTAL:
return extend(metamaskState, {
send: {
...metamaskState.send,
gasTotal: action.value,
},
})
case actions.UPDATE_SEND_FROM:
return extend(metamaskState, {
send: {
...metamaskState.send,
from: action.value,
},
})
case actions.UPDATE_SEND_TO:
return extend(metamaskState, {
send: {
...metamaskState.send,
to: action.value,
},
})
case actions.UPDATE_SEND_AMOUNT:
return extend(metamaskState, {
send: {
...metamaskState.send,
amount: action.value,
},
})
case actions.UPDATE_SEND_MEMO:
return extend(metamaskState, {
send: {
...metamaskState.send,
memo: action.value,
},
})
default: default:
return metamaskState return metamaskState

@ -13,6 +13,7 @@ const selectors = {
getGasPrice, getGasPrice,
getGasLimit, getGasLimit,
getAddressBook, getAddressBook,
getSendFrom,
} }
module.exports = selectors module.exports = selectors
@ -107,3 +108,7 @@ function getGasPrice (state) {
function getGasLimit (state) { function getGasLimit (state) {
return state.metamask.send.gasLimit return state.metamask.send.gasLimit
} }
function getSendFrom (state) {
return state.metamask.send.from
}

@ -12,6 +12,8 @@ const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
const { showModal } = require('./actions') const { showModal } = require('./actions')
const { multiplyCurrencies } = require('./conversion-util')
module.exports = SendTransactionScreen module.exports = SendTransactionScreen
inherits(SendTransactionScreen, PersistentForm) inherits(SendTransactionScreen, PersistentForm)
@ -19,13 +21,6 @@ function SendTransactionScreen () {
PersistentForm.call(this) PersistentForm.call(this)
this.state = { this.state = {
from: '',
to: '',
gasPrice: null,
gasLimit: null,
amount: '0x0',
txData: null,
memo: '',
dropdownOpen: false, dropdownOpen: false,
} }
@ -41,6 +36,7 @@ SendTransactionScreen.prototype.componentWillMount = function () {
estimateGas, estimateGas,
selectedAddress, selectedAddress,
data, data,
updateGasTotal,
} = this.props } = this.props
const { symbol } = selectedToken || {} const { symbol } = selectedToken || {}
@ -58,13 +54,23 @@ SendTransactionScreen.prototype.componentWillMount = function () {
Object.assign(estimateGasParams, { data }) Object.assign(estimateGasParams, { data })
} }
Promise.all([ Promise
getGasPrice(), .all([
estimateGas({ getGasPrice(),
from: selectedAddress, estimateGas({
gas: '746a528800', from: selectedAddress,
}), gas: '746a528800',
]) }),
])
.then(([gasPrice, gas]) => {
const newGasTotal = multiplyCurrencies(gas, gasPrice, {
toNumericBase: 'hex',
multiplicandBase: 16,
multiplierBase: 16,
})
updateGasTotal(newGasTotal)
})
} }
SendTransactionScreen.prototype.renderHeaderIcon = function () { SendTransactionScreen.prototype.renderHeaderIcon = function () {
@ -122,10 +128,11 @@ SendTransactionScreen.prototype.renderHeader = function () {
SendTransactionScreen.prototype.renderFromRow = function () { SendTransactionScreen.prototype.renderFromRow = function () {
const { const {
from,
fromAccounts, fromAccounts,
conversionRate, conversionRate,
selectedAccount,
setSelectedAddress, setSelectedAddress,
updateSendFrom,
} = this.props } = this.props
const { dropdownOpen } = this.state const { dropdownOpen } = this.state
@ -137,8 +144,8 @@ SendTransactionScreen.prototype.renderFromRow = function () {
h(FromDropdown, { h(FromDropdown, {
dropdownOpen, dropdownOpen,
accounts: fromAccounts, accounts: fromAccounts,
selectedAccount, selectedAccount: from,
onSelect: address => setSelectedAddress(address), onSelect: updateSendFrom,
openDropdown: () => this.setState({ dropdownOpen: true }), openDropdown: () => this.setState({ dropdownOpen: true }),
closeDropdown: () => this.setState({ dropdownOpen: false }), closeDropdown: () => this.setState({ dropdownOpen: false }),
conversionRate, conversionRate,
@ -148,12 +155,10 @@ SendTransactionScreen.prototype.renderFromRow = function () {
} }
SendTransactionScreen.prototype.handleToChange = function (event) { SendTransactionScreen.prototype.handleToChange = function (event) {
const { updateSendTo } = this.props
const to = event.target.value const to = event.target.value
this.setState({ updateSendTo(to)
...this.state,
to,
})
} }
SendTransactionScreen.prototype.renderToRow = function () { SendTransactionScreen.prototype.renderToRow = function () {
@ -174,26 +179,21 @@ SendTransactionScreen.prototype.renderToRow = function () {
} }
SendTransactionScreen.prototype.handleAmountChange = function (value) { SendTransactionScreen.prototype.handleAmountChange = function (value) {
const { updateSendAmount } = this.props
const amount = value const amount = value
this.setState({ updateSendAmount(amount)
...this.state,
amount,
})
} }
SendTransactionScreen.prototype.renderAmountRow = function () { SendTransactionScreen.prototype.renderAmountRow = function () {
const { const {
conversionRate,
tokenToUSDRate,
selectedToken, selectedToken,
primaryCurrency = 'ETH', primaryCurrency = 'ETH',
amountConversionRate,
} = this.props } = this.props
const { amount } = this.state const { amount } = this.state
const amountConversionRate = selectedToken ? tokenToUSDRate : conversionRate
return h('div.send-v2__form-row', [ return h('div.send-v2__form-row', [
h('div.send-v2__form-label', 'Amount:'), h('div.send-v2__form-label', 'Amount:'),
@ -214,8 +214,7 @@ SendTransactionScreen.prototype.renderGasRow = function () {
const { const {
conversionRate, conversionRate,
showCustomizeGasModal, showCustomizeGasModal,
gasLimit, gasTotal,
gasPrice,
} = this.props } = this.props
return h('div.send-v2__form-row', [ return h('div.send-v2__form-row', [
@ -223,8 +222,7 @@ SendTransactionScreen.prototype.renderGasRow = function () {
h('div.send-v2__form-label', 'Gas fee:'), h('div.send-v2__form-label', 'Gas fee:'),
h(GasFeeDisplay, { h(GasFeeDisplay, {
gasLimit, gasTotal,
gasPrice,
conversionRate, conversionRate,
onClick: showCustomizeGasModal, onClick: showCustomizeGasModal,
}), }),
@ -239,6 +237,7 @@ SendTransactionScreen.prototype.renderGasRow = function () {
} }
SendTransactionScreen.prototype.renderMemoRow = function () { SendTransactionScreen.prototype.renderMemoRow = function () {
const { updateSendMemo } = this.props
const { memo } = this.state const { memo } = this.state
return h('div.send-v2__form-row', [ return h('div.send-v2__form-row', [
@ -247,12 +246,7 @@ SendTransactionScreen.prototype.renderMemoRow = function () {
h(MemoTextArea, { h(MemoTextArea, {
memo, memo,
onChange: (event) => { onChange: (event) => updateSendMemo(event.target.value),
this.setState({
...this.state,
memo: event.target.value,
})
},
}), }),
]) ])
@ -313,16 +307,14 @@ SendTransactionScreen.prototype.addToAddressBookIfNew = function (newAddress) {
SendTransactionScreen.prototype.onSubmit = function (event) { SendTransactionScreen.prototype.onSubmit = function (event) {
event.preventDefault() event.preventDefault()
const { const {
from: {address: from},
to, to,
amount, amount,
} = this.state
const {
gasLimit: gas, gasLimit: gas,
gasPrice, gasPrice,
signTokenTx, signTokenTx,
signTx, signTx,
selectedToken, selectedToken,
selectedAccount: { address: from },
toAccounts, toAccounts,
} = this.props } = this.props

Loading…
Cancel
Save