Merge branch 'NewUI-flat' into merge-master-to-newUI-flat-dec20

feature/default_network_editable
Chi Kei Chan 7 years ago committed by GitHub
commit 9959aea598
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/scripts/controllers/transactions.js
  2. 1
      app/scripts/metamask-controller.js
  3. 19
      ui/app/actions.js
  4. 24
      ui/app/components/pending-tx/confirm-send-ether.js
  5. 38
      ui/app/components/pending-tx/confirm-send-token.js
  6. 3
      ui/app/components/send/send-constants.js
  7. 3
      ui/app/components/send/send-v2-container.js
  8. 54
      ui/app/send-v2.js

@ -194,6 +194,10 @@ module.exports = class TransactionController extends EventEmitter {
this.txStateManager.updateTx(txMeta, 'retryTransaction: manual retry') this.txStateManager.updateTx(txMeta, 'retryTransaction: manual retry')
} }
async updateTransaction (txMeta) {
this.txStateManager.updateTx(txMeta, 'confTx: user updated transaction')
}
async updateAndApproveTransaction (txMeta) { async updateAndApproveTransaction (txMeta) {
this.txStateManager.updateTx(txMeta, 'confTx: user approved transaction') this.txStateManager.updateTx(txMeta, 'confTx: user approved transaction')
await this.approveTransaction(txMeta.id) await this.approveTransaction(txMeta.id)

@ -376,6 +376,7 @@ module.exports = class MetamaskController extends EventEmitter {
// txController // txController
cancelTransaction: nodeify(txController.cancelTransaction, txController), cancelTransaction: nodeify(txController.cancelTransaction, txController),
updateTransaction: nodeify(txController.updateTransaction, txController),
updateAndApproveTransaction: nodeify(txController.updateAndApproveTransaction, txController), updateAndApproveTransaction: nodeify(txController.updateAndApproveTransaction, txController),
retryTransaction: nodeify(this.retryTransaction, this), retryTransaction: nodeify(this.retryTransaction, this),

@ -125,6 +125,7 @@ var actions = {
sendTx: sendTx, sendTx: sendTx,
signTx: signTx, signTx: signTx,
signTokenTx: signTokenTx, signTokenTx: signTokenTx,
updateTransaction,
updateAndApproveTx, updateAndApproveTx,
cancelTx: cancelTx, cancelTx: cancelTx,
completedTx: completedTx, completedTx: completedTx,
@ -694,6 +695,23 @@ function signTokenTx (tokenAddress, toAddress, amount, txData) {
} }
} }
function updateTransaction (txData) {
log.info('actions: updateTx: ' + JSON.stringify(txData))
return (dispatch) => {
log.debug(`actions calling background.updateTx`)
background.updateTransaction(txData, (err) => {
dispatch(actions.hideLoadingIndication())
dispatch(actions.updateTransactionParams(txData.id, txData.txParams))
if (err) {
dispatch(actions.txError(err))
dispatch(actions.goHome())
return log.error(err.message)
}
dispatch(actions.showConfTxPage({ id: txData.id }))
})
}
}
function updateAndApproveTx (txData) { function updateAndApproveTx (txData) {
log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData)) log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
return (dispatch) => { return (dispatch) => {
@ -756,6 +774,7 @@ function cancelTx (txData) {
return (dispatch) => { return (dispatch) => {
log.debug(`background.cancelTransaction`) log.debug(`background.cancelTransaction`)
background.cancelTransaction(txData.id, () => { background.cancelTransaction(txData.id, () => {
dispatch(actions.clearSend())
dispatch(actions.completedTx(txData.id)) dispatch(actions.completedTx(txData.id))
}) })
} }

@ -421,7 +421,9 @@ ConfirmSendEther.prototype.onSubmit = function (event) {
ConfirmSendEther.prototype.cancel = function (event, txMeta) { ConfirmSendEther.prototype.cancel = function (event, txMeta) {
event.preventDefault() event.preventDefault()
this.props.cancelTransaction(txMeta) const { cancelTransaction } = this.props
cancelTransaction(txMeta)
} }
ConfirmSendEther.prototype.checkValidity = function () { ConfirmSendEther.prototype.checkValidity = function () {
@ -445,26 +447,6 @@ ConfirmSendEther.prototype.gatherTxMeta = function () {
const state = this.state const state = this.state
const txData = clone(state.txData) || clone(props.txData) const txData = clone(state.txData) || clone(props.txData)
if (props.send.editingTransactionId) {
const {
send: {
memo,
amount: value,
gasLimit: gas,
gasPrice,
},
} = props
const { txParams: { from, to } } = txData
txData.txParams = {
from: ethUtil.addHexPrefix(from),
to: ethUtil.addHexPrefix(to),
memo: memo && ethUtil.addHexPrefix(memo),
value: ethUtil.addHexPrefix(value),
gas: ethUtil.addHexPrefix(gas),
gasPrice: ethUtil.addHexPrefix(gasPrice),
}
}
// log.debug(`UI has defaulted to tx meta ${JSON.stringify(txData)}`) // log.debug(`UI has defaulted to tx meta ${JSON.stringify(txData)}`)
return txData return txData
} }

@ -2,7 +2,6 @@ const Component = require('react').Component
const { connect } = require('react-redux') const { connect } = require('react-redux')
const h = require('react-hyperscript') const h = require('react-hyperscript')
const inherits = require('util').inherits const inherits = require('util').inherits
const ethAbi = require('ethereumjs-abi')
const tokenAbi = require('human-standard-token-abi') const tokenAbi = require('human-standard-token-abi')
const abiDecoder = require('abi-decoder') const abiDecoder = require('abi-decoder')
abiDecoder.addABI(tokenAbi) abiDecoder.addABI(tokenAbi)
@ -415,7 +414,9 @@ ConfirmSendToken.prototype.onSubmit = function (event) {
ConfirmSendToken.prototype.cancel = function (event, txMeta) { ConfirmSendToken.prototype.cancel = function (event, txMeta) {
event.preventDefault() event.preventDefault()
this.props.cancelTransaction(txMeta) const { cancelTransaction } = this.props
cancelTransaction(txMeta)
} }
ConfirmSendToken.prototype.checkValidity = function () { ConfirmSendToken.prototype.checkValidity = function () {
@ -439,39 +440,6 @@ ConfirmSendToken.prototype.gatherTxMeta = function () {
const state = this.state const state = this.state
const txData = clone(state.txData) || clone(props.txData) const txData = clone(state.txData) || clone(props.txData)
if (props.send.editingTransactionId) {
const {
send: {
memo,
amount,
gasLimit: gas,
gasPrice,
to,
},
} = props
const { txParams: { from, to: tokenAddress } } = txData
const tokenParams = {
from: ethUtil.addHexPrefix(from),
value: '0',
gas: ethUtil.addHexPrefix(gas),
gasPrice: ethUtil.addHexPrefix(gasPrice),
}
const data = '0xa9059cbb' + Array.prototype.map.call(
ethAbi.rawEncode(['address', 'uint256'], [to, ethUtil.addHexPrefix(amount)]),
x => ('00' + x.toString(16)).slice(-2)
).join('')
txData.txParams = {
...tokenParams,
to: ethUtil.addHexPrefix(tokenAddress),
memo: memo && ethUtil.addHexPrefix(memo),
data,
}
}
// log.debug(`UI has defaulted to tx meta ${JSON.stringify(txData)}`) // log.debug(`UI has defaulted to tx meta ${JSON.stringify(txData)}`)
return txData return txData
} }

@ -20,6 +20,8 @@ const MIN_GAS_TOTAL = multiplyCurrencies(MIN_GAS_LIMIT_HEX, MIN_GAS_PRICE_HEX, {
multiplierBase: 16, multiplierBase: 16,
}) })
const TOKEN_TRANSFER_FUNCTION_SIGNATURE = '0xa9059cbb'
module.exports = { module.exports = {
MIN_GAS_PRICE_GWEI, MIN_GAS_PRICE_GWEI,
MIN_GAS_PRICE_HEX, MIN_GAS_PRICE_HEX,
@ -27,4 +29,5 @@ module.exports = {
MIN_GAS_LIMIT_HEX, MIN_GAS_LIMIT_HEX,
MIN_GAS_LIMIT_DEC, MIN_GAS_LIMIT_DEC,
MIN_GAS_TOTAL, MIN_GAS_TOTAL,
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
} }

@ -50,6 +50,7 @@ function mapStateToProps (state) {
data, data,
amountConversionRate: selectedToken ? tokenToFiatRate : conversionRate, amountConversionRate: selectedToken ? tokenToFiatRate : conversionRate,
tokenContract: getSelectedTokenContract(state), tokenContract: getSelectedTokenContract(state),
unapprovedTxs: state.metamask.unapprovedTxs,
} }
} }
@ -64,6 +65,7 @@ function mapDispatchToProps (dispatch) {
), ),
signTx: txParams => dispatch(actions.signTx(txParams)), signTx: txParams => dispatch(actions.signTx(txParams)),
updateAndApproveTx: txParams => dispatch(actions.updateAndApproveTx(txParams)), updateAndApproveTx: txParams => dispatch(actions.updateAndApproveTx(txParams)),
updateTx: txData => dispatch(actions.updateTransaction(txData)),
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)), updateGasTotal: newTotal => dispatch(actions.updateGasTotal(newTotal)),
@ -77,7 +79,6 @@ function mapDispatchToProps (dispatch) {
updateSendErrors: newError => dispatch(actions.updateSendErrors(newError)), updateSendErrors: newError => dispatch(actions.updateSendErrors(newError)),
goHome: () => dispatch(actions.goHome()), goHome: () => dispatch(actions.goHome()),
clearSend: () => dispatch(actions.clearSend()), clearSend: () => dispatch(actions.clearSend()),
backToConfirmScreen: editingTransactionId => dispatch(actions.showConfTxPage({ id: editingTransactionId })),
setMaxModeTo: bool => dispatch(actions.setMaxModeTo(bool)), setMaxModeTo: bool => dispatch(actions.setMaxModeTo(bool)),
} }
} }

