diff options
author | Sergey Ukustov <sergey@ukstv.me> | 2017-10-03 07:10:47 +0800 |
---|---|---|
committer | Sergey Ukustov <sergey@ukstv.me> | 2017-10-03 07:10:47 +0800 |
commit | e11ca1289019123cd143adcb6312186452630723 (patch) | |
tree | 4debbc517ee74b3bc307def4f64aa98907571167 /app/scripts/lib | |
parent | 82d1f391986ac6f7cb7d9029f50d44b5a8c9442b (diff) | |
parent | b7c195160238119291ce62b01db1c8f7e4f94568 (diff) | |
download | tangerine-wallet-browser-e11ca1289019123cd143adcb6312186452630723.tar tangerine-wallet-browser-e11ca1289019123cd143adcb6312186452630723.tar.gz tangerine-wallet-browser-e11ca1289019123cd143adcb6312186452630723.tar.bz2 tangerine-wallet-browser-e11ca1289019123cd143adcb6312186452630723.tar.lz tangerine-wallet-browser-e11ca1289019123cd143adcb6312186452630723.tar.xz tangerine-wallet-browser-e11ca1289019123cd143adcb6312186452630723.tar.zst tangerine-wallet-browser-e11ca1289019123cd143adcb6312186452630723.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/pending-tx-tracker.js | 15 | ||||
-rw-r--r-- | app/scripts/lib/tx-state-history-helper.js | 10 | ||||
-rw-r--r-- | app/scripts/lib/tx-state-manager.js | 10 |
3 files changed, 12 insertions, 23 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js index b97cec9ce..3d358b00e 100644 --- a/app/scripts/lib/pending-tx-tracker.js +++ b/app/scripts/lib/pending-tx-tracker.js @@ -1,6 +1,5 @@ const EventEmitter = require('events') const EthQuery = require('ethjs-query') -const sufficientBalance = require('./util').sufficientBalance /* Utility class for tracking the transactions as they @@ -12,7 +11,6 @@ const sufficientBalance = require('./util').sufficientBalance requires a: { provider: //, nonceTracker: //see nonce tracker, - getBalnce: //(address) a function for getting balances, getPendingTransactions: //() a function for getting an array of transactions, publishTransaction: //(rawTx) a async function for publishing raw transactions, } @@ -25,7 +23,6 @@ module.exports = class PendingTransactionTracker extends EventEmitter { this.query = new EthQuery(config.provider) this.nonceTracker = config.nonceTracker this.retryLimit = config.retryLimit || Infinity - this.getBalance = config.getBalance this.getPendingTransactions = config.getPendingTransactions this.publishTransaction = config.publishTransaction } @@ -99,23 +96,11 @@ module.exports = class PendingTransactionTracker extends EventEmitter { } async _resubmitTx (txMeta) { - const address = txMeta.txParams.from - const balance = this.getBalance(address) - if (balance === undefined) return - if (txMeta.retryCount > this.retryLimit) { const err = new Error(`Gave up submitting after ${this.retryLimit} blocks un-mined.`) return this.emit('tx:failed', txMeta.id, err) } - // if the value of the transaction is greater then the balance, fail. - if (!sufficientBalance(txMeta.txParams, balance)) { - const insufficientFundsError = new Error('Insufficient balance during rebroadcast.') - this.emit('tx:failed', txMeta.id, insufficientFundsError) - log.error(insufficientFundsError) - return - } - // Only auto-submit already-signed txs: if (!('rawTx' in txMeta)) return diff --git a/app/scripts/lib/tx-state-history-helper.js b/app/scripts/lib/tx-state-history-helper.js index 304069d57..db6e3bc9f 100644 --- a/app/scripts/lib/tx-state-history-helper.js +++ b/app/scripts/lib/tx-state-history-helper.js @@ -20,11 +20,15 @@ function migrateFromSnapshotsToDiffs(longHistory) { ) } -function generateHistoryEntry(previousState, newState) { - return jsonDiffer.compare(previousState, newState) +function generateHistoryEntry(previousState, newState, note) { + const entry = jsonDiffer.compare(previousState, newState) + // Add a note to the first op, since it breaks if we append it to the entry + if (note && entry[0]) entry[0].note = note + return entry } -function replayHistory(shortHistory) { +function replayHistory(_shortHistory) { + const shortHistory = clone(_shortHistory) return shortHistory.reduce((val, entry) => jsonDiffer.applyPatch(val, entry).newDocument) } diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index abb9d7910..cf8117864 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -82,7 +82,7 @@ module.exports = class TransactionStateManger extends EventEmitter { return txMeta } - updateTx (txMeta) { + updateTx (txMeta, note) { if (txMeta.txParams) { Object.keys(txMeta.txParams).forEach((key) => { let value = txMeta.txParams[key] @@ -96,8 +96,8 @@ module.exports = class TransactionStateManger extends EventEmitter { // 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) + const entry = txStateHistoryHelper.generateHistoryEntry(previousState, currentState, note) + txMeta.history.push(entry) // commit txMeta to state const txId = txMeta.id @@ -113,7 +113,7 @@ module.exports = class TransactionStateManger extends EventEmitter { updateTxParams (txId, txParams) { const txMeta = this.getTx(txId) txMeta.txParams = extend(txMeta.txParams, txParams) - this.updateTx(txMeta) + this.updateTx(txMeta, `txStateManager#updateTxParams`) } /* @@ -233,7 +233,7 @@ module.exports = class TransactionStateManger extends EventEmitter { if (status === 'submitted' || status === 'rejected') { this.emit(`${txMeta.id}:finished`, txMeta) } - this.updateTx(txMeta) + this.updateTx(txMeta, `txStateManager: setting status to ${status}`) this.emit('update:badge') } |