|
|
@ -3,16 +3,14 @@ const h = require('react-hyperscript') |
|
|
|
const inherits = require('util').inherits |
|
|
|
const inherits = require('util').inherits |
|
|
|
const connect = require('react-redux').connect |
|
|
|
const connect = require('react-redux').connect |
|
|
|
const actions = require('../../actions') |
|
|
|
const actions = require('../../actions') |
|
|
|
|
|
|
|
const Dropdown = require('../dropdown').Dropdown |
|
|
|
// connect, dispatch actions...
|
|
|
|
const DropdownMenuItem = require('../dropdown').DropdownMenuItem |
|
|
|
// onClick: () => props.dispatch(actions.setProviderType('mainnet')),
|
|
|
|
|
|
|
|
// onClick: () => props.dispatch(actions.setDefaultRpcTarget()),
|
|
|
|
|
|
|
|
// onClick: () => props.dispatch(actions.setRpcTarget(rpcTarget)),
|
|
|
|
|
|
|
|
// onClick: () => this.props.dispatch(actions.showConfigPage()),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function mapStateToProps (state) { |
|
|
|
function mapStateToProps (state) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
active: state.appState.modalOpen |
|
|
|
provider: state.metamask.provider, |
|
|
|
|
|
|
|
frequentRpcList: state.metamask.frequentRpcList || [], |
|
|
|
|
|
|
|
networkDropdownOpen: state.appState.networkDropdownOpen, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -21,6 +19,20 @@ function mapDispatchToProps (dispatch) { |
|
|
|
hideModal: () => { |
|
|
|
hideModal: () => { |
|
|
|
dispatch(actions.hideModal()) |
|
|
|
dispatch(actions.hideModal()) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
setProviderType: (type) => { |
|
|
|
|
|
|
|
dispatch(actions.setProviderType(type)) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
setDefaultRpcTarget: () => { |
|
|
|
|
|
|
|
dispatch(actions.setDefaultRpcTarget(type)) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
setRpcTarget: (target) => { |
|
|
|
|
|
|
|
dispatch(actions.setRpcTarget(target)) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
showConfigPage: () => { |
|
|
|
|
|
|
|
dispatch(actions.showConfigPage()) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
showNetworkDropdown: () => {dispatch(actions.showNetworkDropdown())}, |
|
|
|
|
|
|
|
hideNetworkDropdown: () => {dispatch(actions.hideNetworkDropdown())}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -30,18 +42,20 @@ function NetworkDropdown () { |
|
|
|
Component.call(this) |
|
|
|
Component.call(this) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(NetworkDropdown) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// renderNetworkDropdown
|
|
|
|
// renderNetworkDropdown
|
|
|
|
// renderCustomOption
|
|
|
|
// renderCustomOption
|
|
|
|
// renderCommonRpc
|
|
|
|
// renderCommonRpc
|
|
|
|
// TODO: specify default props and proptypes
|
|
|
|
// TODO: specify default props and proptypes
|
|
|
|
NetworkDropdown.prototype.render = function () { |
|
|
|
NetworkDropdown.prototype.render = function () { |
|
|
|
|
|
|
|
console.log("RENDER") |
|
|
|
const props = this.props |
|
|
|
const props = this.props |
|
|
|
const { provider: { type: providerType, rpcTarget: activeNetwork } } = props |
|
|
|
const { provider: { type: providerType, rpcTarget: activeNetwork } } = props |
|
|
|
const rpcList = props.frequentRpcList |
|
|
|
const rpcList = props.frequentRpcList |
|
|
|
const state = this.state || {} |
|
|
|
const state = this.state || {} |
|
|
|
const isOpen = state.isNetworkMenuOpen |
|
|
|
console.log("this.state", state) |
|
|
|
|
|
|
|
const isOpen = this.props.networkDropdownOpen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("isOpen", isOpen) |
|
|
|
|
|
|
|
|
|
|
|
return h(Dropdown, { |
|
|
|
return h(Dropdown, { |
|
|
|
useCssTransition: true, |
|
|
|
useCssTransition: true, |
|
|
@ -56,7 +70,7 @@ NetworkDropdown.prototype.render = function () { |
|
|
|
// classes from three constituent nodes of the toggle element
|
|
|
|
// classes from three constituent nodes of the toggle element
|
|
|
|
|
|
|
|
|
|
|
|
if (isNotToggleElement) { |
|
|
|
if (isNotToggleElement) { |
|
|
|
this.setState({ isNetworkMenuOpen: false }) |
|
|
|
this.props.hideNetworkDropdown() |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
zIndex: 11, |
|
|
|
zIndex: 11, |
|
|
@ -74,8 +88,8 @@ NetworkDropdown.prototype.render = function () { |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
key: 'main', |
|
|
|
key: 'main', |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
onClick: () => props.dispatch(actions.setProviderType('mainnet')), |
|
|
|
onClick: () => props.setProviderType('mainnet'), |
|
|
|
style: { |
|
|
|
style: { |
|
|
|
fontSize: '18px', |
|
|
|
fontSize: '18px', |
|
|
|
}, |
|
|
|
}, |
|
|
@ -91,8 +105,8 @@ NetworkDropdown.prototype.render = function () { |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
key: 'ropsten', |
|
|
|
key: 'ropsten', |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
onClick: () => props.dispatch(actions.setProviderType('ropsten')), |
|
|
|
onClick: () => props.setProviderType('ropsten'), |
|
|
|
style: { |
|
|
|
style: { |
|
|
|
fontSize: '18px', |
|
|
|
fontSize: '18px', |
|
|
|
}, |
|
|
|
}, |
|
|
@ -108,8 +122,8 @@ NetworkDropdown.prototype.render = function () { |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
key: 'kovan', |
|
|
|
key: 'kovan', |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
onClick: () => props.dispatch(actions.setProviderType('kovan')), |
|
|
|
onClick: () => props.setProviderType('kovan'), |
|
|
|
style: { |
|
|
|
style: { |
|
|
|
fontSize: '18px', |
|
|
|
fontSize: '18px', |
|
|
|
}, |
|
|
|
}, |
|
|
@ -125,8 +139,8 @@ NetworkDropdown.prototype.render = function () { |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
key: 'rinkeby', |
|
|
|
key: 'rinkeby', |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
onClick: () => props.dispatch(actions.setProviderType('rinkeby')), |
|
|
|
onClick: () => propssetProviderType('rinkeby'), |
|
|
|
style: { |
|
|
|
style: { |
|
|
|
fontSize: '18px', |
|
|
|
fontSize: '18px', |
|
|
|
}, |
|
|
|
}, |
|
|
@ -142,8 +156,8 @@ NetworkDropdown.prototype.render = function () { |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
key: 'default', |
|
|
|
key: 'default', |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
onClick: () => props.dispatch(actions.setDefaultRpcTarget()), |
|
|
|
onClick: () => props.setDefaultRpcTarget(), |
|
|
|
style: { |
|
|
|
style: { |
|
|
|
fontSize: '18px', |
|
|
|
fontSize: '18px', |
|
|
|
}, |
|
|
|
}, |
|
|
@ -161,8 +175,8 @@ NetworkDropdown.prototype.render = function () { |
|
|
|
h( |
|
|
|
h( |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
onClick: () => this.props.dispatch(actions.showConfigPage()), |
|
|
|
onClick: () => this.props.showConfigPage(), |
|
|
|
style: { |
|
|
|
style: { |
|
|
|
fontSize: '18px', |
|
|
|
fontSize: '18px', |
|
|
|
}, |
|
|
|
}, |
|
|
@ -211,8 +225,8 @@ NetworkDropdown.prototype.renderCommonRpc = function (rpcList, provider) { |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
key: `common${rpc}`, |
|
|
|
key: `common${rpc}`, |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: false }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
onClick: () => props.dispatch(actions.setRpcTarget(rpc)), |
|
|
|
onClick: () => props.setRpcTarget(rpc), |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ |
|
|
|
[ |
|
|
|
h('i.fa.fa-question-circle.fa-lg.menu-icon'), |
|
|
|
h('i.fa.fa-question-circle.fa-lg.menu-icon'), |
|
|
@ -246,8 +260,8 @@ NetworkDropdown.prototype.renderCustomOption = function (provider) { |
|
|
|
DropdownMenuItem, |
|
|
|
DropdownMenuItem, |
|
|
|
{ |
|
|
|
{ |
|
|
|
key: rpcTarget, |
|
|
|
key: rpcTarget, |
|
|
|
onClick: () => props.dispatch(actions.setRpcTarget(rpcTarget)), |
|
|
|
onClick: () => props.setRpcTarget(rpcTarget), |
|
|
|
closeMenu: () => this.setState({ isNetworkMenuOpen: false }), |
|
|
|
closeMenu: () => this.props.hideNetworkDropdown(), |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ |
|
|
|
[ |
|
|
|
h('i.fa.fa-question-circle.fa-lg.menu-icon'), |
|
|
|
h('i.fa.fa-question-circle.fa-lg.menu-icon'), |
|
|
@ -257,3 +271,6 @@ NetworkDropdown.prototype.renderCustomOption = function (provider) { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const comp = connect(mapStateToProps, mapDispatchToProps)(NetworkDropdown) |
|
|
|
|
|
|
|
module.exports = comp |