mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Implemented functionality for displaying recent custom RPCs
This commit is contained in:
parent
17a7436602
commit
7a0ce31bd3
@ -1,10 +1,11 @@
|
|||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
const normalizeAddress = require('../sig-util').normalize
|
const normalizeAddress = require('../sig-util').normalize
|
||||||
|
const extend = require('xtend')
|
||||||
|
|
||||||
class PreferencesController {
|
class PreferencesController {
|
||||||
|
|
||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
const initState = opts.initState || { frequentRPCList: [] }
|
const initState = extend({ frequentRpcList: [] }, opts.initState)
|
||||||
this.store = new ObservableStore(initState)
|
this.store = new ObservableStore(initState)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,23 +26,23 @@ class PreferencesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addToFrequentRpcList (_url) {
|
addToFrequentRpcList (_url) {
|
||||||
return new Promise((resolve, reject) => {
|
let rpcList = this.getFrequentRpcList()
|
||||||
let rpcList = this.getFrequentRPCList()
|
let index = rpcList.findIndex((element) => { return element === _url })
|
||||||
let index = rpcList.findIndex((element) => { element === _url })
|
if (index !== -1) {
|
||||||
if (index) {
|
|
||||||
rpcList.splice(index, 1)
|
rpcList.splice(index, 1)
|
||||||
}
|
}
|
||||||
if (rpcList.length >= 3) {
|
if (_url !== 'http://localhost:8545') {
|
||||||
|
rpcList.push(_url)
|
||||||
|
}
|
||||||
|
if (rpcList.length > 2) {
|
||||||
rpcList.shift()
|
rpcList.shift()
|
||||||
}
|
}
|
||||||
rpcList.push(_url)
|
this.store.updateState({ frequentRpcList: rpcList })
|
||||||
this.store.updateState({ frequentRPCList: rpcList })
|
return Promise.resolve()
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getFrequentRpcList () {
|
getFrequentRpcList () {
|
||||||
return this.store.getState().frequentRPCList
|
return this.store.getState().frequentRpcList
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -627,8 +627,9 @@ function markAccountsFound() {
|
|||||||
|
|
||||||
function setRpcTarget (newRpc) {
|
function setRpcTarget (newRpc) {
|
||||||
if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
|
if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
|
||||||
|
background.addToFrequentRpcList(newRpc, () => {
|
||||||
background.setRpcTarget(newRpc)
|
background.setRpcTarget(newRpc)
|
||||||
background.addToFrequentRpcList(newRpc)
|
})
|
||||||
return {
|
return {
|
||||||
type: actions.SET_RPC_TARGET,
|
type: actions.SET_RPC_TARGET,
|
||||||
value: newRpc,
|
value: newRpc,
|
||||||
|
@ -58,6 +58,7 @@ function mapStateToProps (state) {
|
|||||||
forgottenPassword: state.appState.forgottenPassword,
|
forgottenPassword: state.appState.forgottenPassword,
|
||||||
lastUnreadNotice: state.metamask.lastUnreadNotice,
|
lastUnreadNotice: state.metamask.lastUnreadNotice,
|
||||||
lostAccounts: state.metamask.lostAccounts,
|
lostAccounts: state.metamask.lostAccounts,
|
||||||
|
frequentRpcList: state.metamask.frequentRpcList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +211,7 @@ App.prototype.renderAppBar = function () {
|
|||||||
|
|
||||||
App.prototype.renderNetworkDropdown = function () {
|
App.prototype.renderNetworkDropdown = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
|
const rpcList = props.frequentRpcList
|
||||||
const state = this.state || {}
|
const state = this.state || {}
|
||||||
const isOpen = state.isNetworkMenuOpen
|
const isOpen = state.isNetworkMenuOpen
|
||||||
|
|
||||||
@ -261,6 +263,7 @@ App.prototype.renderNetworkDropdown = function () {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
this.renderCustomOption(props.provider),
|
this.renderCustomOption(props.provider),
|
||||||
|
this.renderCommonRpc(rpcList, props.provider),
|
||||||
|
|
||||||
props.isUnlocked && h(DropMenuItem, {
|
props.isUnlocked && h(DropMenuItem, {
|
||||||
label: 'Custom RPC',
|
label: 'Custom RPC',
|
||||||
@ -508,3 +511,23 @@ App.prototype.renderCustomOption = function (provider) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App.prototype.renderCommonRpc = function (rpcList, provider) {
|
||||||
|
const { rpcTarget } = provider
|
||||||
|
const props = this.props
|
||||||
|
|
||||||
|
return rpcList.map((rpc) => {
|
||||||
|
if ((rpc === 'http://localhost:8545') || (rpc === rpcTarget)) {
|
||||||
|
return null
|
||||||
|
} else {
|
||||||
|
return h(DropMenuItem, {
|
||||||
|
label: rpc,
|
||||||
|
closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
|
||||||
|
action: () => props.dispatch(actions.setRpcTarget(rpc)),
|
||||||
|
icon: h('i.fa.fa-question-circle.fa-lg'),
|
||||||
|
activeNetworkRender: rpc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user