aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/send-v2.js
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/app/send-v2.js
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/app/send-v2.js')
-rw-r--r--ui/app/send-v2.js78
1 files changed, 62 insertions, 16 deletions
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)
+ }
}