aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-08-15 09:46:04 +0800
committerkumavis <aaron@kumavis.me>2017-08-15 09:46:04 +0800
commitfdffb6fedc6a29a2f952f7db669bdc2907afb854 (patch)
tree35a996001d2e32950c1e7bd0ee8fb37d0b345bd8 /app/scripts/controllers
parent68c6b2d666719476bff78cbc107a56be3b86dbe1 (diff)
downloadtangerine-wallet-browser-fdffb6fedc6a29a2f952f7db669bdc2907afb854.tar.gz
tangerine-wallet-browser-fdffb6fedc6a29a2f952f7db669bdc2907afb854.tar.zst
tangerine-wallet-browser-fdffb6fedc6a29a2f952f7db669bdc2907afb854.zip
introduce tx-state-history-helper and diff-based history
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/transactions.js34
1 files changed, 19 insertions, 15 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 58c468e22..872d11b50 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -8,6 +8,7 @@ const TxProviderUtil = require('../lib/tx-utils')
const PendingTransactionTracker = require('../lib/pending-tx-tracker')
const createId = require('../lib/random-id')
const NonceTracker = require('../lib/nonce-tracker')
+const txStateHistoryHelper = require('../lib/tx-state-history-helper')
module.exports = class TransactionController extends EventEmitter {
constructor (opts) {
@@ -128,19 +129,17 @@ module.exports = class TransactionController extends EventEmitter {
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)
this.emit('update')
@@ -148,16 +147,22 @@ module.exports = class TransactionController extends EventEmitter {
// Adds a tx to the txlist
addTx (txMeta) {
- const txCount = this.getTxCount()
- const network = this.getNetwork()
- const fullTxList = this.getFullTxList()
- const txHistoryLimit = this.txHistoryLimit
+ // initialize history
+ txMeta.history = []
+ // capture initial snapshot of txMeta for history
+ const snapshot = txStateHistoryHelper.snapshotFromTxMeta(txMeta)
+ txMeta.history.push(snapshot)
// checks if the length of the tx history is
// longer then desired persistence limit
// and then if it is removes only confirmed
// or rejected tx's.
// not tx's that are pending or unapproved
+ const txCount = this.getTxCount()
+ const network = this.getNetwork()
+ const fullTxList = this.getFullTxList()
+ const txHistoryLimit = this.txHistoryLimit
+
if (txCount > txHistoryLimit - 1) {
const index = fullTxList.findIndex((metaTx) => ((metaTx.status === 'confirmed' || metaTx.status === 'rejected') && network === txMeta.metamaskNetworkId))
fullTxList.splice(index, 1)
@@ -206,7 +211,6 @@ module.exports = class TransactionController extends EventEmitter {
status: 'unapproved',
metamaskNetworkId: this.getNetwork(),
txParams: txParams,
- history: [],
}
// add default tx params
await this.addTxDefaults(txMeta)