aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/_locales/en/messages.json7
-rw-r--r--app/scripts/controllers/network/network.js11
-rw-r--r--app/scripts/controllers/transactions/index.js9
-rw-r--r--app/scripts/controllers/transactions/nonce-tracker.js54
-rw-r--r--app/scripts/controllers/transactions/pending-tx-tracker.js4
-rw-r--r--app/scripts/metamask-controller.js39
6 files changed, 78 insertions, 46 deletions
diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json
index 40d362f51..457c3c3b1 100644
--- a/app/_locales/en/messages.json
+++ b/app/_locales/en/messages.json
@@ -253,6 +253,9 @@
"editAccountName": {
"message": "Edit Account Name"
},
+ "editingTransaction": {
+ "message": "Make changes to your transaction"
+ },
"emailUs": {
"message": "Email us!"
},
@@ -771,6 +774,10 @@
"onlySendToEtherAddress": {
"message": "Only send ETH to an Ethereum address."
},
+ "onlySendTokensToAccountAddress": {
+ "message": "Only send $1 to an Ethereum account address.",
+ "description": "displays token symbol"
+ },
"searchTokens": {
"message": "Search Tokens"
},
diff --git a/app/scripts/controllers/network/network.js b/app/scripts/controllers/network/network.js
index 93fde7c57..5e0c63e7d 100644
--- a/app/scripts/controllers/network/network.js
+++ b/app/scripts/controllers/network/network.js
@@ -89,14 +89,21 @@ module.exports = class NetworkController extends EventEmitter {
type: 'rpc',
rpcTarget,
}
- this.providerStore.updateState(providerConfig)
- this._switchNetwork(providerConfig)
+ this.providerConfig = providerConfig
}
async setProviderType (type) {
assert.notEqual(type, 'rpc', `NetworkController - cannot call "setProviderType" with type 'rpc'. use "setRpcTarget"`)
assert(INFURA_PROVIDER_TYPES.includes(type) || type === LOCALHOST, `NetworkController - Unknown rpc type "${type}"`)
const providerConfig = { type }
+ this.providerConfig = providerConfig
+ }
+
+ resetConnection () {
+ this.providerConfig = this.getProviderConfig()
+ }
+
+ set providerConfig (providerConfig) {
this.providerStore.updateState(providerConfig)
this._switchNetwork(providerConfig)
}
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index b53947e27..8e2288aed 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -165,7 +165,7 @@ class TransactionController extends EventEmitter {
// add default tx params
txMeta = await this.addTxGasDefaults(txMeta)
} catch (error) {
- console.log(error)
+ log.warn(error)
this.txStateManager.setTxStatusFailed(txMeta.id, error)
throw error
}
@@ -264,7 +264,12 @@ class TransactionController extends EventEmitter {
// must set transaction to submitted/failed before releasing lock
nonceLock.releaseLock()
} catch (err) {
- this.txStateManager.setTxStatusFailed(txId, err)
+ // this is try-catch wrapped so that we can guarantee that the nonceLock is released
+ try {
+ this.txStateManager.setTxStatusFailed(txId, err)
+ } catch (err) {
+ log.error(err)
+ }
// must set transaction to submitted/failed before releasing lock
if (nonceLock) nonceLock.releaseLock()
// continue with error chain
diff --git a/app/scripts/controllers/transactions/nonce-tracker.js b/app/scripts/controllers/transactions/nonce-tracker.js
index f8cdc5523..35ca08d6c 100644
--- a/app/scripts/controllers/transactions/nonce-tracker.js
+++ b/app/scripts/controllers/transactions/nonce-tracker.js
@@ -49,29 +49,35 @@ class NonceTracker {
await this._globalMutexFree()
// await lock free, then take lock
const releaseLock = await this._takeMutex(address)
- // evaluate multiple nextNonce strategies
- const nonceDetails = {}
- const networkNonceResult = await this._getNetworkNextNonce(address)
- const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address)
- const nextNetworkNonce = networkNonceResult.nonce
- const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed)
-
- const pendingTxs = this.getPendingTransactions(address)
- const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0
-
- nonceDetails.params = {
- highestLocallyConfirmed,
- highestSuggested,
- nextNetworkNonce,
+ try {
+ // evaluate multiple nextNonce strategies
+ const nonceDetails = {}
+ const networkNonceResult = await this._getNetworkNextNonce(address)
+ const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address)
+ const nextNetworkNonce = networkNonceResult.nonce
+ const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed)
+
+ const pendingTxs = this.getPendingTransactions(address)
+ const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0
+
+ nonceDetails.params = {
+ highestLocallyConfirmed,
+ highestSuggested,
+ nextNetworkNonce,
+ }
+ nonceDetails.local = localNonceResult
+ nonceDetails.network = networkNonceResult
+
+ const nextNonce = Math.max(networkNonceResult.nonce, localNonceResult.nonce)
+ assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
+
+ // return nonce and release cb
+ return { nextNonce, nonceDetails, releaseLock }
+ } catch (err) {
+ // release lock if we encounter an error
+ releaseLock()
+ throw err
}
- nonceDetails.local = localNonceResult
- nonceDetails.network = networkNonceResult
-
- const nextNonce = Math.max(networkNonceResult.nonce, localNonceResult.nonce)
- assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
-
- // return nonce and release cb
- return { nextNonce, nonceDetails, releaseLock }
}
async _getCurrentBlock () {
@@ -85,8 +91,8 @@ class NonceTracker {
async _globalMutexFree () {
const globalMutex = this._lookupMutex('global')
- const release = await globalMutex.acquire()
- release()
+ const releaseLock = await globalMutex.acquire()
+ releaseLock()
}
async _takeMutex (lockId) {
diff --git a/app/scripts/controllers/transactions/pending-tx-tracker.js b/app/scripts/controllers/transactions/pending-tx-tracker.js
index 6e2fcb40b..4e41cdaf8 100644
--- a/app/scripts/controllers/transactions/pending-tx-tracker.js
+++ b/app/scripts/controllers/transactions/pending-tx-tracker.js
@@ -196,14 +196,14 @@ class PendingTransactionTracker extends EventEmitter {
async _checkPendingTxs () {
const signedTxList = this.getPendingTransactions()
// in order to keep the nonceTracker accurate we block it while updating pending transactions
- const nonceGlobalLock = await this.nonceTracker.getGlobalLock()
+ const { releaseLock } = await this.nonceTracker.getGlobalLock()
try {
await Promise.all(signedTxList.map((txMeta) => this._checkPendingTx(txMeta)))
} catch (err) {
log.error('PendingTransactionWatcher - Error updating pending transactions')
log.error(err)
}
- nonceGlobalLock.releaseLock()
+ releaseLock()
}
/**
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 1bb0af5ee..e444180cc 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -394,6 +394,8 @@ module.exports = class MetamaskController extends EventEmitter {
updateAndApproveTransaction: nodeify(txController.updateAndApproveTransaction, txController),
retryTransaction: nodeify(this.retryTransaction, this),
getFilteredTxList: nodeify(txController.getFilteredTxList, txController),
+ isNonceTaken: nodeify(txController.isNonceTaken, txController),
+ estimateGas: nodeify(this.estimateGas, this),
// messageManager
signMessage: nodeify(this.signMessage, this),
@@ -434,28 +436,24 @@ module.exports = class MetamaskController extends EventEmitter {
* @returns {Object} vault
*/
async createNewVaultAndKeychain (password) {
- const release = await this.createVaultMutex.acquire()
- let vault
-
+ const releaseLock = await this.createVaultMutex.acquire()
try {
+ let vault
const accounts = await this.keyringController.getAccounts()
-
if (accounts.length > 0) {
vault = await this.keyringController.fullUpdate()
-
} else {
vault = await this.keyringController.createNewVaultAndKeychain(password)
const accounts = await this.keyringController.getAccounts()
this.preferencesController.setAddresses(accounts)
this.selectFirstIdentity()
}
- release()
+ releaseLock()
+ return vault
} catch (err) {
- release()
+ releaseLock()
throw err
}
-
- return vault
}
/**
@@ -464,7 +462,7 @@ module.exports = class MetamaskController extends EventEmitter {
* @param {} seed
*/
async createNewVaultAndRestore (password, seed) {
- const release = await this.createVaultMutex.acquire()
+ const releaseLock = await this.createVaultMutex.acquire()
try {
// clear known identities
this.preferencesController.setAddresses([])
@@ -474,10 +472,10 @@ module.exports = class MetamaskController extends EventEmitter {
const accounts = await this.keyringController.getAccounts()
this.preferencesController.setAddresses(accounts)
this.selectFirstIdentity()
- release()
+ releaseLock()
return vault
} catch (err) {
- release()
+ releaseLock()
throw err
}
}
@@ -628,10 +626,7 @@ module.exports = class MetamaskController extends EventEmitter {
async resetAccount () {
const selectedAddress = this.preferencesController.getSelectedAddress()
this.txController.wipeTransactions(selectedAddress)
-
- const networkController = this.networkController
- const oldType = networkController.getProviderConfig().type
- await networkController.setProviderType(oldType, true)
+ this.networkController.resetConnection()
return selectedAddress
}
@@ -958,6 +953,18 @@ module.exports = class MetamaskController extends EventEmitter {
return state
}
+ estimateGas (estimateGasParams) {
+ return new Promise((resolve, reject) => {
+ return this.txController.txGasUtil.query.estimateGas(estimateGasParams, (err, res) => {
+ if (err) {
+ return reject(err)
+ }
+
+ return resolve(res)
+ })
+ })
+ }
+
//=============================================================================
// PASSWORD MANAGEMENT
//=============================================================================