aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers/transactions
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-10-21 11:48:10 +0800
committerGitHub <noreply@github.com>2018-10-21 11:48:10 +0800
commit3b46478024f87bd237b507e5fb18068febf02de9 (patch)
tree1b70c2e7f431e7e3eb638c7630a2d220fa3dd030 /app/scripts/controllers/transactions
parent600f755dbf8d4cfdc152e3d521b537ee9a046a35 (diff)
parentba3617b685b9dcd8a62e0009ee2015c5997fead3 (diff)
downloadtangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.gz
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.bz2
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.lz
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.xz
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.tar.zst
tangerine-wallet-browser-3b46478024f87bd237b507e5fb18068febf02de9.zip
Merge branch 'develop' into develop
Diffstat (limited to 'app/scripts/controllers/transactions')
-rw-r--r--app/scripts/controllers/transactions/index.js39
-rw-r--r--app/scripts/controllers/transactions/tx-state-manager.js5
2 files changed, 43 insertions, 1 deletions
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index ebd49f882..9f2290924 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -166,6 +166,10 @@ class TransactionController extends EventEmitter {
async addUnapprovedTransaction (txParams) {
// validate
const normalizedTxParams = txUtils.normalizeTxParams(txParams)
+ // Assert the from address is the selected address
+ if (normalizedTxParams.from !== this.getSelectedAddress()) {
+ throw new Error(`Transaction from address isn't valid for this account`)
+ }
txUtils.validateTxParams(normalizedTxParams)
// construct txMeta
let txMeta = this.txStateManager.generateTxMeta({
@@ -362,7 +366,40 @@ class TransactionController extends EventEmitter {
this.txStateManager.setTxStatusSubmitted(txId)
}
- confirmTransaction (txId) {
+ /**
+ * Sets the status of the transaction to confirmed and sets the status of nonce duplicates as
+ * dropped if the txParams have data it will fetch the txReceipt
+ * @param {number} txId - The tx's ID
+ * @returns {Promise<void>}
+ */
+ async confirmTransaction (txId) {
+ // get the txReceipt before marking the transaction confirmed
+ // to ensure the receipt is gotten before the ui revives the tx
+ const txMeta = this.txStateManager.getTx(txId)
+
+ if (!txMeta) {
+ return
+ }
+
+ try {
+ const txReceipt = await this.query.getTransactionReceipt(txMeta.hash)
+
+ // It seems that sometimes the numerical values being returned from
+ // this.query.getTransactionReceipt are BN instances and not strings.
+ const gasUsed = typeof txReceipt.gasUsed !== 'string'
+ ? txReceipt.gasUsed.toString(16)
+ : txReceipt.gasUsed
+
+ txMeta.txReceipt = {
+ ...txReceipt,
+ gasUsed,
+ }
+
+ this.txStateManager.updateTx(txMeta, 'transactions#confirmTransaction - add txReceipt')
+ } catch (err) {
+ log.error(err)
+ }
+
this.txStateManager.setTxStatusConfirmed(txId)
this._markNonceDuplicatesDropped(txId)
}
diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js
index daa6cc388..58c48e34e 100644
--- a/app/scripts/controllers/transactions/tx-state-manager.js
+++ b/app/scripts/controllers/transactions/tx-state-manager.js
@@ -400,6 +400,11 @@ class TransactionStateManager extends EventEmitter {
*/
_setTxStatus (txId, status) {
const txMeta = this.getTx(txId)
+
+ if (!txMeta) {
+ return
+ }
+
txMeta.status = status
setTimeout(() => {
try {