Add owner management notifications

This commit is contained in:
Germán Martínez 2019-09-20 12:40:29 +02:00
parent 0e58604395
commit 858f7ca038
6 changed files with 62 additions and 120 deletions

View File

@ -1,105 +1,3 @@
// @flow // @flow
export * from './notificationTypes'
export type Notifications = { export * from './notificationBuilder'
// Default
BEFORE_EXECUTION_OR_CREATION: string,
AFTER_EXECUTION: string,
CREATED_MORE_CONFIRMATIONS_NEEDED: string,
ERROR: string,
// Wallet Connection
CONNECT_WALLET_MSG: string,
CONNECT_WALLET_READ_MODE_MSG: string,
WALLET_CONNECTED_MSG: string,
UNLOCK_WALLET_MSG: string,
CONNECT_WALLET_ERROR_MSG: string,
// Regular/Custom Transactions
SIGN_TX_MSG: string,
TX_PENDING_MSG: string,
TX_PENDING_MORE_CONFIRMATIONS_MSG: string,
TX_REJECTED_MSG: string,
TX_EXECUTED_MSG: string,
TX_FAILED_MSG: string,
// Approval Transactions
TX_CONFIRMATION_PENDING_MSG: string,
TX_CONFIRMATION_EXECUTED_MSG: string,
TX_CONFIRMATION_FAILED_MSG: string,
// Safe Name
SAFE_NAME_CHANGED_MSG: string,
// Owners
SIGN_OWNER_CHANGE_MSG: string,
ONWER_CHANGE_PENDING_MSG: string,
ONWER_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: string,
ONWER_CHANGE_REJECTED_MSG: string,
ONWER_CHANGE_EXECUTED_MSG: string,
ONWER_CHANGE_FAILED_MSG: string,
// Threshold
SIGN_THRESHOLD_CHANGE_MSG: string,
THRESHOLD_CHANGE_PENDING_MSG: string,
THRESHOLD_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: string,
THRESHOLD_CHANGE_REJECTED_MSG: string,
THRESHOLD_CHANGE_EXECUTED_MSG: string,
THRESHOLD_CHANGE_FAILED_MSG: string,
// Rinkeby version
RINKEBY_VERSION_MSG: string,
WRONG_NETWORK_RINKEBY_MSG: string,
WRONG_NETWOEK_MAINNET_MSG: string,
}
export const NOTIFICATIONS: Notifications = {
// Default
BEFORE_EXECUTION_OR_CREATION: 'Transaction in progress',
AFTER_EXECUTION: 'Transaction successfully executed',
CREATED_MORE_CONFIRMATIONS_NEEDED: 'Transaction in progress: More confirmations required to execute',
ERROR: 'Transaction failed',
// Wallet Connection
CONNECT_WALLET_MSG: 'Please connect wallet to continue',
CONNECT_WALLET_READ_MODE_MSG: 'You are in read-only mode: Please connect wallet',
WALLET_CONNECTED_MSG: 'Wallet connected',
UNLOCK_WALLET_MSG: 'Unlock your wallet to connect',
CONNECT_WALLET_ERROR_MSG: 'Error connecting to your wallet',
// Regular/Custom Transactions
SIGN_TX_MSG: 'Please sign the transaction',
TX_PENDING_MSG: 'Transaction pending',
TX_PENDING_MORE_CONFIRMATIONS_MSG: 'Transaction pending: More confirmations required to execute',
TX_REJECTED_MSG: 'Transaction rejected',
TX_EXECUTED_MSG: 'Transaction successfully executed',
TX_FAILED_MSG: 'Transaction failed',
// Approval Transactions
TX_CONFIRMATION_PENDING_MSG: 'Confirmation transaction pending',
TX_CONFIRMATION_EXECUTED_MSG: 'Confirmation transaction succesful',
TX_CONFIRMATION_FAILED_MSG: 'Confirmation transaction failed',
// Safe Name
SAFE_NAME_CHANGED_MSG: 'Safe name changed',
// Owners
SIGN_OWNER_CHANGE_MSG: 'Please sign the owner change',
ONWER_CHANGE_PENDING_MSG: 'Owner change pending',
ONWER_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: 'Owner change pending: More confirmations required to execute',
ONWER_CHANGE_REJECTED_MSG: 'Owner change rejected',
ONWER_CHANGE_EXECUTED_MSG: 'Owner change successfully executed',
ONWER_CHANGE_FAILED_MSG: 'Owner change failed',
// Threshold
SIGN_THRESHOLD_CHANGE_MSG: 'Please sign the required confirmations change',
THRESHOLD_CHANGE_PENDING_MSG: 'Required confirmations change pending',
THRESHOLD_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: 'Required confirmations change pending: More confirmations required to execute',
THRESHOLD_CHANGE_REJECTED_MSG: 'Required confirmations change rejected',
THRESHOLD_CHANGE_EXECUTED_MSG: 'Required confirmations change successfully executed',
THRESHOLD_CHANGE_FAILED_MSG: 'Required confirmations change failed',
// Network
RINKEBY_VERSION_MSG: 'Rinkeby Version: Don\'t send mainnet assets to this Safe',
WRONG_NETWORK_RINKEBY_MSG: 'Wrong network: Please use Rinkeby',
WRONG_NETWOEK_MAINNET_MSG: 'Wrong network: Please use Mainnet',
}

