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
export type Notifications = {
// 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',
}
export * from './notificationTypes'
export * from './notificationBuilder'

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import { List } from 'immutable'
import { withStyles } from '@material-ui/core/styles'
import { withSnackbar } from 'notistack'
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 OwnerForm from './screens/OwnerForm'
import ReviewReplaceOwner from './screens/Review'
@ -30,7 +30,8 @@ type Props = {
threshold: string,
createTransaction: Function,
replaceSafeOwner: Function,
enqueueSnackbar: (message: string, variant: Variant) => void,
enqueueSnackbar: Function,
closeSnackbar: Function,
}
type ActiveScreen = 'checkOwner' | 'reviewReplaceOwner'
@ -38,7 +39,8 @@ export const sendReplaceOwner = async (
values: Object,
safeAddress: string,
ownerAddressToRemove: string,
enqueueSnackbar: (message: string, variant: Variant) => void,
enqueueSnackbar: Function,
closeSnackbar: Function,
createTransaction: Function,
replaceSafeOwner: Function,
) => {
@ -52,7 +54,15 @@ export const sendReplaceOwner = async (
.swapOwner(prevAddress, ownerAddressToRemove, values.ownerAddress)
.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) {
replaceSafeOwner({
@ -78,6 +88,7 @@ const ReplaceOwner = ({
createTransaction,
replaceSafeOwner,
enqueueSnackbar,
closeSnackbar,
}: Props) => {
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner')
const [values, setValues] = useState<Object>({})
@ -107,6 +118,7 @@ const ReplaceOwner = ({
safeAddress,
ownerAddress,
enqueueSnackbar,
closeSnackbar,
createTransaction,
replaceSafeOwner,
)