aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/tx-state-manager.js
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-22 02:35:22 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-22 02:35:22 +0800
commitfbba3a1ac8575b910e8a2a684748d617eec19414 (patch)
treec2940c33345d128a2888fc4441b8342e6b778d65 /app/scripts/lib/tx-state-manager.js
parent7ea83b6bae34dcf652d85474fe1d82893d592d55 (diff)
parent9203b4edf9df8b616877c57970fb01a7fb87924b (diff)
downloadtangerine-wallet-browser-fbba3a1ac8575b910e8a2a684748d617eec19414.tar.gz
tangerine-wallet-browser-fbba3a1ac8575b910e8a2a684748d617eec19414.tar.zst
tangerine-wallet-browser-fbba3a1ac8575b910e8a2a684748d617eec19414.zip
Merge branch 'master' into transactionControllerRefractorPt3
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)
}