@ -2,6 +2,7 @@ const { inherits } = require('util')
const PersistentForm = require('../lib/persistent-form') const PersistentForm = require('../lib/persistent-form')
const h = require('react-hyperscript') const h = require('react-hyperscript')
const ethAbi = require('ethereumjs-abi')
const ethUtil = require('ethereumjs-util') const ethUtil = require('ethereumjs-util')
const Identicon = require('./components/identicon') const Identicon = require('./components/identicon')
@ -13,6 +14,7 @@ const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
const { const {
MIN_GAS_TOTAL, MIN_GAS_TOTAL,
TOKEN_TRANSFER_FUNCTION_SIGNATURE,
} = require('./components/send/send-constants') } = require('./components/send/send-constants')
const { const {
@ -552,6 +554,48 @@ SendTransactionScreen.prototype.addToAddressBookIfNew = function (newAddress) {
} }
} }
SendTransactionScreen.prototype.getEditedTx = function () {
const {
from: {address: from},
to,
amount,
gasLimit: gas,
gasPrice,
selectedToken,
editingTransactionId,
unapprovedTxs,
} = this.props
const editingTx = {
...unapprovedTxs[editingTransactionId],
txParams: {
from: ethUtil.addHexPrefix(from),
gas: ethUtil.addHexPrefix(gas),
gasPrice: ethUtil.addHexPrefix(gasPrice),
}
}
if (selectedToken) {
const data = TOKEN_TRANSFER_FUNCTION_SIGNATURE + Array.prototype.map.call(
ethAbi.rawEncode(['address', 'uint256'], [to, ethUtil.addHexPrefix(amount)]),
x => ('00' + x.toString(16)).slice(-2)
).join('')
Object.assign(editingTx.txParams, {
value: ethUtil.addHexPrefix('0'),
to: ethUtil.addHexPrefix(selectedToken.address),
data,
})
} else {
Object.assign(editingTx.txParams, {
value: ethUtil.addHexPrefix(amount),
to: ethUtil.addHexPrefix(to),
})
}
return editingTx
}
SendTransactionScreen.prototype.onSubmit = function (event) { SendTransactionScreen.prototype.onSubmit = function (event) {
event.preventDefault() event.preventDefault()
const { const {
@ -562,10 +606,10 @@ SendTransactionScreen.prototype.onSubmit = function (event) {
gasPrice, gasPrice,
signTokenTx, signTokenTx,
signTx, signTx,
updateTx,
selectedToken, selectedToken,
editingTransactionId, editingTransactionId,
errors: { amount: amountError, to: toError }, errors: { amount: amountError, to: toError },
backToConfirmScreen,
} = this.props } = this.props
const noErrors = !amountError && toError === null const noErrors = !amountError && toError === null
@ -577,9 +621,10 @@ SendTransactionScreen.prototype.onSubmit = function (event) {
this.addToAddressBookIfNew(to) this.addToAddressBookIfNew(to)
if (editingTransactionId) { if (editingTransactionId) {
backToConfirmScreen(editingTransactionId) const editedTx = this.getEditedTx()
return
} updateTx(editedTx)
} else {
const txParams = { const txParams = {
from, from,
@ -597,3 +642,4 @@ SendTransactionScreen.prototype.onSubmit = function (event) {
? signTokenTx(selectedToken.address, to, amount, txParams) ? signTokenTx(selectedToken.address, to, amount, txParams)
: signTx(txParams) : signTx(txParams)
} }
}

Loading…
Cancel
Save