View File

@ -1,6 +1,6 @@
// @flow // @flow
export * from './gas' export * from './gas'
export * from './send' export * from './send'
export * from './safeBlockchainOperations'
export * from './safeTxSignerEIP712' export * from './safeTxSignerEIP712'
export * from './txHistory' export * from './txHistory'
export * from './notifiedTransactions'

View File

@ -4,9 +4,9 @@ import { List } from 'immutable'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import { withSnackbar } from 'notistack' import { withSnackbar } from 'notistack'
import Modal from '~/components/Modal' import Modal from '~/components/Modal'
import { type Variant } from '~/components/Header'
import { type Owner } from '~/routes/safe/store/models/owner' import { type Owner } from '~/routes/safe/store/models/owner'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { NOTIFIED_TRANSACTIONS } from '~/logic/safe/transactions'
import OwnerForm from './screens/OwnerForm' import OwnerForm from './screens/OwnerForm'
import ThresholdForm from './screens/ThresholdForm' import ThresholdForm from './screens/ThresholdForm'
import ReviewAddOwner from './screens/Review' import ReviewAddOwner from './screens/Review'
@ -30,7 +30,8 @@ type Props = {
network: string, network: string,
addSafeOwner: Function, addSafeOwner: Function,
createTransaction: Function, createTransaction: Function,
enqueueSnackbar: (message: string, variant: Variant) => void, enqueueSnackbar: Function,
closeSnackbar: Function,
} }
type ActiveScreen = 'selectOwner' | 'selectThreshold' | 'reviewAddOwner' type ActiveScreen = 'selectOwner' | 'selectThreshold' | 'reviewAddOwner'
@ -38,14 +39,23 @@ export const sendAddOwner = async (
values: Object, values: Object,
safeAddress: string, safeAddress: string,
ownersOld: List<Owner>, ownersOld: List<Owner>,
enqueueSnackbar: (message: string, variant: Variant) => void, enqueueSnackbar: Function,
closeSnackbar: Function,
createTransaction: Function, createTransaction: Function,
addSafeOwner: Function, addSafeOwner: Function,
) => { ) => {
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const txData = gnosisSafe.contract.methods.addOwnerWithThreshold(values.ownerAddress, values.threshold).encodeABI() const txData = gnosisSafe.contract.methods.addOwnerWithThreshold(values.ownerAddress, values.threshold).encodeABI()
const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, enqueueSnackbar) const txHash = await createTransaction(
safeAddress,
safeAddress,
0,
txData,
NOTIFIED_TRANSACTIONS.OWNER_CHANGE_TX,
enqueueSnackbar,
closeSnackbar,
)
if (txHash) { if (txHash) {
addSafeOwner({ safeAddress, ownerName: values.ownerName, ownerAddress: values.ownerAddress }) addSafeOwner({ safeAddress, ownerName: values.ownerName, ownerAddress: values.ownerAddress })
@ -64,6 +74,7 @@ const AddOwner = ({
createTransaction, createTransaction,
addSafeOwner, addSafeOwner,
enqueueSnackbar, enqueueSnackbar,
closeSnackbar,
}: Props) => { }: Props) => {
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('selectOwner') const [activeScreen, setActiveScreen] = useState<ActiveScreen>('selectOwner')
const [values, setValues] = useState<Object>({}) const [values, setValues] = useState<Object>({})
@ -104,7 +115,7 @@ const AddOwner = ({
const onAddOwner = async () => { const onAddOwner = async () => {
onClose() onClose()
try { try {
sendAddOwner(values, safeAddress, owners, enqueueSnackbar, createTransaction, addSafeOwner) sendAddOwner(values, safeAddress, owners, enqueueSnackbar, closeSnackbar, createTransaction, addSafeOwner)
} catch (error) { } catch (error) {
// eslint-disable-next-line // eslint-disable-next-line
console.log('Error while removing an owner ' + error) console.log('Error while removing an owner ' + error)

View File

@ -1,5 +1,6 @@
// @flow // @flow
import React from 'react' import React from 'react'
import { withSnackbar } from 'notistack'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import Close from '@material-ui/icons/Close' import Close from '@material-ui/icons/Close'
import OpenInNew from '@material-ui/icons/OpenInNew' import OpenInNew from '@material-ui/icons/OpenInNew'
@ -14,8 +15,10 @@ import Field from '~/components/forms/Field'
import TextField from '~/components/forms/TextField' import TextField from '~/components/forms/TextField'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Identicon from '~/components/Identicon' import Identicon from '~/components/Identicon'
import { getEtherScanLink } from '~/logic/wallets/getWeb3'
import { composeValidators, required, minMaxLength } from '~/components/forms/validator' import { composeValidators, required, minMaxLength } from '~/components/forms/validator'
import { getNofiticationsFromTxType } from '~/logic/notifications'
import { NOTIFIED_TRANSACTIONS } from '~/logic/safe/transactions'
import { getEtherScanLink } from '~/logic/wallets/getWeb3'
import Modal from '~/components/Modal' import Modal from '~/components/Modal'
import { styles } from './style' import { styles } from './style'
import { secondary } from '~/theme/variables' import { secondary } from '~/theme/variables'
@ -37,6 +40,7 @@ type Props = {
network: string, network: string,
selectedOwnerName: string, selectedOwnerName: string,
editSafeOwner: Function, editSafeOwner: Function,
enqueueSnackbar: Function,
} }
const EditOwnerComponent = ({ const EditOwnerComponent = ({
@ -48,9 +52,14 @@ const EditOwnerComponent = ({
selectedOwnerName, selectedOwnerName,
editSafeOwner, editSafeOwner,
network, network,
enqueueSnackbar,
}: Props) => { }: Props) => {
const handleSubmit = (values) => { const handleSubmit = (values) => {
editSafeOwner({ safeAddress, ownerAddress, ownerName: values.ownerName }) editSafeOwner({ safeAddress, ownerAddress, ownerName: values.ownerName })
const notification = getNofiticationsFromTxType(NOTIFIED_TRANSACTIONS.OWNER_NAME_CHANGE_TX)
enqueueSnackbar(notification.afterExecution.description, notification.afterExecution.options)
onClose() onClose()
} }
@ -116,6 +125,6 @@ const EditOwnerComponent = ({
) )
} }
const EditOwnerModal = withStyles(styles)(EditOwnerComponent) const EditOwnerModal = withStyles(styles)(withSnackbar(EditOwnerComponent))
export default EditOwnerModal export default EditOwnerModal

View File

@ -4,9 +4,9 @@ import { List } from 'immutable'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import { withSnackbar } from 'notistack' import { withSnackbar } from 'notistack'
import Modal from '~/components/Modal' import Modal from '~/components/Modal'
import { type Variant } from '~/components/Header'
import { type Owner } from '~/routes/safe/store/models/owner' import { type Owner } from '~/routes/safe/store/models/owner'
import { getGnosisSafeInstanceAt, SENTINEL_ADDRESS } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt, SENTINEL_ADDRESS } from '~/logic/contracts/safeContracts'
import { NOTIFIED_TRANSACTIONS } from '~/logic/safe/transactions'
import CheckOwner from './screens/CheckOwner' import CheckOwner from './screens/CheckOwner'
import ThresholdForm from './screens/ThresholdForm' import ThresholdForm from './screens/ThresholdForm'
import ReviewRemoveOwner from './screens/Review' import ReviewRemoveOwner from './screens/Review'
@ -32,7 +32,8 @@ type Props = {
network: string, network: string,
createTransaction: Function, createTransaction: Function,
removeSafeOwner: Function, removeSafeOwner: Function,
enqueueSnackbar: (message: string, variant: Variant) => void, enqueueSnackbar: Function,
closeSnackbar: Function,
} }
type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner' type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner'
@ -43,7 +44,8 @@ export const sendRemoveOwner = async (
ownerAddressToRemove: string, ownerAddressToRemove: string,
ownerNameToRemove: string, ownerNameToRemove: string,
ownersOld: List<Owner>, ownersOld: List<Owner>,
enqueueSnackbar: (message: string, variant: Variant) => void, enqueueSnackbar: Function,
closeSnackbar: Function,
createTransaction: Function, createTransaction: Function,
removeSafeOwner: Function, removeSafeOwner: Function,
) => { ) => {
@ -57,7 +59,15 @@ export const sendRemoveOwner = async (
.removeOwner(prevAddress, ownerAddressToRemove, values.threshold) .removeOwner(prevAddress, ownerAddressToRemove, values.threshold)
.encodeABI() .encodeABI()
const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, enqueueSnackbar) const txHash = await createTransaction(
safeAddress,
safeAddress,
0,
txData,
NOTIFIED_TRANSACTIONS.OWNER_CHANGE_TX,
enqueueSnackbar,
closeSnackbar,
)
if (txHash) { if (txHash) {
removeSafeOwner({ safeAddress, ownerAddress: ownerAddressToRemove }) removeSafeOwner({ safeAddress, ownerAddress: ownerAddressToRemove })
@ -78,6 +88,7 @@ const RemoveOwner = ({
createTransaction, createTransaction,
removeSafeOwner, removeSafeOwner,
enqueueSnackbar, enqueueSnackbar,
closeSnackbar,
}: Props) => { }: Props) => {
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner') const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner')
const [values, setValues] = useState<Object>({}) const [values, setValues] = useState<Object>({})
@ -117,6 +128,7 @@ const RemoveOwner = ({
ownerName, ownerName,
owners, owners,
enqueueSnackbar, enqueueSnackbar,
closeSnackbar,
createTransaction, createTransaction,
removeSafeOwner, removeSafeOwner,
) )

View File

@ -4,7 +4,7 @@ import { List } from 'immutable'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import { withSnackbar } from 'notistack' import { withSnackbar } from 'notistack'
import Modal from '~/components/Modal' import Modal from '~/components/Modal'
import { type Variant } from '~/components/Header' import { NOTIFIED_TRANSACTIONS } from '~/logic/safe/transactions'
import { getGnosisSafeInstanceAt, SENTINEL_ADDRESS } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt, SENTINEL_ADDRESS } from '~/logic/contracts/safeContracts'
import OwnerForm from './screens/OwnerForm' import OwnerForm from './screens/OwnerForm'
import ReviewReplaceOwner from './screens/Review' import ReviewReplaceOwner from './screens/Review'
@ -30,7 +30,8 @@ type Props = {
threshold: string, threshold: string,
createTransaction: Function, createTransaction: Function,
replaceSafeOwner: Function, replaceSafeOwner: Function,
enqueueSnackbar: (message: string, variant: Variant) => void, enqueueSnackbar: Function,
closeSnackbar: Function,
} }
type ActiveScreen = 'checkOwner' | 'reviewReplaceOwner' type ActiveScreen = 'checkOwner' | 'reviewReplaceOwner'
@ -38,7 +39,8 @@ export const sendReplaceOwner = async (
values: Object, values: Object,
safeAddress: string, safeAddress: string,
ownerAddressToRemove: string, ownerAddressToRemove: string,
enqueueSnackbar: (message: string, variant: Variant) => void, enqueueSnackbar: Function,
closeSnackbar: Function,
createTransaction: Function, createTransaction: Function,
replaceSafeOwner: Function, replaceSafeOwner: Function,
) => { ) => {
@ -52,7 +54,15 @@ export const sendReplaceOwner = async (
.swapOwner(prevAddress, ownerAddressToRemove, values.ownerAddress) .swapOwner(prevAddress, ownerAddressToRemove, values.ownerAddress)
.encodeABI() .encodeABI()
const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, enqueueSnackbar) const txHash = await createTransaction(
safeAddress,
safeAddress,
0,
txData,
NOTIFIED_TRANSACTIONS.OWNER_CHANGE_TX,
enqueueSnackbar,
closeSnackbar,
)
if (txHash) { if (txHash) {
replaceSafeOwner({ replaceSafeOwner({
@ -78,6 +88,7 @@ const ReplaceOwner = ({
createTransaction, createTransaction,
replaceSafeOwner, replaceSafeOwner,
enqueueSnackbar, enqueueSnackbar,
closeSnackbar,
}: Props) => { }: Props) => {
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner') const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner')
const [values, setValues] = useState<Object>({}) const [values, setValues] = useState<Object>({})
@ -107,6 +118,7 @@ const ReplaceOwner = ({
safeAddress, safeAddress,
ownerAddress, ownerAddress,
enqueueSnackbar, enqueueSnackbar,
closeSnackbar,
createTransaction, createTransaction,
replaceSafeOwner, replaceSafeOwner,
) )