mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
[WIP] Extract network dropdown into own component
This commit is contained in:
parent
e39c600a45
commit
4cd33453dc
@ -15,6 +15,11 @@ var actions = {
|
|||||||
SIDEBAR_CLOSE: 'UI_SIDEBAR_CLOSE',
|
SIDEBAR_CLOSE: 'UI_SIDEBAR_CLOSE',
|
||||||
showSidebar: showSidebar,
|
showSidebar: showSidebar,
|
||||||
hideSidebar: hideSidebar,
|
hideSidebar: hideSidebar,
|
||||||
|
// network dropdown open
|
||||||
|
NETWORK_DROPDOWN_OPEN: 'UI_NETWORK_DROPDOWN_OPEN',
|
||||||
|
NETWORK_DROPDOWN_CLOSE: 'UI_NETWORK_DROPDOWN_CLOSE',
|
||||||
|
showNetworkDropdown: showNetworkDropdown,
|
||||||
|
hideNetworkDropdown: hideNetworkDropdown,
|
||||||
// menu state
|
// menu state
|
||||||
getNetworkStatus: 'getNetworkStatus',
|
getNetworkStatus: 'getNetworkStatus',
|
||||||
// transition state
|
// transition state
|
||||||
@ -773,6 +778,19 @@ function useEtherscanProvider () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showNetworkDropdown () {
|
||||||
|
return {
|
||||||
|
type: actions.NETWORK_DROPDOWN_OPEN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideNetworkDropdown () {
|
||||||
|
return {
|
||||||
|
type: actions.NETWORK_DROPDOWN_CLOSE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function showModal () {
|
function showModal () {
|
||||||
return {
|
return {
|
||||||
type: actions.MODAL_OPEN,
|
type: actions.MODAL_OPEN,
|
||||||
|
@ -36,6 +36,8 @@ const HDRestoreVaultScreen = require('./keychains/hd/restore-vault')
|
|||||||
const RevealSeedConfirmation = require('./keychains/hd/recover-seed/confirmation')
|
const RevealSeedConfirmation = require('./keychains/hd/recover-seed/confirmation')
|
||||||
const ReactCSSTransitionGroup = require('react-addons-css-transition-group')
|
const ReactCSSTransitionGroup = require('react-addons-css-transition-group')
|
||||||
const AccountDropdowns = require('./components/account-dropdowns').AccountDropdowns
|
const AccountDropdowns = require('./components/account-dropdowns').AccountDropdowns
|
||||||
|
const NetworkDropdown = require('./components/dropdowns/network-dropdown')
|
||||||
|
console.log('imported:', NetworkDropdown)
|
||||||
|
|
||||||
// Global Modals
|
// Global Modals
|
||||||
const BuyModal = require('./components/modals/index').BuyModal
|
const BuyModal = require('./components/modals/index').BuyModal
|
||||||
@ -55,6 +57,7 @@ function mapStateToProps (state) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
// state from plugin
|
// state from plugin
|
||||||
|
networkDropdownOpen: state.appState.networkDropdownOpen,
|
||||||
sidebarOpen: state.appState.sidebarOpen,
|
sidebarOpen: state.appState.sidebarOpen,
|
||||||
isLoading: state.appState.isLoading,
|
isLoading: state.appState.isLoading,
|
||||||
loadingMessage: state.appState.loadingMessage,
|
loadingMessage: state.appState.loadingMessage,
|
||||||
@ -81,9 +84,11 @@ function mapStateToProps (state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps (dispatch) {
|
function mapDispatchToProps (dispatch, ownProps) {
|
||||||
return {
|
return {
|
||||||
hideSidebar: () => {dispatch(actions.hideSidebar())},
|
hideSidebar: () => {dispatch(actions.hideSidebar())},
|
||||||
|
showNetworkDropdown: () => {dispatch(actions.showNetworkDropdown())},
|
||||||
|
hideNetworkDropdown: () => {dispatch(actions.hideNetworkDropdown())},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +120,11 @@ App.prototype.render = function () {
|
|||||||
this.renderSidebar(),
|
this.renderSidebar(),
|
||||||
|
|
||||||
// network dropdown
|
// network dropdown
|
||||||
this.renderNetworkDropdown(),
|
h(NetworkDropdown, {
|
||||||
|
provider: this.props.provider,
|
||||||
|
frequentRpcList: this.props.frequentRpcList,
|
||||||
|
}, []),
|
||||||
|
// this.renderNetworkDropdown(),
|
||||||
// this.renderDropdown(),
|
// this.renderDropdown(),
|
||||||
|
|
||||||
h(Loading, {
|
h(Loading, {
|
||||||
@ -233,7 +242,14 @@ App.prototype.renderAppBar = function () {
|
|||||||
onClick: (event) => {
|
onClick: (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
this.setState({ isNetworkMenuOpen: !isNetworkMenuOpen })
|
console.log("NI CLICK:", this.props.networkDropdownOpen)
|
||||||
|
if (this.props.networkDropdownOpen === false) {
|
||||||
|
this.props.showNetworkDropdown()
|
||||||
|
} else {
|
||||||
|
this.props.hideNetworkDropdown()
|
||||||
|
}
|
||||||
|
// this.props.toggleNetworkOpen()
|
||||||
|
// this.setState({ isNetworkMenuOpen: !isNetworkMenuOpen })
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -249,6 +265,7 @@ App.prototype.renderNetworkDropdown = function () {
|
|||||||
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 || {}
|
||||||
|
console.log("this.state:", state)
|
||||||
const isOpen = state.isNetworkMenuOpen
|
const isOpen = state.isNetworkMenuOpen
|
||||||
|
|
||||||
return h(Dropdown, {
|
return h(Dropdown, {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// App-Specific Instances
|
// App-Specific Instances
|
||||||
// const AccountSelectionDropdown = require('./account-selection-dropdown')
|
// const AccountSelectionDropdown = require('./account-selection-dropdown')
|
||||||
// const AccountOptionsDropdown = require('./account-options-dropdown')
|
// const AccountOptionsDropdown = require('./account-options-dropdown')
|
||||||
const NetworkDropdown = require('./network-dropdown')
|
const NetworkDropdown = require('./network-dropdown').default
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// AccountSelectionDropdown,
|
// AccountSelectionDropdown,
|
||||||
|
@ -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
|
@ -38,6 +38,7 @@ function reduceApp (state, action) {
|
|||||||
menuOpen: false,
|
menuOpen: false,
|
||||||
modalOpen: false,
|
modalOpen: false,
|
||||||
sidebarOpen: false,
|
sidebarOpen: false,
|
||||||
|
networkDropdownOpen: false,
|
||||||
currentView: seedWords ? seedConfView : defaultView,
|
currentView: seedWords ? seedConfView : defaultView,
|
||||||
accountDetail: {
|
accountDetail: {
|
||||||
subview: 'transactions',
|
subview: 'transactions',
|
||||||
@ -51,6 +52,17 @@ function reduceApp (state, action) {
|
|||||||
}, state.appState)
|
}, state.appState)
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
// dropdown methods
|
||||||
|
case actions.NETWORK_DROPDOWN_OPEN:
|
||||||
|
return extend(appState, {
|
||||||
|
networkDropdownOpen: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
case actions.NETWORK_DROPDOWN_CLOSE:
|
||||||
|
return extend(appState, {
|
||||||
|
networkDropdownOpen: false,
|
||||||
|
})
|
||||||
|
|
||||||
// sidebar methods
|
// sidebar methods
|
||||||
case actions.SIDEBAR_OPEN:
|
case actions.SIDEBAR_OPEN:
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
@ -74,7 +86,6 @@ function reduceApp (state, action) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// transition methods
|
// transition methods
|
||||||
|
|
||||||
case actions.TRANSITION_FORWARD:
|
case actions.TRANSITION_FORWARD:
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
transForward: true,
|
transForward: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user