aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2018-02-28 07:14:18 +0800
committerfrankiebee <frankie.diamond@gmail.com>2018-03-08 09:16:16 +0800
commit62febac87659ddf78a34dd0dac1ee8a38d8c8e77 (patch)
treedbaad0f640c011cf97e9a8ccdbd5ba816dba7e9e /app/scripts/lib
parent33373b676f4d6ddfa95caa18683cef0be4b6327a (diff)
downloadtangerine-wallet-browser-62febac87659ddf78a34dd0dac1ee8a38d8c8e77.tar
tangerine-wallet-browser-62febac87659ddf78a34dd0dac1ee8a38d8c8e77.tar.gz
tangerine-wallet-browser-62febac87659ddf78a34dd0dac1ee8a38d8c8e77.tar.bz2
tangerine-wallet-browser-62febac87659ddf78a34dd0dac1ee8a38d8c8e77.tar.lz
tangerine-wallet-browser-62febac87659ddf78a34dd0dac1ee8a38d8c8e77.tar.xz
tangerine-wallet-browser-62febac87659ddf78a34dd0dac1ee8a38d8c8e77.tar.zst
tangerine-wallet-browser-62febac87659ddf78a34dd0dac1ee8a38d8c8e77.zip
refactor retrytx with higher gas price:
- create a new tx instead of overwriting the tx hash - add a new state 'dropped' to the txStateManager - mark duplicate txs as dropped when one gets confirmed in a block
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/tx-state-manager.js38
1 files changed, 28 insertions, 10 deletions
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index 051efd247..25442ce47 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -1,9 +1,21 @@
const extend = require('xtend')
const EventEmitter = require('events')
const ObservableStore = require('obs-store')
+const createId = require('./random-id')
const ethUtil = require('ethereumjs-util')
const txStateHistoryHelper = require('./tx-state-history-helper')
+// STATUS METHODS
+ // statuses:
+ // - `'unapproved'` the user has not responded
+ // - `'rejected'` the user has responded no!
+ // - `'approved'` the user has approved the tx
+ // - `'signed'` the tx is signed
+ // - `'submitted'` the tx is sent to a server
+ // - `'confirmed'` the tx has been included in a block.
+ // - `'failed'` the tx failed for some reason, included on tx data.
+ // - `'dropped'` the tx nonce was already used
+
module.exports = class TransactionStateManger extends EventEmitter {
constructor ({ initState, txHistoryLimit, getNetwork }) {
super()
@@ -16,6 +28,16 @@ module.exports = class TransactionStateManger extends EventEmitter {
this.getNetwork = getNetwork
}
+ generateTxMeta (opts) {
+ return extend({
+ id: createId(),
+ time: (new Date()).getTime(),
+ status: 'unapproved',
+ metamaskNetworkId: this.getNetwork(),
+ loadingDefaults: true,
+ }, opts)
+ }
+
// Returns the number of txs for the current network.
getTxCount () {
return this.getTxList().length
@@ -164,16 +186,6 @@ module.exports = class TransactionStateManger extends EventEmitter {
})
}
- // STATUS METHODS
- // statuses:
- // - `'unapproved'` the user has not responded
- // - `'rejected'` the user has responded no!
- // - `'approved'` the user has approved the tx
- // - `'signed'` the tx is signed
- // - `'submitted'` the tx is sent to a server
- // - `'confirmed'` the tx has been included in a block.
- // - `'failed'` the tx failed for some reason, included on tx data.
-
// get::set status
// should return the status of the tx.
@@ -211,6 +223,12 @@ module.exports = class TransactionStateManger extends EventEmitter {
this._setTxStatus(txId, 'confirmed')
}
+ // should update the status dropped
+ setTxStatusDropped (txId) {
+ this._setTxStatus(txId, 'dropped')
+ }
+
+
setTxStatusFailed (txId, err) {
const txMeta = this.getTx(txId)
txMeta.err = {