1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Break out rpc update and rpclist into two reducers.

This commit is contained in:
Kevin Serrano 2017-03-07 10:25:50 -08:00
parent e66035254f
commit 2a98beb878
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
3 changed files with 31 additions and 11 deletions

View File

@ -112,11 +112,13 @@ var actions = {
// config screen
SHOW_CONFIG_PAGE: 'SHOW_CONFIG_PAGE',
SET_RPC_TARGET: 'SET_RPC_TARGET',
SET_DEFAULT_RPC_TARGET: 'SET_DEFAULT_RPC_TARGET',
SET_PROVIDER_TYPE: 'SET_PROVIDER_TYPE',
USE_ETHERSCAN_PROVIDER: 'USE_ETHERSCAN_PROVIDER',
useEtherscanProvider: useEtherscanProvider,
showConfigPage: showConfigPage,
setRpcTarget: setRpcTarget,
setDefaultRpcTarget: setDefaultRpcTarget,
setProviderType: setProviderType,
// loading overlay
SHOW_LOADING: 'SHOW_LOADING_INDICATION',
@ -669,18 +671,34 @@ function markAccountsFound() {
// config
//
// default rpc target refers to localhost:8545 in this instance.
function setDefaultRpcTarget (rpcList) {
log.debug(`background.setDefaultRpcTarget`)
background.setRpcTarget('http://localhost:8545')
return (dispatch) => {
dispatch({
type: actions.SET_RPC_TARGET,
value: 'http://localhost:8545',
})
dispatch({
type: actions.SET_RPC_LIST,
value: rpcList,
})
}
}
function setRpcTarget (newRpc) {
return (dispatch) => {
log.debug(`background.setRpcTarget`)
background.setRpcTarget(newRpc)
background.updateFrequentRpcList(newRpc, (frequentRpcList) => {
const value = {
rpcTarget: newRpc,
frequentRpcList,
}
background.updateFrequentRpcList(newRpc, (rpcList) => {
dispatch({
type: actions.SET_RPC_TARGET,
value,
value: newRpc,
})
dispatch({
type: actions.SET_RPC_LIST,
value: rpcList,
})
})
}

View File

@ -258,9 +258,7 @@ 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.setDefaultRpcTarget(rpcList)),
icon: h('i.fa.fa-question-circle.fa-lg'),
activeNetworkRender: props.provider.rpcTarget,
}),

View File

@ -53,12 +53,16 @@ function reduceMetamask (state, action) {
isUnlocked: false,
})
case actions.SET_RPC_LIST:
return extend(metamaskState, {
frequentRpcList: action.value,
})
case actions.SET_RPC_TARGET:
return extend(metamaskState, {
frequentRpcList: action.value.frequentRpcList,
provider: {
type: 'rpc',
rpcTarget: action.value.rpcTarget,
rpcTarget: action.value,
},
})