aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2017-10-04 07:02:58 +0800
committerGitHub <noreply@github.com>2017-10-04 07:02:58 +0800
commitbd99bc2e88b44b13ca818fbba478bd74eef222e3 (patch)
tree8a653f7015c89305d5c1d35ffc70ab52a30ddb0c /app/scripts/lib
parentac4868170f4c61d13291389d01bf1002fe240ed4 (diff)
parentf12504cd09f136fb5ac0d4dd2a6afab8fa6e6524 (diff)
downloadtangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar.gz
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar.zst
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.zip
Merge branch 'master' into NewUI-flat
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/pending-tx-tracker.js27
-rw-r--r--app/scripts/lib/tx-state-history-helper.js10
-rw-r--r--app/scripts/lib/tx-state-manager.js10
3 files changed, 19 insertions, 28 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js
index b97cec9ce..6f1601586 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
}
@@ -89,33 +86,24 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
// other
|| errorMessage.includes('gateway timeout')
|| errorMessage.includes('nonce too low')
- || txMeta.retryCount > 1
)
// ignore resubmit warnings, return early
if (isKnownTx) return
// encountered real error - transition to error state
- this.emit('tx:failed', txMeta.id, err)
+ txMeta.warning = {
+ error: errorMessage,
+ message: 'There was an error when resubmitting this transaction.',
+ }
+ this.emit('tx:warning', txMeta, err)
}))
}
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
@@ -148,11 +136,10 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
}
} catch (err) {
txMeta.warning = {
- error: err,
+ error: err.message,
message: 'There was a problem loading this transaction.',
}
- this.emit('tx:warning', txMeta)
- throw err
+ this.emit('tx:warning', txMeta, err)
}
}
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')
}