aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-02-24 05:56:58 +0800
committerKevin Serrano <kevgagser@gmail.com>2017-02-24 05:56:58 +0800
commit62854398f1d3c72a82ae9d4feb03d9a1a947534e (patch)
tree879c6ded10ca1f11bdb7057282ffbc61c01b36e4
parent3be6ee5f6cc5e7b79a8eeea182f91a15eb9ed989 (diff)
downloadtangerine-wallet-browser-62854398f1d3c72a82ae9d4feb03d9a1a947534e.tar
tangerine-wallet-browser-62854398f1d3c72a82ae9d4feb03d9a1a947534e.tar.gz
tangerine-wallet-browser-62854398f1d3c72a82ae9d4feb03d9a1a947534e.tar.bz2
tangerine-wallet-browser-62854398f1d3c72a82ae9d4feb03d9a1a947534e.tar.lz
tangerine-wallet-browser-62854398f1d3c72a82ae9d4feb03d9a1a947534e.tar.xz
tangerine-wallet-browser-62854398f1d3c72a82ae9d4feb03d9a1a947534e.tar.zst
tangerine-wallet-browser-62854398f1d3c72a82ae9d4feb03d9a1a947534e.zip
Tested against code to play nice with unit tests.
-rw-r--r--app/scripts/lib/controllers/preferences.js13
-rw-r--r--app/scripts/metamask-controller.js2
-rw-r--r--test/unit/actions/config_test.js28
-rw-r--r--ui/app/actions.js18
-rw-r--r--ui/app/app.js4
-rw-r--r--ui/app/reducers/metamask.js3
6 files changed, 54 insertions, 14 deletions
diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js
index 8cc320179..7bd2e5631 100644
--- a/app/scripts/lib/controllers/preferences.js
+++ b/app/scripts/lib/controllers/preferences.js
@@ -25,6 +25,14 @@ class PreferencesController {
return this.store.getState().selectedAddress
}
+ updateFrequentRpcList (_url) {
+ return this.addToFrequentRpcList(_url)
+ .then((rpcList) => {
+ this.store.updateState({ frequentRpcList: rpcList })
+ return rpcList
+ })
+ }
+
addToFrequentRpcList (_url) {
let rpcList = this.getFrequentRpcList()
let index = rpcList.findIndex((element) => { return element === _url })
@@ -37,8 +45,7 @@ class PreferencesController {
if (rpcList.length > 2) {
rpcList.shift()
}
- this.store.updateState({ frequentRpcList: rpcList })
- return Promise.resolve()
+ return Promise.resolve(rpcList)
}
getFrequentRpcList () {
@@ -49,6 +56,8 @@ class PreferencesController {
// PRIVATE METHODS
//
+
+
}
module.exports = PreferencesController
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index da186d958..ad67a5875 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -259,7 +259,7 @@ module.exports = class MetamaskController extends EventEmitter {
// PreferencesController
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
- addToFrequentRpcList: nodeify(preferencesController.addToFrequentRpcList).bind(preferencesController),
+ updateFrequentRpcList: nodeify(preferencesController.updateFrequentRpcList).bind(preferencesController),
// KeyringController
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
diff --git a/test/unit/actions/config_test.js b/test/unit/actions/config_test.js
index f851e4102..fea0cf0ba 100644
--- a/test/unit/actions/config_test.js
+++ b/test/unit/actions/config_test.js
@@ -11,6 +11,7 @@ describe ('config view actions', function() {
var initialState = {
metamask: {
rpcTarget: 'foo',
+ frequentRpcList: []
},
appState: {
currentView: {
@@ -30,15 +31,36 @@ describe ('config view actions', function() {
describe('SET_RPC_TARGET', function() {
it('sets the state.metamask.rpcTarget property of the state to the action.value', function() {
+ const value = {
+ rpcTarget: 'foo',
+ frequentRpcList: ['foo']
+ }
const action = {
type: actions.SET_RPC_TARGET,
- value: 'bar',
+ value,
}
var result = reducers(initialState, action)
assert.equal(result.metamask.provider.type, 'rpc')
- assert.equal(result.metamask.provider.rpcTarget, action.value)
+ assert.equal(result.metamask.provider.rpcTarget, value.rpcTarget)
+ assert.equal(result.metamask.frequentRpcList[0], value.frequentRpcList[0])
+ })
+
+ it('should handle multiple requests to change the rpc gracefully', function() {
+ const value = {
+ rpcTarget: 'foo',
+ frequentRpcList: ['foo']
+ }
+
+ const action = {
+ type: actions.SET_RPC_TARGET,
+ value,
+ }
+
+ var result = reducers(initialState, action)
+ var secondResult = reducers(result, action)
+ assert.equal(secondResult.metamask.frequentRpcList.length, 1)
})
})
-})
+})
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 86638fc91..7e5add1d0 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -626,13 +626,19 @@ function markAccountsFound() {
//
function setRpcTarget (newRpc) {
- if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
- background.addToFrequentRpcList(newRpc, () => {
+ return (dispatch) => {
+ if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
background.setRpcTarget(newRpc)
- })
- return {
- type: actions.SET_RPC_TARGET,
- value: newRpc,
+ background.updateFrequentRpcList(newRpc, (frequentRpcList) => {
+ const value = {
+ rpcTarget: newRpc,
+ frequentRpcList,
+ }
+ dispatch({
+ type: actions.SET_RPC_TARGET,
+ value,
+ })
+ })
}
}
diff --git a/ui/app/app.js b/ui/app/app.js
index d61f93dd2..cf865f23f 100644
--- a/ui/app/app.js
+++ b/ui/app/app.js
@@ -257,7 +257,9 @@ App.prototype.renderNetworkDropdown = function () {
h(DropMenuItem, {
label: 'Localhost 8545',
closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
- action: () => props.dispatch(actions.setRpcTarget('http://localhost:8545')),
+ action: () => {
+ props.dispatch(actions.setRpcTarget('http://localhost:8545'))
+ },
icon: h('i.fa.fa-question-circle.fa-lg'),
activeNetworkRender: props.provider.rpcTarget,
}),
diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js
index 3875cf6d1..7bf2969e7 100644
--- a/ui/app/reducers/metamask.js
+++ b/ui/app/reducers/metamask.js
@@ -55,9 +55,10 @@ function reduceMetamask (state, action) {
case actions.SET_RPC_TARGET:
return extend(metamaskState, {
+ frequentRpcList: action.value.frequentRpcList,
provider: {
type: 'rpc',
- rpcTarget: action.value,
+ rpcTarget: action.value.rpcTarget,
},
})