2017-08-08 22:37:41 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
|
|
|
const connect = require('react-redux').connect
|
|
|
|
const FadeModal = require('boron').FadeModal
|
2017-08-13 19:24:51 +02:00
|
|
|
const actions = require('../../actions')
|
|
|
|
const isMobileView = require('../../../lib/is-mobile-view')
|
|
|
|
const isPopupOrNotification = require('../../../../app/scripts/lib/is-popup-or-notification')
|
2017-08-21 04:10:49 +02:00
|
|
|
|
|
|
|
// Modal Components
|
|
|
|
const BuyOptions = require('./buy-options-modal')
|
|
|
|
const AccountDetailsModal = require('./account-details-modal')
|
|
|
|
const EditAccountNameModal = require('./edit-account-name-modal')
|
2017-08-21 04:28:20 +02:00
|
|
|
const NewAccountModal = require('./new-account-modal')
|
2017-08-21 03:32:58 +02:00
|
|
|
|
|
|
|
const MODALS = {
|
2017-08-21 12:53:01 +02:00
|
|
|
BUY: {
|
|
|
|
contents: [
|
|
|
|
h(BuyOptions, {}, []),
|
|
|
|
],
|
|
|
|
mobileModalStyle: {
|
|
|
|
width: '95%',
|
|
|
|
top: isPopupOrNotification() === 'popup' ? '48vh' : '36.5vh',
|
|
|
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
|
|
|
},
|
|
|
|
laptopModalStyle: {
|
|
|
|
width: '66%',
|
|
|
|
top: 'calc(30% + 10px)',
|
|
|
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
EDIT_ACCOUNT_NAME: {
|
|
|
|
contents: [
|
|
|
|
h(EditAccountNameModal, {}, []),
|
|
|
|
],
|
|
|
|
mobileModalStyle: {
|
|
|
|
width: '95%',
|
|
|
|
top: isPopupOrNotification() === 'popup' ? '48vh' : '36.5vh',
|
|
|
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
|
|
|
},
|
|
|
|
laptopModalStyle: {
|
2017-08-21 14:58:30 +02:00
|
|
|
width: '375px',
|
2017-08-21 12:53:01 +02:00
|
|
|
top: 'calc(30% + 10px)',
|
|
|
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ACCOUNT_DETAILS: {
|
|
|
|
contents: [
|
|
|
|
h(AccountDetailsModal, {}, []),
|
|
|
|
],
|
2017-08-21 14:58:30 +02:00
|
|
|
mobileModalStyle: {
|
|
|
|
width: '95%',
|
|
|
|
top: isPopupOrNotification() === 'popup' ? '48vh' : '36.5vh',
|
|
|
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
|
|
|
},
|
|
|
|
laptopModalStyle: {
|
|
|
|
width: '360px',
|
|
|
|
top: 'calc(30% + 10px)',
|
|
|
|
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
|
|
|
|
},
|
2017-08-21 12:53:01 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
NEW_ACCOUNT: {
|
|
|
|
contents: [
|
|
|
|
h(NewAccountModal, {}, []),
|
|
|
|
],
|
|
|
|
mobileModalStyle: {},
|
|
|
|
laptopModalStyle: {}
|
|
|
|
},
|
|
|
|
|
|
|
|
DEFAULT: {
|
|
|
|
contents: [],
|
|
|
|
mobileModalStyle: {},
|
|
|
|
laptopModalStyle: {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const BACKDROPSTYLE = {
|
|
|
|
backgroundColor: 'rgba(245, 245, 245, 0.85)',
|
2017-08-21 03:32:58 +02:00
|
|
|
}
|
2017-08-08 22:37:41 +02:00
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
2017-08-21 03:32:58 +02:00
|
|
|
active: state.appState.modal.open,
|
|
|
|
modalState: state.appState.modal.modalState,
|
2017-08-08 22:37:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
hideModal: () => {
|
|
|
|
dispatch(actions.hideModal())
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-13 19:24:51 +02:00
|
|
|
// Global Modal Component
|
2017-08-08 22:37:41 +02:00
|
|
|
inherits(Modal, Component)
|
|
|
|
function Modal () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(Modal)
|
|
|
|
|
2017-08-09 03:44:20 +02:00
|
|
|
Modal.prototype.render = function () {
|
2017-08-21 12:53:01 +02:00
|
|
|
const modal = MODALS[this.props.modalState.name || 'DEFAULT']
|
2017-08-09 02:51:06 +02:00
|
|
|
|
2017-08-21 12:53:01 +02:00
|
|
|
const children = modal.contents
|
|
|
|
const modalStyle = modal[isMobileView() ? 'mobileModalStyle' : 'laptopModalStyle']
|
2017-08-21 03:32:58 +02:00
|
|
|
|
2017-08-08 22:37:41 +02:00
|
|
|
return h(FadeModal,
|
|
|
|
{
|
2017-08-08 23:05:19 +02:00
|
|
|
className: 'modal',
|
2017-08-08 22:37:41 +02:00
|
|
|
keyboard: false,
|
|
|
|
onHide: () => {this.onHide()},
|
|
|
|
ref: (ref) => {
|
|
|
|
this.modalRef = ref
|
|
|
|
},
|
2017-08-21 12:53:01 +02:00
|
|
|
modalStyle,
|
|
|
|
backdropStyle: BACKDROPSTYLE,
|
2017-08-08 22:37:41 +02:00
|
|
|
},
|
2017-08-21 03:32:58 +02:00
|
|
|
children,
|
2017-08-08 22:37:41 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
Modal.prototype.componentWillReceiveProps = function(nextProps) {
|
|
|
|
if (nextProps.active) {
|
|
|
|
this.show()
|
|
|
|
} else if (this.props.active) {
|
|
|
|
this.hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Modal.prototype.onHide = function() {
|
|
|
|
if (this.props.onHideCallback) {
|
|
|
|
this.props.onHideCallback()
|
|
|
|
}
|
|
|
|
this.props.hideModal()
|
|
|
|
}
|
|
|
|
|
|
|
|
Modal.prototype.hide = function() {
|
|
|
|
this.modalRef.hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
Modal.prototype.show = function() {
|
|
|
|
this.modalRef.show()
|
|
|
|
}
|