aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-12-21 01:17:16 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-12-21 09:37:18 +0800
commitbf4043c59bb67ea93599207d91cb7a4f4426e75f (patch)
tree04013dc75d07ede37a6b0dbbf616a1dbff0c75b1 /ui
parent1f1fc2c49ecbb5c6a0a1d925d5c02cf48f795b2f (diff)
downloadtangerine-wallet-browser-bf4043c59bb67ea93599207d91cb7a4f4426e75f.tar.gz
tangerine-wallet-browser-bf4043c59bb67ea93599207d91cb7a4f4426e75f.tar.zst
tangerine-wallet-browser-bf4043c59bb67ea93599207d91cb7a4f4426e75f.zip
Adds updateTransaction to background and used it to update after editing in send-v2.
Diffstat (limited to 'ui')
-rw-r--r--ui/app/actions.js22
-rw-r--r--ui/app/components/pending-tx/confirm-send-ether.js29
-rw-r--r--ui/app/components/pending-tx/confirm-send-token.js42
-rw-r--r--ui/app/components/send/send-v2-container.js2
-rw-r--r--ui/app/conf-tx.js2
-rw-r--r--ui/app/send-v2.js78
6 files changed, 80 insertions, 95 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 9d3d7184e..ef8a5ec46 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -125,8 +125,8 @@ var actions = {
sendTx: sendTx,
signTx: signTx,
signTokenTx: signTokenTx,
+ updateTransaction,
updateAndApproveTx,
- updateAndCancelTx,
cancelTx: cancelTx,
completedTx: completedTx,
txError: txError,
@@ -693,29 +693,28 @@ function signTokenTx (tokenAddress, toAddress, amount, txData) {
}
}
-function updateAndApproveTx (txData) {
- log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
+function updateTransaction (txData) {
+ log.info('actions: updateTx: ' + JSON.stringify(txData))
return (dispatch) => {
- log.debug(`actions calling background.updateAndApproveTx`)
- background.updateAndApproveTransaction(txData, (err) => {
+ log.debug(`actions calling background.updateTx`)
+ background.updateTransaction(txData, (err) => {
dispatch(actions.hideLoadingIndication())
dispatch(actions.updateTransactionParams(txData.id, txData.txParams))
- dispatch(actions.clearSend())
if (err) {
dispatch(actions.txError(err))
dispatch(actions.goHome())
return log.error(err.message)
}
- dispatch(actions.completedTx(txData.id))
+ dispatch(actions.showConfTxPage({ id: txData.id }))
})
}
}
-function updateAndCancelTx (txData) {
- log.info('actions: updateAndCancelTx: ' + JSON.stringify(txData))
+function updateAndApproveTx (txData) {
+ log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
return (dispatch) => {
- log.debug(`actions calling background.updateAndCancelTx`)
- background.updateAndCancelTransaction(txData, (err) => {
+ log.debug(`actions calling background.updateAndApproveTx`)
+ background.updateAndApproveTransaction(txData, (err) => {
dispatch(actions.hideLoadingIndication())
dispatch(actions.updateTransactionParams(txData.id, txData.txParams))
dispatch(actions.clearSend())
@@ -773,6 +772,7 @@ function cancelTx (txData) {
return (dispatch) => {
log.debug(`background.cancelTransaction`)
background.cancelTransaction(txData.id, () => {
+ dispatch(actions.clearSend())
dispatch(actions.completedTx(txData.id))
})
}
diff --git a/ui/app/components/pending-tx/confirm-send-ether.js b/ui/app/components/pending-tx/confirm-send-ether.js
index 01195502e..566224864 100644
--- a/ui/app/components/pending-tx/confirm-send-ether.js
+++ b/ui/app/components/pending-tx/confirm-send-ether.js
@@ -55,7 +55,6 @@ function mapDispatchToProps (dispatch) {
dispatch(actions.showSendPage())
},
cancelTransaction: ({ id }) => dispatch(actions.cancelTx({ id })),
- updateAndCancelTx: txMeta => dispatch(actions.updateAndCancelTx(txMeta)),
}
}
@@ -422,13 +421,9 @@ ConfirmSendEther.prototype.onSubmit = function (event) {
ConfirmSendEther.prototype.cancel = function (event, txMeta) {
event.preventDefault()
- const { send, updateAndCancelTx, cancelTransaction } = this.props
+ const { cancelTransaction } = this.props
- if (send.editingTransactionId) {
- updateAndCancelTx(txMeta)
- } else {
- cancelTransaction(txMeta)
- }
+ cancelTransaction(txMeta)
}
ConfirmSendEther.prototype.checkValidity = function () {
@@ -452,26 +447,6 @@ ConfirmSendEther.prototype.gatherTxMeta = function () {
const state = this.state
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)}`)
return txData
}
diff --git a/ui/app/components/pending-tx/confirm-send-token.js b/ui/app/components/pending-tx/confirm-send-token.js
index e6ce3f6e6..a07835911 100644
--- a/ui/app/components/pending-tx/confirm-send-token.js
+++ b/ui/app/components/pending-tx/confirm-send-token.js
@@ -89,7 +89,6 @@ function mapDispatchToProps (dispatch, ownProps) {
}))
dispatch(actions.showSendTokenPage())
},
- updateAndCancelTx: txMeta => dispatch(actions.updateAndCancelTx(txMeta)),
}
}
@@ -416,13 +415,9 @@ ConfirmSendToken.prototype.onSubmit = function (event) {
ConfirmSendToken.prototype.cancel = function (event, txMeta) {
event.preventDefault()
- const { send, updateAndCancelTx, cancelTransaction } = this.props
+ const { send, cancelTransaction } = this.props
- if (send.editingTransactionId) {
- updateAndCancelTx(txMeta)
- } else {
- cancelTransaction(txMeta)
- }
+ cancelTransaction(txMeta)
}
ConfirmSendToken.prototype.checkValidity = function () {
@@ -446,39 +441,6 @@ ConfirmSendToken.prototype.gatherTxMeta = function () {
const state = this.state
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)}`)
return txData
}
diff --git a/ui/app/components/send/send-v2-container.js b/ui/app/components/send/send-v2-container.js
index 655de8897..ff7714e82 100644
--- a/ui/app/components/send/send-v2-container.js
+++ b/ui/app/components/send/send-v2-container.js
@@ -50,6 +50,7 @@ function mapStateToProps (state) {
data,
amountConversionRate: selectedToken ? tokenToFiatRate : conversionRate,
tokenContract: getSelectedTokenContract(state),
+ unapprovedTxs: state.metamask.unapprovedTxs,
}
}
@@ -64,6 +65,7 @@ function mapDispatchToProps (dispatch) {
),
signTx: txParams => dispatch(actions.signTx(txParams)),
updateAndApproveTx: txParams => dispatch(actions.updateAndApproveTx(txParams)),
+ updateTx: txData => dispatch(actions.updateTransaction(txData)),
setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)),
addToAddressBook: address => dispatch(actions.addToAddressBook(address)),
updateGasTotal: newTotal => dispatch(actions.updateGasTotal(newTotal)),
diff --git a/ui/app/conf-tx.js b/ui/app/conf-tx.js
index 9f273aaec..d71e4b35f 100644
--- a/ui/app/conf-tx.js
+++ b/ui/app/conf-tx.js
@@ -115,7 +115,7 @@ function currentTxView (opts) {
log.info('rendering current tx view')
const { txData } = opts
const { txParams, msgParams } = txData
-
+ console.log(`22222 currentTxView txData`, txData);
if (txParams) {
log.debug('txParams detected, rendering pending tx')
return h(PendingTx, opts)
diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js
index e1b88f0db..617211b20 100644
--- a/ui/app/send-v2.js
+++ b/ui/app/send-v2.js
@@ -2,6 +2,7 @@ const { inherits } = require('util')
const PersistentForm = require('../lib/persistent-form')
const h = require('react-hyperscript')
+const ethAbi = require('ethereumjs-abi')
const ethUtil = require('ethereumjs-util')
const Identicon = require('./components/identicon')
@@ -552,6 +553,47 @@ 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]
+
+ editingTx.txParams = {
+ from: ethUtil.addHexPrefix(from),
+ gas: ethUtil.addHexPrefix(gas),
+ gasPrice: ethUtil.addHexPrefix(gasPrice),
+ }
+
+ if (selectedToken) {
+ const data = '0xa9059cbb' + 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) {
event.preventDefault()
const {
@@ -562,10 +604,12 @@ SendTransactionScreen.prototype.onSubmit = function (event) {
gasPrice,
signTokenTx,
signTx,
+ updateTx,
selectedToken,
editingTransactionId,
errors: { amount: amountError, to: toError },
backToConfirmScreen,
+ unapprovedTxs,
} = this.props
const noErrors = !amountError && toError === null
@@ -577,23 +621,25 @@ SendTransactionScreen.prototype.onSubmit = function (event) {
this.addToAddressBookIfNew(to)
if (editingTransactionId) {
- backToConfirmScreen(editingTransactionId)
- return
- }
+ const editedTx = this.getEditedTx()
- const txParams = {
- from,
- value: '0',
- gas,
- gasPrice,
- }
+ updateTx(editedTx)
+ } else {
- if (!selectedToken) {
- txParams.value = amount
- txParams.to = to
- }
+ const txParams = {
+ from,
+ value: '0',
+ gas,
+ gasPrice,
+ }
- selectedToken
- ? signTokenTx(selectedToken.address, to, amount, txParams)
- : signTx(txParams)
+ if (!selectedToken) {
+ txParams.value = amount
+ txParams.to = to
+ }
+
+ selectedToken
+ ? signTokenTx(selectedToken.address, to, amount, txParams)
+ : signTx(txParams)
+ }
}