1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 05:12:18 +01:00
metamask-extension/ui/app/components/modals/modal.js

439 lines
9.7 KiB
JavaScript
Raw Normal View History

2018-07-11 06:20:40 +02:00
const Component = require('react').Component
2017-08-08 22:37:41 +02:00
const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('react-redux').connect
2017-08-08 22:37:41 +02:00
const FadeModal = require('boron').FadeModal
const actions = require('../../actions')
const isMobileView = require('../../../lib/is-mobile-view')
const { getEnvironmentType } = require('../../../../app/scripts/lib/util')
const { ENVIRONMENT_TYPE_POPUP } = require('../../../../app/scripts/lib/enums')
// 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-05-31 01:17:40 +02:00
const ConfirmResetAccount = require('./confirm-reset-account')
2018-07-11 01:19:29 +02:00
const ConfirmRemoveAccount = require('./confirm-remove-account')
const TransactionConfirmed = require('./transaction-confirmed')
2018-05-31 01:17:40 +02:00
const WelcomeBeta = require('./welcome-beta')
const Notification = require('./notification')
import ConfirmCustomizeGasModal from './customize-gas'
2018-05-31 01:17:40 +02:00
const modalContainerBaseStyle = {
transform: 'translate3d(-50%, 0, 0px)',
border: '1px solid #CCCFD1',
borderRadius: '8px',
backgroundColor: '#FFFFFF',
boxShadow: '0 2px 22px 0 rgba(0,0,0,0.2)',
}
const modalContainerLaptopStyle = {
...modalContainerBaseStyle,
width: '344px',
top: '15%',
}
const modalContainerMobileStyle = {
...modalContainerBaseStyle,
width: '309px',
top: '12.5%',
}
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: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP ? '52vh' : '36.5vh',
2017-09-29 21:03:29 +02:00
},
laptopModalStyle: {
width: '449px',
top: 'calc(33% + 45px)',
},
},
BETA_UI_NOTIFICATION_MODAL: {
contents: [
2018-05-31 01:17:40 +02:00
h(Notification, [
h(WelcomeBeta),
]),
],
mobileModalStyle: {
2018-05-31 01:17:40 +02:00
...modalContainerMobileStyle,
},
laptopModalStyle: {
2018-05-31 01:17:40 +02:00
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
},
},
OLD_UI_NOTIFICATION_MODAL: {
contents: [
h(NotifcationModal, {
2018-03-15 00:31:45 +01:00
header: 'oldUI',
message: 'oldUIMessage',
}),
],
mobileModalStyle: {
width: '95%',
top: getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_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: {
2018-05-31 01:17:40 +02:00
...modalContainerMobileStyle,
2018-02-08 18:18:25 +01:00
},
laptopModalStyle: {
2018-05-31 01:17:40 +02:00
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
2018-02-08 18:18:25 +01:00
},
},
2018-07-11 07:35:37 +02:00
CONFIRM_REMOVE_ACCOUNT: {
2018-07-11 01:19:29 +02:00
contents: h(ConfirmRemoveAccount),
mobileModalStyle: {
...modalContainerMobileStyle,
},
laptopModalStyle: {
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
},
},
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: {
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',
},
},
CONFIRM_CUSTOMIZE_GAS: {
contents: [
h(ConfirmCustomizeGasModal),
],
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',
},
},
TRANSACTION_CONFIRMED: {
disableBackdropClick: true,
contents: [
2018-05-31 01:17:40 +02:00
h(Notification, [
h(TransactionConfirmed),
]),
],
mobileModalStyle: {
2018-05-31 01:17:40 +02:00
...modalContainerMobileStyle,
},
laptopModalStyle: {
2018-05-31 01:17:40 +02:00
...modalContainerLaptopStyle,
},
contentStyle: {
borderRadius: '8px',
},
},
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 { contents: children, disableBackdropClick = false } = modal
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,
closeOnClick: !disableBackdropClick,
2017-08-08 22:37:41 +02:00
},
2018-07-11 06:20:40 +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()
}