mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Refactor of code into separate reducers and actions.
This commit is contained in:
parent
08ca7dac5a
commit
e7e024bcdd
@ -29,7 +29,7 @@ class PreferencesController {
|
|||||||
return this.addToFrequentRpcList(_url)
|
return this.addToFrequentRpcList(_url)
|
||||||
.then((rpcList) => {
|
.then((rpcList) => {
|
||||||
this.store.updateState({ frequentRpcList: rpcList })
|
this.store.updateState({ frequentRpcList: rpcList })
|
||||||
return rpcList
|
return Promise.resolve()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,8 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
return {
|
return {
|
||||||
// etc
|
// etc
|
||||||
getState: (cb) => cb(null, this.getState()),
|
getState: (cb) => cb(null, this.getState()),
|
||||||
setRpcTarget: this.setRpcTarget.bind(this),
|
setDefaultRpc: this.setDefaultRpc.bind(this),
|
||||||
|
setCustomRpc: this.setCustomRpc.bind(this),
|
||||||
setProviderType: this.setProviderType.bind(this),
|
setProviderType: this.setProviderType.bind(this),
|
||||||
useEtherscanProvider: this.useEtherscanProvider.bind(this),
|
useEtherscanProvider: this.useEtherscanProvider.bind(this),
|
||||||
setCurrentCurrency: this.setCurrentCurrency.bind(this),
|
setCurrentCurrency: this.setCurrentCurrency.bind(this),
|
||||||
@ -265,7 +266,6 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
|
|
||||||
// PreferencesController
|
// PreferencesController
|
||||||
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
|
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
|
||||||
updateFrequentRpcList: nodeify(preferencesController.updateFrequentRpcList).bind(preferencesController),
|
|
||||||
|
|
||||||
// KeyringController
|
// KeyringController
|
||||||
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
setLocked: nodeify(keyringController.setLocked).bind(keyringController),
|
||||||
@ -662,12 +662,21 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
if (this.isNetworkLoading()) this.lookupNetwork()
|
if (this.isNetworkLoading()) this.lookupNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
setRpcTarget (rpcTarget) {
|
setDefaultRpc () {
|
||||||
this.configManager.setRpcTarget(rpcTarget)
|
this.configManager.setRpcTarget('http://localhost:8545')
|
||||||
extension.runtime.reload()
|
extension.runtime.reload()
|
||||||
this.lookupNetwork()
|
this.lookupNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCustomRpc (rpcTarget, rpcList) {
|
||||||
|
this.configManager.setRpcTarget(rpcTarget)
|
||||||
|
return this.preferencesController.updateFrequentRpcList(rpcTarget)
|
||||||
|
.then(() => {
|
||||||
|
extension.runtime.reload()
|
||||||
|
this.lookupNetwork()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
setProviderType (type) {
|
setProviderType (type) {
|
||||||
this.configManager.setProviderType(type)
|
this.configManager.setProviderType(type)
|
||||||
extension.runtime.reload()
|
extension.runtime.reload()
|
||||||
|
@ -36,16 +36,10 @@ describe ('config view actions', function() {
|
|||||||
value: 'foo',
|
value: 'foo',
|
||||||
}
|
}
|
||||||
|
|
||||||
const secondAction = {
|
|
||||||
type: actions.SET_RPC_LIST,
|
|
||||||
value: ['foo'],
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = reducers(initialState, action)
|
var result = reducers(initialState, action)
|
||||||
result = reducers(result, secondAction)
|
result = reducers(result, secondAction)
|
||||||
assert.equal(result.metamask.provider.type, 'rpc')
|
assert.equal(result.metamask.provider.type, 'rpc')
|
||||||
assert.equal(result.metamask.provider.rpcTarget, 'foo')
|
assert.equal(result.metamask.provider.rpcTarget, 'foo')
|
||||||
assert.equal(result.metamask.frequentRpcList[0], 'foo')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should handle multiple requests to change the rpc gracefully', function() {
|
it('should handle multiple requests to change the rpc gracefully', function() {
|
||||||
@ -60,10 +54,8 @@ describe ('config view actions', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var result = reducers(initialState, action)
|
var result = reducers(initialState, action)
|
||||||
var secondResult = reducers(result, secondAction)
|
var secondResult = reducers(result, action)
|
||||||
var thirdResult = reducers(secondResult, action)
|
assert.equal(secondResult.metamask.frequentRpcList.length, 1)
|
||||||
var fourthResult = reducers(thirdResult, secondAction)
|
|
||||||
assert.equal(fourthResult.metamask.frequentRpcList.length, 1)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -674,33 +674,21 @@ function markAccountsFound() {
|
|||||||
// default rpc target refers to localhost:8545 in this instance.
|
// default rpc target refers to localhost:8545 in this instance.
|
||||||
function setDefaultRpcTarget (rpcList) {
|
function setDefaultRpcTarget (rpcList) {
|
||||||
log.debug(`background.setDefaultRpcTarget`)
|
log.debug(`background.setDefaultRpcTarget`)
|
||||||
background.setRpcTarget('http://localhost:8545')
|
background.setDefaultRpc()
|
||||||
return (dispatch) => {
|
return {
|
||||||
dispatch({
|
type: actions.SET_RPC_TARGET,
|
||||||
type: actions.SET_RPC_TARGET,
|
value: 'http://localhost:8545',
|
||||||
value: 'http://localhost:8545',
|
|
||||||
})
|
|
||||||
dispatch({
|
|
||||||
type: actions.SET_RPC_LIST,
|
|
||||||
value: rpcList,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setRpcTarget (newRpc) {
|
function setRpcTarget (newRpc) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
log.debug(`background.setRpcTarget`)
|
log.debug(`background.setRpcTarget`)
|
||||||
background.setRpcTarget(newRpc)
|
background.setCustomRpc(newRpc)
|
||||||
background.updateFrequentRpcList(newRpc, (rpcList) => {
|
return {
|
||||||
dispatch({
|
type: actions.SET_RPC_TARGET,
|
||||||
type: actions.SET_RPC_TARGET,
|
value: newRpc,
|
||||||
value: newRpc,
|
}
|
||||||
})
|
|
||||||
dispatch({
|
|
||||||
type: actions.SET_RPC_LIST,
|
|
||||||
value: rpcList,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ function reduceMetamask (state, action) {
|
|||||||
conversionDate: 'N/A',
|
conversionDate: 'N/A',
|
||||||
noActiveNotices: true,
|
noActiveNotices: true,
|
||||||
lastUnreadNotice: undefined,
|
lastUnreadNotice: undefined,
|
||||||
|
frequentRpcList: [],
|
||||||
}, state.metamask)
|
}, state.metamask)
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user