diff --git a/src/routes/safe/components/Settings/ChangeSafeName/index.jsx b/src/routes/safe/components/Settings/ChangeSafeName/index.jsx index 886016eb..7c368172 100644 --- a/src/routes/safe/components/Settings/ChangeSafeName/index.jsx +++ b/src/routes/safe/components/Settings/ChangeSafeName/index.jsx @@ -1,11 +1,11 @@ // @flow import React from 'react' import { withStyles } from '@material-ui/core/styles' +import { withSnackbar } from 'notistack' import Block from '~/components/layout/Block' import Col from '~/components/layout/Col' import Field from '~/components/forms/Field' import Heading from '~/components/layout/Heading' -import { SharedSnackbarConsumer } from '~/components/SharedSnackBar' import { composeValidators, required, minMaxLength } from '~/components/forms/validator' import TextField from '~/components/forms/TextField' import GnoForm from '~/components/forms/GnoForm' @@ -22,17 +22,17 @@ type Props = { safeAddress: string, safeName: string, updateSafe: Function, - openSnackbar: Function, + enqueueSnackbar: Function, } const ChangeSafeName = (props: Props) => { const { - classes, safeAddress, safeName, updateSafe, openSnackbar, + classes, safeAddress, safeName, updateSafe, enqueueSnackbar, } = props const handleSubmit = (values) => { updateSafe({ address: safeAddress, name: values.safeName }) - openSnackbar('Safe name changed', 'success') + enqueueSnackbar('Safe name changed', 'success') } return ( @@ -80,10 +80,4 @@ const ChangeSafeName = (props: Props) => { ) } -const withSnackbar = (props) => ( - - {({ openSnackbar }) => } - -) - -export default withStyles(styles)(withSnackbar) +export default withStyles(styles)(withSnackbar(ChangeSafeName)) diff --git a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx index 1ace6021..893ba5db 100644 --- a/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/AddOwnerModal/index.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react' import { List } from 'immutable' import { withStyles } from '@material-ui/core/styles' -import { SharedSnackbarConsumer } from '~/components/SharedSnackBar' +import { withSnackbar } from 'notistack' import Modal from '~/components/Modal' import { type Owner } from '~/routes/safe/store/models/owner' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' @@ -29,6 +29,7 @@ type Props = { network: string, addSafeOwner: Function, createTransaction: Function, + enqueueSnackbar: Function, } type ActiveScreen = 'selectOwner' | 'selectThreshold' | 'reviewAddOwner' @@ -36,14 +37,14 @@ export const sendAddOwner = async ( values: Object, safeAddress: string, ownersOld: List, - openSnackbar: Function, + enqueueSnackbar: Function, createTransaction: Function, addSafeOwner: Function, ) => { const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const txData = gnosisSafe.contract.methods.addOwnerWithThreshold(values.ownerAddress, values.threshold).encodeABI() - const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar) + const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, enqueueSnackbar) if (txHash) { addSafeOwner({ safeAddress, ownerName: values.ownerName, ownerAddress: values.ownerAddress }) @@ -61,6 +62,7 @@ const AddOwner = ({ network, createTransaction, addSafeOwner, + enqueueSnackbar, }: Props) => { const [activeScreen, setActiveScreen] = useState('selectOwner') const [values, setValues] = useState({}) @@ -98,59 +100,51 @@ const AddOwner = ({ setActiveScreen('reviewAddOwner') } - return ( - <> - - {({ openSnackbar }) => { - const onAddOwner = async () => { - onClose() - try { - sendAddOwner(values, safeAddress, owners, openSnackbar, createTransaction, addSafeOwner) - } catch (error) { - // eslint-disable-next-line - console.log('Error while removing an owner ' + error) - } - } + const onAddOwner = async () => { + onClose() + try { + sendAddOwner(values, safeAddress, owners, enqueueSnackbar, createTransaction, addSafeOwner) + } catch (error) { + // eslint-disable-next-line + console.log('Error while removing an owner ' + error) + } + } - return ( - - <> - {activeScreen === 'selectOwner' && ( - - )} - {activeScreen === 'selectThreshold' && ( - - )} - {activeScreen === 'reviewAddOwner' && ( - - )} - - - ) - }} - - + return ( + + <> + {activeScreen === 'selectOwner' && ( + + )} + {activeScreen === 'selectThreshold' && ( + + )} + {activeScreen === 'reviewAddOwner' && ( + + )} + + ) } -export default withStyles(styles)(AddOwner) +export default withStyles(styles)(withSnackbar(AddOwner)) diff --git a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx index c245965b..a4be9c5d 100644 --- a/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/RemoveOwnerModal/index.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react' import { List } from 'immutable' import { withStyles } from '@material-ui/core/styles' -import { SharedSnackbarConsumer } from '~/components/SharedSnackBar' +import { withSnackbar } from 'notistack' import Modal from '~/components/Modal' import { type Owner } from '~/routes/safe/store/models/owner' import { getGnosisSafeInstanceAt, SENTINEL_ADDRESS } from '~/logic/contracts/safeContracts' @@ -31,7 +31,9 @@ type Props = { network: string, createTransaction: Function, removeSafeOwner: Function, + enqueueSnackbar: Function, } + type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner' export const sendRemoveOwner = async ( @@ -40,7 +42,7 @@ export const sendRemoveOwner = async ( ownerAddressToRemove: string, ownerNameToRemove: string, ownersOld: List, - openSnackbar: Function, + enqueueSnackbar: Function, createTransaction: Function, removeSafeOwner: Function, ) => { @@ -54,7 +56,7 @@ export const sendRemoveOwner = async ( .removeOwner(prevAddress, ownerAddressToRemove, values.threshold) .encodeABI() - const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar) + const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, enqueueSnackbar) if (txHash) { removeSafeOwner({ safeAddress, ownerAddress: ownerAddressToRemove }) @@ -74,6 +76,7 @@ const RemoveOwner = ({ network, createTransaction, removeSafeOwner, + enqueueSnackbar, }: Props) => { const [activeScreen, setActiveScreen] = useState('checkOwner') const [values, setValues] = useState({}) @@ -104,71 +107,63 @@ const RemoveOwner = ({ setActiveScreen('reviewRemoveOwner') } - return ( - <> - - {({ openSnackbar }) => { - const onRemoveOwner = () => { - onClose() - sendRemoveOwner( - values, - safeAddress, - ownerAddress, - ownerName, - owners, - openSnackbar, - createTransaction, - removeSafeOwner, - ) - } + const onRemoveOwner = () => { + onClose() + sendRemoveOwner( + values, + safeAddress, + ownerAddress, + ownerName, + owners, + enqueueSnackbar, + createTransaction, + removeSafeOwner, + ) + } - return ( - - <> - {activeScreen === 'checkOwner' && ( - - )} - {activeScreen === 'selectThreshold' && ( - - )} - {activeScreen === 'reviewRemoveOwner' && ( - - )} - - - ) - }} - - + return ( + + <> + {activeScreen === 'checkOwner' && ( + + )} + {activeScreen === 'selectThreshold' && ( + + )} + {activeScreen === 'reviewRemoveOwner' && ( + + )} + + ) } -export default withStyles(styles)(RemoveOwner) +export default withStyles(styles)(withSnackbar(RemoveOwner)) diff --git a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx index 02b9037e..26c63fb0 100644 --- a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react' import { List } from 'immutable' import { withStyles } from '@material-ui/core/styles' -import { SharedSnackbarConsumer } from '~/components/SharedSnackBar' +import { withSnackbar } from 'notistack' import Modal from '~/components/Modal' import { getGnosisSafeInstanceAt, SENTINEL_ADDRESS } from '~/logic/contracts/safeContracts' import OwnerForm from './screens/OwnerForm' @@ -29,6 +29,7 @@ type Props = { threshold: string, createTransaction: Function, replaceSafeOwner: Function, + enqueueSnackbar: Function, } type ActiveScreen = 'checkOwner' | 'reviewReplaceOwner' @@ -36,7 +37,7 @@ export const sendReplaceOwner = async ( values: Object, safeAddress: string, ownerAddressToRemove: string, - openSnackbar: Function, + enqueueSnackbar: Function, createTransaction: Function, replaceSafeOwner: Function, ) => { @@ -50,7 +51,7 @@ export const sendReplaceOwner = async ( .swapOwner(prevAddress, ownerAddressToRemove, values.ownerAddress) .encodeABI() - const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar) + const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, enqueueSnackbar) if (txHash) { replaceSafeOwner({ @@ -75,6 +76,7 @@ const ReplaceOwner = ({ threshold, createTransaction, replaceSafeOwner, + enqueueSnackbar, }: Props) => { const [activeScreen, setActiveScreen] = useState('checkOwner') const [values, setValues] = useState({}) @@ -96,67 +98,59 @@ const ReplaceOwner = ({ setActiveScreen('reviewReplaceOwner') } - return ( - <> - - {({ openSnackbar }) => { - const onReplaceOwner = () => { - onClose() - try { - sendReplaceOwner( - values, - safeAddress, - ownerAddress, - openSnackbar, - createTransaction, - replaceSafeOwner, - ) - } catch (error) { - // eslint-disable-next-line - console.log('Error while removing an owner ' + error) - } - } + const onReplaceOwner = () => { + onClose() + try { + sendReplaceOwner( + values, + safeAddress, + ownerAddress, + enqueueSnackbar, + createTransaction, + replaceSafeOwner, + ) + } catch (error) { + // eslint-disable-next-line + console.log('Error while removing an owner ' + error) + } + } - return ( - - <> - {activeScreen === 'checkOwner' && ( - - )} - {activeScreen === 'reviewReplaceOwner' && ( - - )} - - - ) - }} - - + return ( + + <> + {activeScreen === 'checkOwner' && ( + + )} + {activeScreen === 'reviewReplaceOwner' && ( + + )} + + ) } -export default withStyles(styles)(ReplaceOwner) +export default withStyles(styles)(withSnackbar(ReplaceOwner)) diff --git a/src/routes/safe/components/Settings/ThresholdSettings/index.jsx b/src/routes/safe/components/Settings/ThresholdSettings/index.jsx index 701fa6c6..44ec5e56 100644 --- a/src/routes/safe/components/Settings/ThresholdSettings/index.jsx +++ b/src/routes/safe/components/Settings/ThresholdSettings/index.jsx @@ -2,7 +2,7 @@ import React, { useState } from 'react' import { withStyles } from '@material-ui/core/styles' import { List } from 'immutable' -import { SharedSnackbarConsumer } from '~/components/SharedSnackBar' +import { withSnackbar } from 'notistack' import Heading from '~/components/layout/Heading' import Button from '~/components/layout/Button' import Bold from '~/components/layout/Bold' @@ -22,10 +22,11 @@ type Props = { createTransaction: Function, safeAddress: string, granted: boolean, + enqueueSnackbar: Function, } const ThresholdSettings = ({ - owners, threshold, classes, createTransaction, safeAddress, granted, + owners, threshold, classes, createTransaction, safeAddress, granted, enqueueSnackbar, }: Props) => { const [isModalOpen, setModalOpen] = useState(false) @@ -33,66 +34,58 @@ const ThresholdSettings = ({ setModalOpen((prevOpen) => !prevOpen) } + const onChangeThreshold = async (newThreshold) => { + const safeInstance = await getGnosisSafeInstanceAt(safeAddress) + const txData = safeInstance.contract.methods.changeThreshold(newThreshold).encodeABI() + + createTransaction(safeAddress, safeAddress, 0, txData, enqueueSnackbar) + } + return ( <> - - {({ openSnackbar }) => { - const onChangeThreshold = async (newThreshold) => { - const safeInstance = await getGnosisSafeInstanceAt(safeAddress) - const txData = safeInstance.contract.methods.changeThreshold(newThreshold).encodeABI() - - createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar) - } - - return ( - <> - - Required confirmations - - Any transaction requires the confirmation of: - - - {threshold} - {' '} - out of - {' '} - {owners.size} - {' '} - owners - - {owners.size > 1 && granted && ( - - - - )} - - - - - - ) - }} - + + Required confirmations + + Any transaction requires the confirmation of: + + + {threshold} + {' '} + out of + {' '} + {owners.size} + {' '} + owners + + {owners.size > 1 && granted && ( + + + + )} + + + + ) } -export default withStyles(styles)(ThresholdSettings) +export default withStyles(styles)(withSnackbar(ThresholdSettings))