Implement backdrop for wrong network, don't allow to close wrong network notification
This commit is contained in:
parent
33d8153593
commit
102acbc392
|
@ -0,0 +1,23 @@
|
||||||
|
// @flow
|
||||||
|
import React from 'react'
|
||||||
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
|
import ReactDOM from 'react-dom'
|
||||||
|
import Backdrop from '@material-ui/core/Backdrop'
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
root: {
|
||||||
|
zIndex: 1300,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const BackdropLayout = ({ isOpen = false }: { isOpen: boolean }) => {
|
||||||
|
if (!isOpen) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const classes = useStyles()
|
||||||
|
|
||||||
|
return ReactDOM.createPortal(<Backdrop classes={{ root: classes.root }} open />, document.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BackdropLayout
|
|
@ -1,11 +1,16 @@
|
||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
|
import { connect } from 'react-redux'
|
||||||
import { SnackbarProvider } from 'notistack'
|
import { SnackbarProvider } from 'notistack'
|
||||||
import { withStyles } from '@material-ui/core/styles'
|
import { withStyles } from '@material-ui/core/styles'
|
||||||
|
import { getNetwork } from '~/config'
|
||||||
|
import { ETHEREUM_NETWORK } from '~/logic/wallets/getWeb3'
|
||||||
import SidebarProvider from '~/components/Sidebar'
|
import SidebarProvider from '~/components/Sidebar'
|
||||||
import Header from '~/components/Header'
|
import Header from '~/components/Header'
|
||||||
|
import Backdrop from '~/components/layout/Backdrop'
|
||||||
import Img from '~/components/layout/Img'
|
import Img from '~/components/layout/Img'
|
||||||
import Notifier from '~/components/Notifier'
|
import Notifier from '~/components/Notifier'
|
||||||
|
import { networkSelector } from '~/logic/wallets/store/selectors'
|
||||||
import AlertLogo from './assets/alert.svg'
|
import AlertLogo from './assets/alert.svg'
|
||||||
import CheckLogo from './assets/check.svg'
|
import CheckLogo from './assets/check.svg'
|
||||||
import ErrorLogo from './assets/error.svg'
|
import ErrorLogo from './assets/error.svg'
|
||||||
|
@ -53,33 +58,48 @@ const notificationStyles = {
|
||||||
type Props = {
|
type Props = {
|
||||||
children: React.Node,
|
children: React.Node,
|
||||||
classes: Object,
|
classes: Object,
|
||||||
|
currentNetwork: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const PageFrame = ({ children, classes }: Props) => (
|
const desiredNetwork = getNetwork()
|
||||||
<div className={styles.frame}>
|
|
||||||
<SnackbarProvider
|
|
||||||
maxSnack={5}
|
|
||||||
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
|
||||||
classes={{
|
|
||||||
variantSuccess: classes.success,
|
|
||||||
variantError: classes.error,
|
|
||||||
variantWarning: classes.warning,
|
|
||||||
variantInfo: classes.info,
|
|
||||||
}}
|
|
||||||
iconVariant={{
|
|
||||||
success: <Img src={CheckLogo} alt="Success" />,
|
|
||||||
error: <Img src={ErrorLogo} alt="Error" />,
|
|
||||||
warning: <Img src={AlertLogo} alt="Warning" />,
|
|
||||||
info: '',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Notifier />
|
|
||||||
<SidebarProvider>
|
|
||||||
<Header />
|
|
||||||
{children}
|
|
||||||
</SidebarProvider>
|
|
||||||
</SnackbarProvider>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default withStyles(notificationStyles)(PageFrame)
|
const PageFrame = ({ children, classes, currentNetwork }: Props) => {
|
||||||
|
const isWrongNetwork = currentNetwork !== ETHEREUM_NETWORK.UNKNOWN && currentNetwork !== desiredNetwork
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.frame}>
|
||||||
|
<Backdrop isOpen={isWrongNetwork} />
|
||||||
|
<SnackbarProvider
|
||||||
|
maxSnack={5}
|
||||||
|
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
|
||||||
|
classes={{
|
||||||
|
variantSuccess: classes.success,
|
||||||
|
variantError: classes.error,
|
||||||
|
variantWarning: classes.warning,
|
||||||
|
variantInfo: classes.info,
|
||||||
|
}}
|
||||||
|
iconVariant={{
|
||||||
|
success: <Img src={CheckLogo} alt="Success" />,
|
||||||
|
error: <Img src={ErrorLogo} alt="Error" />,
|
||||||
|
warning: <Img src={AlertLogo} alt="Warning" />,
|
||||||
|
info: '',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Notifier />
|
||||||
|
<SidebarProvider>
|
||||||
|
<Header />
|
||||||
|
{children}
|
||||||
|
</SidebarProvider>
|
||||||
|
</SnackbarProvider>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withStyles(notificationStyles)(
|
||||||
|
connect(
|
||||||
|
(state) => ({
|
||||||
|
currentNetwork: networkSelector(state),
|
||||||
|
}),
|
||||||
|
null,
|
||||||
|
)(PageFrame),
|
||||||
|
)
|
||||||
|
|
|
@ -4,9 +4,8 @@ import { ETHEREUM_NETWORK_IDS, ETHEREUM_NETWORK, getProviderInfo } from '~/logic
|
||||||
import { getNetwork } from '~/config'
|
import { getNetwork } from '~/config'
|
||||||
import type { ProviderProps } from '~/logic/wallets/store/model/provider'
|
import type { ProviderProps } from '~/logic/wallets/store/model/provider'
|
||||||
import { makeProvider } from '~/logic/wallets/store/model/provider'
|
import { makeProvider } from '~/logic/wallets/store/model/provider'
|
||||||
import { NOTIFICATIONS, showSnackbar, enhanceSnackbarForAction } from '~/logic/notifications'
|
import { NOTIFICATIONS, enhanceSnackbarForAction } from '~/logic/notifications'
|
||||||
import enqueueSnackbar from '~/logic/notifications/store/actions/enqueueSnackbar'
|
import enqueueSnackbar from '~/logic/notifications/store/actions/enqueueSnackbar'
|
||||||
import closeSnackbar from '~/logic/notifications/store/actions/closeSnackbar'
|
|
||||||
|
|
||||||
import addProvider from './addProvider'
|
import addProvider from './addProvider'
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ const handleProviderNotification = (provider: ProviderProps, dispatch: Function)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ETHEREUM_NETWORK_IDS[network] !== getNetwork()) {
|
if (ETHEREUM_NETWORK_IDS[network] !== getNetwork()) {
|
||||||
dispatch(enqueueSnackbar(enhanceSnackbarForAction(NOTIFICATIONS.WRONG_NETWORK_MSG)))
|
dispatch(enqueueSnackbar(NOTIFICATIONS.WRONG_NETWORK_MSG))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (ETHEREUM_NETWORK.RINKEBY === getNetwork()) {
|
if (ETHEREUM_NETWORK.RINKEBY === getNetwork()) {
|
||||||
|
|
Loading…
Reference in New Issue