aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
authorBruno <brunobar79@gmail.com>2018-05-31 10:27:33 +0800
committerBruno <brunobar79@gmail.com>2018-05-31 10:27:33 +0800
commitde9672726833e26ea96d198c0d9f1464015614f5 (patch)
tree5a213d4ff8269fe52c9e561fe8da6fefb4e03d09 /app/scripts/controllers
parent3dd58463caef98c2cc1f068931624795a43912db (diff)
parent39d22a4ddb4ba0f4ad456009c86486a433c6724e (diff)
downloadtangerine-wallet-browser-de9672726833e26ea96d198c0d9f1464015614f5.tar.gz
tangerine-wallet-browser-de9672726833e26ea96d198c0d9f1464015614f5.tar.zst
tangerine-wallet-browser-de9672726833e26ea96d198c0d9f1464015614f5.zip
Merge remote-tracking branch 'upstream/develop' into develop
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/address-book.js27
-rw-r--r--app/scripts/controllers/preferences.js30
-rw-r--r--app/scripts/controllers/recent-blocks.js22
-rw-r--r--app/scripts/controllers/transactions/index.js23
4 files changed, 46 insertions, 56 deletions
diff --git a/app/scripts/controllers/address-book.js b/app/scripts/controllers/address-book.js
index c91e6b2e4..4697e074c 100644
--- a/app/scripts/controllers/address-book.js
+++ b/app/scripts/controllers/address-book.js
@@ -13,19 +13,17 @@ class AddressBookController {
* @param {object} opts Overrides the defaults for the initial state of this.store
* @property {array} opts.initState initializes the the state of the AddressBookController. Can contain an
* addressBook property to initialize the addressBook array
- * @param {KeyringController} keyringController (Soon to be deprecated) The keyringController used in the current
- * MetamaskController. Contains the identities used in this AddressBookController.
+ * @property {object} opts.preferencesStore the {@code PreferencesController} store
* @property {object} store The the store of the current users address book
* @property {array} store.addressBook An array of addresses and nicknames. These are set by the user when sending
* to a new address.
*
*/
- constructor (opts = {}, keyringController) {
- const initState = extend({
+ constructor ({initState, preferencesStore}) {
+ this.store = new ObservableStore(extend({
addressBook: [],
- }, opts.initState)
- this.store = new ObservableStore(initState)
- this.keyringController = keyringController
+ }, initState))
+ this._preferencesStore = preferencesStore
}
//
@@ -62,7 +60,7 @@ class AddressBookController {
*/
_addToAddressBook (address, name) {
const addressBook = this._getAddressBook()
- const identities = this._getIdentities()
+ const {identities} = this._preferencesStore.getState()
const addressBookIndex = addressBook.findIndex((element) => { return element.address.toLowerCase() === address.toLowerCase() || element.name === name })
const identitiesIndex = Object.keys(identities).findIndex((element) => { return element.toLowerCase() === address.toLowerCase() })
@@ -95,19 +93,6 @@ class AddressBookController {
_getAddressBook () {
return this.store.getState().addressBook
}
-
- /**
- * Retrieves identities from the keyring controller in order to avoid
- * duplication
- *
- * @deprecated
- * @returns {array} Returns the identies array from the keyringContoller's state
- *
- */
- _getIdentities () {
- return this.keyringController.memStore.getState().identities
- }
-
}
module.exports = AddressBookController
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index 1d3308d36..a4ff1207e 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -27,6 +27,7 @@ class PreferencesController {
useBlockie: false,
featureFlags: {},
currentLocale: opts.initLangCode,
+ identities: {},
}, opts.initState)
this.store = new ObservableStore(initState)
}
@@ -62,6 +63,16 @@ class PreferencesController {
this.store.updateState({ currentLocale: key })
}
+ setAddresses (addresses) {
+ const oldIdentities = this.store.getState().identities
+ const identities = addresses.reduce((ids, address, index) => {
+ const oldId = oldIdentities[address] || {}
+ ids[address] = {name: `Account ${index + 1}`, address, ...oldId}
+ return ids
+ }, {})
+ this.store.updateState({ identities })
+ }
+
/**
* Setter for the `selectedAddress` property
*
@@ -156,6 +167,21 @@ class PreferencesController {
}
/**
+ * Sets a custom label for an account
+ * @param {string} account the account to set a label for
+ * @param {string} label the custom label for the account
+ * @return {Promise<string>}
+ */
+ setAccountLabel (account, label) {
+ const address = normalizeAddress(account)
+ const {identities} = this.store.getState()
+ identities[address] = identities[address] || {}
+ identities[address].name = label
+ this.store.updateState({ identities })
+ return Promise.resolve(label)
+ }
+
+ /**
* Gets an updated rpc list from this.addToFrequentRpcList() and sets the `frequentRpcList` to this update list.
*
* @param {string} _url The the new rpc url to add to the updated list
@@ -189,8 +215,8 @@ class PreferencesController {
* The returned list will have a max length of 2. If the _url currently exists it the list, it will be moved to the
* end of the list. The current list is modified and returned as a promise.
*
- * @param {string} _url The rpc url to add to the frequentRpcList.
- * @returns {Promise<array>} The updated frequentRpcList.
+ * @param {string} _url The rpc url to add to the frequentRpcList.
+ * @returns {Promise<array>} The updated frequentRpcList.
*
*/
addToFrequentRpcList (_url) {
diff --git a/app/scripts/controllers/recent-blocks.js b/app/scripts/controllers/recent-blocks.js
index 1377c1ba9..033ef1d7e 100644
--- a/app/scripts/controllers/recent-blocks.js
+++ b/app/scripts/controllers/recent-blocks.js
@@ -119,29 +119,21 @@ class RecentBlocksController {
*/
async backfill() {
this.blockTracker.once('block', async (block) => {
- let blockNum = block.number
- let recentBlocks
- let state = this.store.getState()
- recentBlocks = state.recentBlocks
-
- while (recentBlocks.length < this.historyLength) {
+ const currentBlockNumber = Number.parseInt(block.number, 16)
+ const blocksToFetch = Math.min(currentBlockNumber, this.historyLength)
+ const prevBlockNumber = currentBlockNumber - 1
+ const targetBlockNumbers = Array(blocksToFetch).fill().map((_, index) => prevBlockNumber - index)
+ await Promise.all(targetBlockNumbers.map(async (targetBlockNumber) => {
try {
- let blockNumBn = new BN(blockNum.substr(2), 16)
- const newNum = blockNumBn.subn(1).toString(10)
- const newBlock = await this.getBlockByNumber(newNum)
+ const newBlock = await this.getBlockByNumber(targetBlockNumber)
if (newBlock) {
this.backfillBlock(newBlock)
- blockNum = newBlock.number
}
-
- state = this.store.getState()
- recentBlocks = state.recentBlocks
} catch (e) {
log.error(e)
}
- await this.wait()
- }
+ }))
})
}
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index 3886db104..aff5db984 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -8,6 +8,7 @@ const TxGasUtil = require('./tx-gas-utils')
const PendingTransactionTracker = require('./pending-tx-tracker')
const NonceTracker = require('./nonce-tracker')
const txUtils = require('./lib/util')
+const cleanErrorStack = require('../../lib/cleanErrorStack')
const log = require('loglevel')
/**
@@ -112,27 +113,13 @@ class TransactionController extends EventEmitter {
}
/**
- Check if a txMeta in the list with the same nonce has been confirmed in a block
- if the txParams dont have a nonce will return false
- @returns {boolean} whether the nonce has been used in a transaction confirmed in a block
- @param {object} txMeta - the txMeta object
- */
- async isNonceTaken (txMeta) {
- const { from, nonce } = txMeta.txParams
- if ('nonce' in txMeta.txParams) {
- const sameNonceTxList = this.txStateManager.getFilteredTxList({from, nonce, status: 'confirmed'})
- return (sameNonceTxList.length >= 1)
- }
- return false
- }
-
- /**
add a new unapproved transaction to the pipeline
@returns {Promise<string>} the hash of the transaction after being submitted to the network
@param txParams {object} - txParams for the transaction
@param opts {object} - with the key origin to put the origin on the txMeta
*/
+
async newUnapprovedTransaction (txParams, opts = {}) {
log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
const initialTxMeta = await this.addUnapprovedTransaction(txParams)
@@ -145,11 +132,11 @@ class TransactionController extends EventEmitter {
case 'submitted':
return resolve(finishedTxMeta.hash)
case 'rejected':
- return reject(new Error('MetaMask Tx Signature: User denied transaction signature.'))
+ return reject(cleanErrorStack(new Error('MetaMask Tx Signature: User denied transaction signature.')))
case 'failed':
- return reject(new Error(finishedTxMeta.err.message))
+ return reject(cleanErrorStack(new Error(finishedTxMeta.err.message)))
default:
- return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))
+ return reject(cleanErrorStack(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`)))
}
})
})