mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Tested against code to play nice with unit tests.
This commit is contained in:
parent
3be6ee5f6c
commit
62854398f1
@ -25,6 +25,14 @@ class PreferencesController {
|
|||||||
return this.store.getState().selectedAddress
|
return this.store.getState().selectedAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateFrequentRpcList (_url) {
|
||||||
|
return this.addToFrequentRpcList(_url)
|
||||||
|
.then((rpcList) => {
|
||||||
|
this.store.updateState({ frequentRpcList: rpcList })
|
||||||
|
return rpcList
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
addToFrequentRpcList (_url) {
|
addToFrequentRpcList (_url) {
|
||||||
let rpcList = this.getFrequentRpcList()
|
let rpcList = this.getFrequentRpcList()
|
||||||
let index = rpcList.findIndex((element) => { return element === _url })
|
let index = rpcList.findIndex((element) => { return element === _url })
|
||||||
@ -37,8 +45,7 @@ class PreferencesController {
|
|||||||
if (rpcList.length > 2) {
|
if (rpcList.length > 2) {
|
||||||
rpcList.shift()
|
rpcList.shift()
|
||||||
}
|
}
|
||||||
this.store.updateState({ frequentRpcList: rpcList })
|
return Promise.resolve(rpcList)
|
||||||
return Promise.resolve()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getFrequentRpcList () {
|
getFrequentRpcList () {
|
||||||
@ -49,6 +56,8 @@ class PreferencesController {
|
|||||||
// PRIVATE METHODS
|
// PRIVATE METHODS
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PreferencesController
|
module.exports = PreferencesController
|
||||||
|
@ -259,7 +259,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
|
|
||||||
// PreferencesController
|
// PreferencesController
|
||||||
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
|
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
|
||||||
addToFrequentRpcList: nodeify(preferencesController.addToFrequentRpcList).bind(preferencesController),
|
updateFrequentRpcList: nodeify(preferencesController.updateFrequentRpcList).bind(preferencesController),
|
||||||
|
|
||||||
// KeyringController
|
// KeyringController
|
||||||
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
||||||
|
@ -11,6 +11,7 @@ describe ('config view actions', function() {
|
|||||||
var initialState = {
|
var initialState = {
|
||||||
metamask: {
|
metamask: {
|
||||||
rpcTarget: 'foo',
|
rpcTarget: 'foo',
|
||||||
|
frequentRpcList: []
|
||||||
},
|
},
|
||||||
appState: {
|
appState: {
|
||||||
currentView: {
|
currentView: {
|
||||||
@ -30,15 +31,36 @@ describe ('config view actions', function() {
|
|||||||
describe('SET_RPC_TARGET', function() {
|
describe('SET_RPC_TARGET', function() {
|
||||||
|
|
||||||
it('sets the state.metamask.rpcTarget property of the state to the action.value', function() {
|
it('sets the state.metamask.rpcTarget property of the state to the action.value', function() {
|
||||||
|
const value = {
|
||||||
|
rpcTarget: 'foo',
|
||||||
|
frequentRpcList: ['foo']
|
||||||
|
}
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.SET_RPC_TARGET,
|
type: actions.SET_RPC_TARGET,
|
||||||
value: 'bar',
|
value,
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = reducers(initialState, action)
|
var result = reducers(initialState, action)
|
||||||
assert.equal(result.metamask.provider.type, 'rpc')
|
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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
|
})
|
||||||
|
@ -626,13 +626,19 @@ function markAccountsFound() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
function setRpcTarget (newRpc) {
|
function setRpcTarget (newRpc) {
|
||||||
if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
|
return (dispatch) => {
|
||||||
background.addToFrequentRpcList(newRpc, () => {
|
if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
|
||||||
background.setRpcTarget(newRpc)
|
background.setRpcTarget(newRpc)
|
||||||
})
|
background.updateFrequentRpcList(newRpc, (frequentRpcList) => {
|
||||||
return {
|
const value = {
|
||||||
type: actions.SET_RPC_TARGET,
|
rpcTarget: newRpc,
|
||||||
value: newRpc,
|
frequentRpcList,
|
||||||
|
}
|
||||||
|
dispatch({
|
||||||
|
type: actions.SET_RPC_TARGET,
|
||||||
|
value,
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,9 @@ App.prototype.renderNetworkDropdown = function () {
|
|||||||
h(DropMenuItem, {
|
h(DropMenuItem, {
|
||||||
label: 'Localhost 8545',
|
label: 'Localhost 8545',
|
||||||
closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
|
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'),
|
icon: h('i.fa.fa-question-circle.fa-lg'),
|
||||||
activeNetworkRender: props.provider.rpcTarget,
|
activeNetworkRender: props.provider.rpcTarget,
|
||||||
}),
|
}),
|
||||||
|
@ -55,9 +55,10 @@ function reduceMetamask (state, action) {
|
|||||||
|
|
||||||
case actions.SET_RPC_TARGET:
|
case actions.SET_RPC_TARGET:
|
||||||
return extend(metamaskState, {
|
return extend(metamaskState, {
|
||||||
|
frequentRpcList: action.value.frequentRpcList,
|
||||||
provider: {
|
provider: {
|
||||||
type: 'rpc',
|
type: 'rpc',
|
||||||
rpcTarget: action.value,
|
rpcTarget: action.value.rpcTarget,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user