mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Extend modal implementation and state management to accomodate multiple modal types
This commit is contained in:
parent
e550d36084
commit
4e9376ca71
@ -791,15 +791,17 @@ function hideNetworkDropdown () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showModal () {
|
function showModal (payload) {
|
||||||
return {
|
return {
|
||||||
type: actions.MODAL_OPEN,
|
type: actions.MODAL_OPEN,
|
||||||
|
payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideModal () {
|
function hideModal (payload) {
|
||||||
return {
|
return {
|
||||||
type: actions.MODAL_CLOSE,
|
type: actions.MODAL_CLOSE,
|
||||||
|
payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ const ReactCSSTransitionGroup = require('react-addons-css-transition-group')
|
|||||||
const NetworkDropdown = require('./components/dropdowns/network-dropdown')
|
const NetworkDropdown = require('./components/dropdowns/network-dropdown')
|
||||||
|
|
||||||
// Global Modals
|
// Global Modals
|
||||||
const BuyModal = require('./components/modals/index').BuyModal
|
const Modal = require('./components/modals/index').Modal
|
||||||
|
|
||||||
module.exports = connect(mapStateToProps, mapDispatchToProps)(App)
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(App)
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ App.prototype.render = function () {
|
|||||||
}, [
|
}, [
|
||||||
|
|
||||||
// global modal
|
// global modal
|
||||||
h(BuyModal, {}, []),
|
h(Modal, {}, []),
|
||||||
|
|
||||||
// app bar
|
// app bar
|
||||||
this.renderAppBar(),
|
this.renderAppBar(),
|
||||||
|
@ -6,10 +6,20 @@ const FadeModal = require('boron').FadeModal
|
|||||||
const actions = require('../../actions')
|
const actions = require('../../actions')
|
||||||
const isMobileView = require('../../../lib/is-mobile-view')
|
const isMobileView = require('../../../lib/is-mobile-view')
|
||||||
const isPopupOrNotification = require('../../../../app/scripts/lib/is-popup-or-notification')
|
const isPopupOrNotification = require('../../../../app/scripts/lib/is-popup-or-notification')
|
||||||
|
const BuyOptions = require('../buy-options')
|
||||||
|
|
||||||
|
const MODALS = {
|
||||||
|
BUY: [
|
||||||
|
h(BuyOptions, {}, []),
|
||||||
|
],
|
||||||
|
EDIT_ACCOUNT_NAME: [],
|
||||||
|
ACCOUNT_DETAILS: [],
|
||||||
|
}
|
||||||
|
|
||||||
function mapStateToProps (state) {
|
function mapStateToProps (state) {
|
||||||
return {
|
return {
|
||||||
active: state.appState.modalOpen
|
active: state.appState.modal.open,
|
||||||
|
modalState: state.appState.modal.modalState,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +58,8 @@ const backdropStyles = {
|
|||||||
|
|
||||||
Modal.prototype.render = function () {
|
Modal.prototype.render = function () {
|
||||||
|
|
||||||
|
const children = MODALS[this.props.modalState.name] || []
|
||||||
|
|
||||||
return h(FadeModal,
|
return h(FadeModal,
|
||||||
{
|
{
|
||||||
className: 'modal',
|
className: 'modal',
|
||||||
@ -59,7 +71,7 @@ Modal.prototype.render = function () {
|
|||||||
modalStyle: isMobileView() ? mobileModalStyles : laptopModalStyles,
|
modalStyle: isMobileView() ? mobileModalStyles : laptopModalStyles,
|
||||||
backdropStyle: backdropStyles,
|
backdropStyle: backdropStyles,
|
||||||
},
|
},
|
||||||
this.props.children,
|
children,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ function mapDispatchToProps (dispatch) {
|
|||||||
return {
|
return {
|
||||||
showSidebar: () => { dispatch(actions.showSidebar()) },
|
showSidebar: () => { dispatch(actions.showSidebar()) },
|
||||||
hideSidebar: () => { dispatch(actions.hideSidebar()) },
|
hideSidebar: () => { dispatch(actions.hideSidebar()) },
|
||||||
showModal: () => { dispatch(actions.showModal()) },
|
showModal: (payload) => { dispatch(actions.showModal(payload)) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,9 @@ TxView.prototype.render = function () {
|
|||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
},
|
},
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
this.props.showModal()
|
this.props.showModal({
|
||||||
|
name: 'BUY',
|
||||||
|
})
|
||||||
},
|
},
|
||||||
}, 'BUY'),
|
}, 'BUY'),
|
||||||
|
|
||||||
|
@ -36,7 +36,12 @@ function reduceApp (state, action) {
|
|||||||
var appState = extend({
|
var appState = extend({
|
||||||
shouldClose: false,
|
shouldClose: false,
|
||||||
menuOpen: false,
|
menuOpen: false,
|
||||||
modalOpen: false,
|
modal: {
|
||||||
|
open: false,
|
||||||
|
modalState: {
|
||||||
|
name: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
sidebarOpen: false,
|
sidebarOpen: false,
|
||||||
networkDropdownOpen: false,
|
networkDropdownOpen: false,
|
||||||
currentView: seedWords ? seedConfView : defaultView,
|
currentView: seedWords ? seedConfView : defaultView,
|
||||||
@ -77,12 +82,20 @@ function reduceApp (state, action) {
|
|||||||
// modal methods:
|
// modal methods:
|
||||||
case actions.MODAL_OPEN:
|
case actions.MODAL_OPEN:
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
modalOpen: true,
|
modal: Object.assign(
|
||||||
|
state.appState.modal,
|
||||||
|
{ open: true },
|
||||||
|
{ modalState: action.payload },
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
case actions.MODAL_CLOSE:
|
case actions.MODAL_CLOSE:
|
||||||
return extend(appState, {
|
return extend(appState, {
|
||||||
modalOpen: false,
|
modal: Object.assign(
|
||||||
|
state.appState.modal,
|
||||||
|
{ open: false },
|
||||||
|
{ modalState: action.payload || state.appState.modal.modalState },
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
// transition methods
|
// transition methods
|
||||||
|
Loading…
Reference in New Issue
Block a user