aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/transaction-manager.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-02-03 12:20:13 +0800
committerkumavis <aaron@kumavis.me>2017-02-03 12:20:13 +0800
commit99fa9ab13aaf69cb8602612816a4df49209fa8a6 (patch)
tree251c246d4b31187ff27a8c3c1537a5ff6a5d8358 /app/scripts/transaction-manager.js
parentbcb86f38cbe91fb814d30b3129de76dba45bff66 (diff)
downloadtangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar.gz
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar.bz2
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar.lz
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar.xz
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.tar.zst
tangerine-wallet-browser-99fa9ab13aaf69cb8602612816a4df49209fa8a6.zip
migration 7 - break off TransactionManager substate
Diffstat (limited to 'app/scripts/transaction-manager.js')
-rw-r--r--app/scripts/transaction-manager.js54
1 files changed, 38 insertions, 16 deletions
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js
index 6fecdba39..7949fb854 100644
--- a/app/scripts/transaction-manager.js
+++ b/app/scripts/transaction-manager.js
@@ -2,6 +2,7 @@ const EventEmitter = require('events')
const async = require('async')
const extend = require('xtend')
const Semaphore = require('semaphore')
+const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const BN = require('ethereumjs-util').BN
const TxProviderUtil = require('./lib/tx-utils')
@@ -10,33 +11,46 @@ const createId = require('./lib/random-id')
module.exports = class TransactionManager extends EventEmitter {
constructor (opts) {
super()
- this.txList = opts.txList || []
- this._setTxList = opts.setTxList
+ this.store = new ObservableStore(extend({
+ txList: [],
+ gasMultiplier: 1,
+ }, opts.initState))
+ this.memStore = new ObservableStore({})
+ // this.networkStore = opts.networkStore || new ObservableStore({})
+ this.getNetwork = opts.getNetwork
+
this.txHistoryLimit = opts.txHistoryLimit
this.getSelectedAddress = opts.getSelectedAddress
this.provider = opts.provider
this.blockTracker = opts.blockTracker
this.txProviderUtils = new TxProviderUtil(this.provider)
this.blockTracker.on('block', this.checkForTxInBlock.bind(this))
- this.getGasMultiplier = opts.getGasMultiplier
- this.getNetwork = opts.getNetwork
this.signEthTx = opts.signTransaction
this.nonceLock = Semaphore(1)
+
+ // memstore is computed from diskStore
+ this._updateMemstore()
+ this.store.subscribe(() => this._updateMemstore() )
+ // this.networkStore.subscribe(() => this._updateMemstore() )
}
getState () {
- var selectedAddress = this.getSelectedAddress()
- return {
- transactions: this.getTxList(),
- unapprovedTxs: this.getUnapprovedTxList(),
- selectedAddressTxList: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAddress}),
- }
+ return this.memStore.getState()
}
-// Returns the tx list
+ // Returns the tx list
getTxList () {
let network = this.getNetwork()
- return this.txList.filter(txMeta => txMeta.metamaskNetworkId === network)
+ let fullTxList = this.store.getState().txList
+ return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network)
+ }
+
+ getGasMultiplier () {
+ return this.store.getState().gasMultiplier
+ }
+
+ setGasMultiplier (gasMultiplier) {
+ return this.store.updateState({ gasMultiplier })
}
// Adds a tx to the txlist
@@ -108,7 +122,7 @@ module.exports = class TransactionManager extends EventEmitter {
id: txId,
time: time,
status: 'unapproved',
- gasMultiplier: this.getGasMultiplier() || 1,
+ gasMultiplier: this.getGasMultiplier(),
metamaskNetworkId: this.getNetwork(),
txParams: txParams,
}
@@ -239,7 +253,7 @@ module.exports = class TransactionManager extends EventEmitter {
getTxsByMetaData (key, value, txList = this.getTxList()) {
return txList.filter((txMeta) => {
- if (key in txMeta.txParams) {
+ if (txMeta.txParams[key]) {
return txMeta.txParams[key] === value
} else {
return txMeta[key] === value
@@ -352,8 +366,16 @@ module.exports = class TransactionManager extends EventEmitter {
// Saves the new/updated txList.
// Function is intended only for internal use
_saveTxList (txList) {
- this.txList = txList
- this._setTxList(txList)
+ this.store.updateState({ txList })
+ }
+
+ _updateMemstore () {
+ const unapprovedTxs = this.getUnapprovedTxList()
+ const selectedAddressTxList = this.getFilteredTxList({
+ from: this.getSelectedAddress(),
+ metamaskNetworkId: this.getNetwork(),
+ })
+ this.memStore.updateState({ unapprovedTxs, selectedAddressTxList })
}
}