aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-07-12 03:29:20 +0800
committerGitHub <noreply@github.com>2017-07-12 03:29:20 +0800
commita1fd9bc6bebcad4421a10ab85f525b9686103549 (patch)
tree01ac51e1506cd5c7a989cb6e071982e72f1714b4
parent0eee232e26dec61512e36bedf131ce0f7ce1ddd4 (diff)
parentc7b9e3fb1878cebbab26d5343cc18084a601c6bb (diff)
downloadtangerine-wallet-browser-a1fd9bc6bebcad4421a10ab85f525b9686103549.tar
tangerine-wallet-browser-a1fd9bc6bebcad4421a10ab85f525b9686103549.tar.gz
tangerine-wallet-browser-a1fd9bc6bebcad4421a10ab85f525b9686103549.tar.bz2
tangerine-wallet-browser-a1fd9bc6bebcad4421a10ab85f525b9686103549.tar.lz
tangerine-wallet-browser-a1fd9bc6bebcad4421a10ab85f525b9686103549.tar.xz
tangerine-wallet-browser-a1fd9bc6bebcad4421a10ab85f525b9686103549.tar.zst
tangerine-wallet-browser-a1fd9bc6bebcad4421a10ab85f525b9686103549.zip
Merge pull request #1762 from MetaMask/ImproveRetryLogic
Improve retry logic
-rw-r--r--CHANGELOG.md3
-rw-r--r--app/scripts/controllers/transactions.js13
-rw-r--r--app/scripts/lib/tx-utils.js9
-rw-r--r--test/unit/tx-utils-test.js38
4 files changed, 51 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 696d68345..395454b41 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,9 @@
## Current Master
+- No longer validate nonce client-side in retry loop.
+- Fix bug where insufficient balance error was sometimes shown on successful transactions.
+
## 3.8.4 2017-7-7
- Improve transaction resubmit logic to fail more eagerly when a user would expect it to.
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index c0d4841a9..43735a691 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -447,27 +447,16 @@ module.exports = class TransactionController extends EventEmitter {
_resubmitTx (txMeta, cb) {
const address = txMeta.txParams.from
const balance = this.ethStore.getState().accounts[address].balance
- const nonce = Number.parseInt(this.ethStore.getState().accounts[address].nonce)
- const txNonce = Number.parseInt(txMeta.txParams.nonce)
- const gtBalance = Number.parseInt(txMeta.txParams.value) > Number.parseInt(balance)
if (!('retryCount' in txMeta)) txMeta.retryCount = 0
// if the value of the transaction is greater then the balance, fail.
- if (gtBalance) {
+ if (!this.txProviderUtils.sufficientBalance(txMeta.txParams, balance)) {
const message = 'Insufficient balance.'
this.setTxStatusFailed(txMeta.id, { message })
cb()
return log.error(message)
}
- // if the nonce of the transaction is lower then the accounts nonce, fail.
- if (txNonce < nonce) {
- const message = 'Invalid nonce.'
- this.setTxStatusFailed(txMeta.id, { message })
- cb()
- return log.error(message)
- }
-
// Only auto-submit already-signed txs:
if (!('rawTx' in txMeta)) return cb()
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 149d93102..4e780fcc0 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -118,6 +118,15 @@ module.exports = class txProviderUtils {
}
}
+ sufficientBalance (tx, hexBalance) {
+ const balance = hexToBn(hexBalance)
+ const value = hexToBn(tx.value)
+ const gasLimit = hexToBn(tx.gas)
+ const gasPrice = hexToBn(tx.gasPrice)
+
+ const maxCost = value.add(gasLimit.mul(gasPrice))
+ return balance.gte(maxCost)
+ }
}
diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js
index 7ace1f587..a43bcfb35 100644
--- a/test/unit/tx-utils-test.js
+++ b/test/unit/tx-utils-test.js
@@ -16,6 +16,44 @@ describe('txUtils', function () {
}))
})
+ describe('#sufficientBalance', function () {
+ it('returns true if max tx cost is equal to balance.', function () {
+ const tx = {
+ 'value': '0x1',
+ 'gas': '0x2',
+ 'gasPrice': '0x3',
+ }
+ const balance = '0x8'
+
+ const result = txUtils.sufficientBalance(tx, balance)
+ assert.ok(result, 'sufficient balance found.')
+ })
+
+ it('returns true if max tx cost is less than balance.', function () {
+ const tx = {
+ 'value': '0x1',
+ 'gas': '0x2',
+ 'gasPrice': '0x3',
+ }
+ const balance = '0x9'
+
+ const result = txUtils.sufficientBalance(tx, balance)
+ assert.ok(result, 'sufficient balance found.')
+ })
+
+ it('returns false if max tx cost is more than balance.', function () {
+ const tx = {
+ 'value': '0x1',
+ 'gas': '0x2',
+ 'gasPrice': '0x3',
+ }
+ const balance = '0x6'
+
+ const result = txUtils.sufficientBalance(tx, balance)
+ assert.ok(!result, 'insufficient balance found.')
+ })
+ })
+
describe('chain Id', function () {
it('prepares a transaction with the provided chainId', function () {
const txParams = {