aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/tx-state-manager.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/lib/tx-state-manager.js')
-rw-r--r--app/scripts/lib/tx-state-manager.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index 378ea38ab..d3314c286 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -1,6 +1,6 @@
-const clone = require('clone')
const extend = require('xtend')
const ObservableStore = require('obs-store')
+const txStateHistoryHelper = require('./tx-state-history-helper')
module.exports = class TransactionStateManger extends ObservableStore {
constructor ({initState, txHistoryLimit, getNetwork}) {
@@ -41,6 +41,11 @@ module.exports = class TransactionStateManger extends ObservableStore {
this.once(`${txMeta.id}:rejected`, function (txId) {
this.removeAllListeners(`${txMeta.id}:signed`)
})
+ // initialize history
+ txMeta.history = []
+ // capture initial snapshot of txMeta for history
+ const snapshot = txStateHistoryHelper.snapshotFromTxMeta(txMeta)
+ txMeta.history.push(snapshot)
const transactions = this.getFullTxList()
const txCount = this.getTxCount()
@@ -57,6 +62,7 @@ module.exports = class TransactionStateManger extends ObservableStore {
}
transactions.push(txMeta)
this._saveTxList(transactions)
+ return txMeta
}
// gets tx by Id and returns it
getTx (txId) {
@@ -66,19 +72,17 @@ module.exports = class TransactionStateManger extends ObservableStore {
updateTx (txMeta) {
// create txMeta snapshot for history
- const txMetaForHistory = clone(txMeta)
- // dont include previous history in this snapshot
- delete txMetaForHistory.history
- // add snapshot to tx history
- if (!txMeta.history) txMeta.history = []
- txMeta.history.push(txMetaForHistory)
-
+ const currentState = txStateHistoryHelper.snapshotFromTxMeta(txMeta)
+ // recover previous tx state obj
+ const previousState = txStateHistoryHelper.replayHistory(txMeta.history)
+ // generate history entry and add to history
+ const entry = txStateHistoryHelper.generateHistoryEntry(previousState, currentState)
+ txMeta.history.push(entry)
+
+ // commit txMeta to state
const txId = txMeta.id
const txList = this.getFullTxList()
const index = txList.findIndex(txData => txData.id === txId)
- if (!txMeta.history) txMeta.history = []
- txMeta.history.push(txMetaForHistory)
-
txList[index] = txMeta
this._saveTxList(txList)
}