1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00
metamask-extension/ui/app/components/modals/modal.js

356 lines
7.9 KiB
JavaScript
Raw Normal View History

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
const actions = require('../../actions')
const isMobileView = require('../../../lib/is-mobile-view')
const isPopupOrNotification = require('../../../../app/scripts/lib/is-popup-or-notification')
const t = require('../../../i18n')
// Modal Components
const BuyOptions = require('./buy-options-modal')
const DepositEtherModal = require('./deposit-ether-modal')
const AccountDetailsModal = require('./account-details-modal')
const EditAccountNameModal = require('./edit-account-name-modal')
const ExportPrivateKeyModal = require('./export-private-key-modal')
2017-08-21 04:28:20 +02:00
const NewAccountModal = require('./new-account-modal')
2017-09-29 17:40:57 +02:00
const ShapeshiftDepositTxModal = require('./shapeshift-deposit-tx-modal.js')
2017-09-29 21:03:29 +02:00
const HideTokenConfirmationModal = require('./hide-token-confirmation-modal')
const CustomizeGasModal = require('../customize-gas-modal')
const NotifcationModal = require('./notification-modal')
2018-02-08 18:18:25 +01:00
const ConfirmResetAccount = require('./notification-modals/confirm-reset-account')
const accountModalStyle = {
mobileModalStyle: {
width: '95%',
2017-09-29 01:34:42 +02:00
// top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh',
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
borderRadius: '4px',
2017-09-29 01:34:42 +02:00
top: '10%',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
laptopModalStyle: {
width: '360px',
2017-09-29 01:34:42 +02:00
// top: 'calc(33% + 45px)',
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
borderRadius: '4px',
2017-09-29 01:34:42 +02:00
top: '10%',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
contentStyle: {
borderRadius: '4px',
},
}
const MODALS = {
BUY: {
contents: [
h(BuyOptions, {}, []),
],
mobileModalStyle: {
width: '95%',
2017-09-29 01:34:42 +02:00
// top: isPopupOrNotification() === 'popup' ? '48vh' : '36.5vh',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
2017-09-20 03:49:35 +02:00
boxShadow: '0 0 7px 0 rgba(0,0,0,0.08)',
2017-09-29 01:34:42 +02:00
top: '10%',
},
laptopModalStyle: {
width: '66%',
2017-09-20 03:49:35 +02:00
maxWidth: '550px',
2017-09-29 01:34:42 +02:00
top: 'calc(10% + 10px)',
left: '0',
right: '0',
margin: '0 auto',
2017-09-20 03:49:35 +02:00
boxShadow: '0 0 7px 0 rgba(0,0,0,0.08)',
2017-09-29 01:34:42 +02:00
transform: 'none',
},
},
DEPOSIT_ETHER: {
contents: [
h(DepositEtherModal, {}, []),
],
onHide: (props) => props.hideWarning(),
mobileModalStyle: {
width: '100%',
height: '100%',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
boxShadow: '0 0 7px 0 rgba(0,0,0,0.08)',
top: '0',
display: 'flex',
},
laptopModalStyle: {
2018-03-12 19:25:12 +01:00
width: '850px',
top: 'calc(10% + 10px)',
left: '0',
right: '0',
margin: '0 auto',
boxShadow: '0 0 6px 0 rgba(0,0,0,0.3)',
2018-03-12 19:25:12 +01:00
borderRadius: '7px',
transform: 'none',
2018-03-12 19:25:12 +01:00
height: 'calc(80% - 20px)',
overflowY: 'hidden',
},
contentStyle: {
2018-03-12 19:25:12 +01:00
borderRadius: '7px',
height: '100%',
},
},
EDIT_ACCOUNT_NAME: {
contents: [
h(EditAccountNameModal, {}, []),
],
mobileModalStyle: {
width: '95%',
2017-09-29 01:34:42 +02:00
// top: isPopupOrNotification() === 'popup' ? '48vh' : '36.5vh',
top: '10%',
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
2017-09-29 01:34:42 +02:00
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
laptopModalStyle: {
width: '375px',
2017-09-29 01:34:42 +02:00
// top: 'calc(30% + 10px)',
top: '10%',
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 2px 2px 2px',
2017-09-29 01:34:42 +02:00
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
},
ACCOUNT_DETAILS: {
contents: [
h(AccountDetailsModal, {}, []),
],
...accountModalStyle,
},
EXPORT_PRIVATE_KEY: {
contents: [
h(ExportPrivateKeyModal, {}, []),
],
...accountModalStyle,
},
2017-09-29 17:40:57 +02:00
SHAPESHIFT_DEPOSIT_TX: {
contents: [
h(ShapeshiftDepositTxModal),
],
...accountModalStyle,
},
2017-09-29 21:03:29 +02:00
HIDE_TOKEN_CONFIRMATION: {
contents: [
h(HideTokenConfirmationModal, {}, []),
],
mobileModalStyle: {
width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh',
},
laptopModalStyle: {
width: '449px',
top: 'calc(33% + 45px)',
},
},
BETA_UI_NOTIFICATION_MODAL: {
contents: [
h(NotifcationModal, {
header: t('uiWelcome'),
message: t('uiWelcomeMessage'),
}),
],
mobileModalStyle: {
width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh',
},
laptopModalStyle: {
width: '449px',
top: 'calc(33% + 45px)',
},
},
OLD_UI_NOTIFICATION_MODAL: {
contents: [
h(NotifcationModal, {
header: t('oldUI'),
message: t('oldUIMessage'),
}),
],
mobileModalStyle: {
width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh',
},
laptopModalStyle: {
width: '449px',
top: 'calc(33% + 45px)',
},
},
2018-02-08 18:18:25 +01:00
CONFIRM_RESET_ACCOUNT: {
contents: h(ConfirmResetAccount),
mobileModalStyle: {
width: '95%',
top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh',
},
laptopModalStyle: {
width: '473px',
top: 'calc(33% + 45px)',
},
},
NEW_ACCOUNT: {
contents: [
h(NewAccountModal, {}, []),
],
mobileModalStyle: {
width: '95%',
2017-09-29 01:34:42 +02:00
// top: isPopupOrNotification() === 'popup' ? '52vh' : '36.5vh',
top: '10%',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
laptopModalStyle: {
width: '449px',
2017-09-29 01:34:42 +02:00
// top: 'calc(33% + 45px)',
top: '10%',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
},
CUSTOMIZE_GAS: {
contents: [
h(CustomizeGasModal, {}, []),
],
mobileModalStyle: {
2017-10-25 10:08:14 +02:00
width: '100vw',
height: '100vh',
top: '0',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
laptopModalStyle: {
width: '720px',
height: '377px',
top: '80px',
transform: 'none',
left: '0',
right: '0',
margin: '0 auto',
},
},
DEFAULT: {
contents: [],
mobileModalStyle: {},
laptopModalStyle: {},
2017-08-29 16:50:48 +02:00
},
}
const BACKDROPSTYLE = {
2017-11-09 00:41:29 +01:00
backgroundColor: 'rgba(0, 0, 0, 0.5)',
}
2017-08-08 22:37:41 +02:00
function mapStateToProps (state) {
return {
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())
},
hideWarning: () => {
dispatch(actions.hideWarning())
},
2017-08-08 22:37:41 +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)
Modal.prototype.render = function () {
const modal = MODALS[this.props.modalState.name || 'DEFAULT']
const children = modal.contents
const modalStyle = modal[isMobileView() ? 'mobileModalStyle' : 'laptopModalStyle']
2017-11-02 13:15:59 +01:00
const contentStyle = modal.contentStyle || {}
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: () => {
if (modal.onHide) {
modal.onHide(this.props)
}
this.onHide()
},
2017-08-08 22:37:41 +02:00
ref: (ref) => {
this.modalRef = ref
},
modalStyle,
2017-09-11 09:45:06 +02:00
contentStyle,
backdropStyle: BACKDROPSTYLE,
2017-08-08 22:37:41 +02:00
},
children,
2017-08-08 22:37:41 +02:00
)
}
2017-08-29 16:50:48 +02:00
Modal.prototype.componentWillReceiveProps = function (nextProps) {
2017-08-08 22:37:41 +02:00
if (nextProps.active) {
this.show()
} else if (this.props.active) {
this.hide()
}
}
2017-08-29 16:50:48 +02:00
Modal.prototype.onHide = function () {
2017-08-08 22:37:41 +02:00
if (this.props.onHideCallback) {
this.props.onHideCallback()
}
this.props.hideModal()
}
2017-08-29 16:50:48 +02:00
Modal.prototype.hide = function () {
2017-08-08 22:37:41 +02:00
this.modalRef.hide()
}
2017-08-29 16:50:48 +02:00
Modal.prototype.show = function () {
2017-08-08 22:37:41 +02:00
this.modalRef.show()
}