Implement generic settings notifications

This commit is contained in:
mmv 2019-11-12 16:55:56 +04:00
parent 5a86436c2f
commit 2b26e18147
10 changed files with 78 additions and 131 deletions

View File

@ -41,7 +41,7 @@ const notificationStyles = {
boxShadow: '0 0 10px 0 rgba(212, 212, 211, 0.59)',
},
info: {
background: '#e8673c',
background: '#ffffff',
fontFamily: 'Averta',
fontSize: '14px',
lineHeight: 1.43,

View File

@ -8,14 +8,14 @@ import closeSnackbarAction from '~/logic/notifications/store/actions/closeSnackb
import { type Notification, NOTIFICATIONS } from './notificationTypes'
export type NotificationsQueue = {
beforeExecution: Notification,
pendingExecution: Notification,
beforeExecution: Notification | null,
pendingExecution: Notification | null,
afterExecution: {
noMoreConfirmationsNeeded: Notification,
moreConfirmationsNeeded: Notification,
noMoreConfirmationsNeeded: Notification | null,
moreConfirmationsNeeded: Notification | null,
},
afterExecutionError: Notification,
afterRejection: Notification,
afterExecutionError: Notification | null,
afterRejection: Notification | null,
}
const standardTxNotificationsQueue: NotificationsQueue = {
@ -31,78 +31,67 @@ const standardTxNotificationsQueue: NotificationsQueue = {
const confirmationTxNotificationsQueue: NotificationsQueue = {
beforeExecution: NOTIFICATIONS.SIGN_TX_MSG,
pendingExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.TX_CONFIRMATION_PENDING_MSG,
pendingExecution: NOTIFICATIONS.TX_CONFIRMATION_PENDING_MSG,
afterRejection: NOTIFICATIONS.TX_REJECTED_MSG,
afterExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.TX_CONFIRMATION_EXECUTED_MSG,
moreConfirmationsNeeded: null,
},
afterRejection: NOTIFICATIONS.TX_REJECTED_MSG,
afterExecution: NOTIFICATIONS.TX_CONFIRMATION_EXECUTED_MSG,
afterExecutionError: NOTIFICATIONS.TX_CONFIRMATION_FAILED_MSG,
}
const cancellationTxNotificationsQueue: NotificationsQueue = {
beforeExecution: NOTIFICATIONS.SIGN_TX_MSG,
pendingExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.TX_PENDING_MSG,
moreConfirmationsNeeded: NOTIFICATIONS.TX_PENDING_MORE_CONFIRMATIONS_MSG,
},
pendingExecution: NOTIFICATIONS.TX_PENDING_MSG,
afterRejection: NOTIFICATIONS.TX_REJECTED_MSG,
afterExecution: NOTIFICATIONS.TX_EXECUTED_MSG,
afterExecutionError: NOTIFICATIONS.TX_FAILED_MSG,
}
const ownerChangeTxNotificationsQueue: NotificationsQueue = {
beforeExecution: NOTIFICATIONS.SIGN_OWNER_CHANGE_MSG,
pendingExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.OWNER_CHANGE_PENDING_MSG,
moreConfirmationsNeeded: NOTIFICATIONS.OWNER_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG,
afterExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.TX_EXECUTED_MSG,
moreConfirmationsNeeded: NOTIFICATIONS.TX_EXECUTED_MORE_CONFIRMATIONS_MSG,
},
afterRejection: NOTIFICATIONS.OWNER_CHANGE_REJECTED_MSG,
afterExecution: NOTIFICATIONS.OWNER_CHANGE_EXECUTED_MSG,
afterExecutionError: NOTIFICATIONS.OWNER_CHANGE_FAILED_MSG,
afterExecutionError: NOTIFICATIONS.TX_FAILED_MSG,
}
const safeNameChangeNotificationsQueue: NotificationsQueue = {
beforeExecution: null,
pendingExecution: {
noMoreConfirmationsNeeded: null,
pendingExecution: null,
afterRejection: null,
afterExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.SAFE_NAME_CHANGED_MSG,
moreConfirmationsNeeded: null,
},
afterRejection: null,
afterExecution: NOTIFICATIONS.SAFE_NAME_CHANGED_MSG,
afterExecutionError: null,
}
const ownerNameChangeNotificationsQueue: NotificationsQueue = {
beforeExecution: null,
pendingExecution: {
noMoreConfirmationsNeeded: null,
pendingExecution: null,
afterRejection: null,
afterExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.OWNER_NAME_CHANGE_EXECUTED_MSG,
moreConfirmationsNeeded: null,
},
afterRejection: null,
afterExecution: NOTIFICATIONS.OWNER_NAME_CHANGE_EXECUTED_MSG,
afterExecutionError: null,
}
const thresholdChangeTxNotificationsQueue: NotificationsQueue = {
beforeExecution: NOTIFICATIONS.SIGN_THRESHOLD_CHANGE_MSG,
pendingExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.THRESHOLD_CHANGE_PENDING_MSG,
moreConfirmationsNeeded: NOTIFICATIONS.THRESHOLD_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG,
const settingsChangeTxNotificationsQueue: NotificationsQueue = {
beforeExecution: NOTIFICATIONS.SIGN_SETTINGS_CHANGE_MSG,
pendingExecution: NOTIFICATIONS.SETTINGS_CHANGE_PENDING_MSG,
afterRejection: NOTIFICATIONS.SETTINGS_CHANGE_REJECTED_MSG,
afterExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.SETTINGS_CHANGE_EXECUTED_MSG,
moreConfirmationsNeeded: NOTIFICATIONS.SETTINGS_CHANGE_EXECUTED_MORE_CONFIRMATIONS_MSG,
},
afterRejection: NOTIFICATIONS.THRESHOLD_CHANGE_REJECTED_MSG,
afterExecution: NOTIFICATIONS.THRESHOLD_CHANGE_EXECUTED_MSG,
afterExecutionError: NOTIFICATIONS.THRESHOLD_CHANGE_FAILED_MSG,
afterExecutionError: NOTIFICATIONS.SETTINGS_CHANGE_FAILED_MSG,
}
const defaultNotificationsQueue: NotificationsQueue = {
beforeExecution: NOTIFICATIONS.SIGN_TX_MSG,
pendingExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.TX_PENDING_MSG,
moreConfirmationsNeeded: NOTIFICATIONS.TX_PENDING_MORE_CONFIRMATIONS_MSG,
},
pendingExecution: NOTIFICATIONS.TX_PENDING_MSG,
afterRejection: NOTIFICATIONS.TX_REJECTED_MSG,
afterExecution: NOTIFICATIONS.TX_EXECUTED_MSG,
afterExecution: {
noMoreConfirmationsNeeded: NOTIFICATIONS.TX_EXECUTED_MSG,
moreConfirmationsNeeded: NOTIFICATIONS.TX_EXECUTED_MORE_CONFIRMATIONS_MSG,
},
afterExecutionError: NOTIFICATIONS.TX_FAILED_MSG,
}
@ -122,8 +111,8 @@ export const getNotificationsFromTxType = (txType: string) => {
notificationsQueue = cancellationTxNotificationsQueue
break
}
case TX_NOTIFICATION_TYPES.OWNER_CHANGE_TX: {
notificationsQueue = ownerChangeTxNotificationsQueue
case TX_NOTIFICATION_TYPES.SETTINGS_CHANGE_TX: {
notificationsQueue = settingsChangeTxNotificationsQueue
break
}
case TX_NOTIFICATION_TYPES.SAFE_NAME_CHANGE_TX: {
@ -134,10 +123,6 @@ export const getNotificationsFromTxType = (txType: string) => {
notificationsQueue = ownerNameChangeNotificationsQueue
break
}
case TX_NOTIFICATION_TYPES.THRESHOLD_CHANGE_TX: {
notificationsQueue = thresholdChangeTxNotificationsQueue
break
}
default: {
notificationsQueue = defaultNotificationsQueue
break
@ -151,7 +136,7 @@ export const enhanceSnackbarForAction = (notification: Notification) => ({
...notification,
options: {
...notification.options,
action: (key) => (
action: (key: number) => (
<IconButton onClick={() => store.dispatch(closeSnackbarAction({ key }))}>
<IconClose />
</IconButton>

View File

@ -51,20 +51,11 @@ export type Notifications = {
OWNER_NAME_CHANGE_EXECUTED_MSG: Notification,
// Owners
SIGN_OWNER_CHANGE_MSG: Notification,
OWNER_CHANGE_PENDING_MSG: Notification,
OWNER_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: Notification,
OWNER_CHANGE_REJECTED_MSG: Notification,
OWNER_CHANGE_EXECUTED_MSG: Notification,
OWNER_CHANGE_FAILED_MSG: Notification,
// Threshold
SIGN_THRESHOLD_CHANGE_MSG: Notification,
THRESHOLD_CHANGE_PENDING_MSG: Notification,
THRESHOLD_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: Notification,
THRESHOLD_CHANGE_REJECTED_MSG: Notification,
THRESHOLD_CHANGE_EXECUTED_MSG: Notification,
THRESHOLD_CHANGE_FAILED_MSG: Notification,
SIGN_SETTINGS_CHANGE_MSG: Notification,
SETTINGS_CHANGE_PENDING_MSG: Notification,
SETTINGS_CHANGE_REJECTED_MSG: Notification,
SETTINGS_CHANGE_EXECUTED_MORE_CONFIRMATIONS_MSG: Notification,
SETTINGS_CHANGE_FAILED_MSG: Notification,
// Rinkeby version
RINKEBY_VERSION_MSG: Notification,
@ -159,7 +150,7 @@ export const NOTIFICATIONS: Notifications = {
},
// Settings
SETTINGS_CHANGE_MSG: {
SIGN_SETTINGS_CHANGE_MSG: {
message: 'Please sign settings change',
options: { variant: SUCCESS, persist: true },
},
@ -167,53 +158,27 @@ export const NOTIFICATIONS: Notifications = {
message: 'Settings change pending',
options: { variant: INFO, persist: true },
},
SETTINGS_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: {
message: 'Owner change pending: More confirmations required to execute',
options: { variant: INFO, persist: true },
},
SETTINGS_CHANGE_REJECTED_MSG: {
message: 'Owner change rejected',
message: 'Settings change rejected',
options: { variant: ERROR, persist: false, autoHideDuration: longDuration },
},
SETTINGS_CHANGE_EXECUTED_MSG: {
message: 'Owner change successfully executed',
message: 'Settings change successfully executed',
options: { variant: SUCCESS, persist: false, autoHideDuration: longDuration },
},
SETTINGS_CHANGE_EXECUTED_MORE_CONFIRMATIONS_MSG: {
message: 'Settings change successfully created. More confirmations needed to execute',
options: { variant: SUCCESS, persist: false, autoHideDuration: longDuration },
},
SETTINGS_CHANGE_FAILED_MSG: {
message: 'Owner change failed',
options: { variant: ERROR, persist: false, autoHideDuration: longDuration },
},
// Threshold
SIGN_THRESHOLD_CHANGE_MSG: {
message: 'Please sign the required confirmations change',
options: { variant: SUCCESS, persist: true },
},
THRESHOLD_CHANGE_PENDING_MSG: {
message: 'Required confirmations change pending',
options: { variant: INFO, persist: true },
},
THRESHOLD_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: {
message: 'Required confirmations change pending: More confirmations required to execute',
options: { variant: INFO, persist: true },
},
THRESHOLD_CHANGE_REJECTED_MSG: {
message: 'Required confirmations change rejected',
options: { variant: ERROR, persist: false, autoHideDuration: longDuration },
},
THRESHOLD_CHANGE_EXECUTED_MSG: {
message: 'Required confirmations change successfully executed',
options: { variant: SUCCESS, persist: false, autoHideDuration: longDuration },
},
THRESHOLD_CHANGE_FAILED_MSG: {
message: 'Required confirmations change failed',
message: 'Settings change failed',
options: { variant: ERROR, persist: false, autoHideDuration: longDuration },
},
// Network
RINKEBY_VERSION_MSG: {
message: "Rinkeby Version: Don't send Mainnet assets to this Safe",
options: { variant: INFO, persist: true, preventDuplicate: true },
options: { variant: WARNING, persist: true, preventDuplicate: true },
},
WRONG_NETWORK_MSG: {
message: `Wrong network: Please use ${capitalize(getNetwork())}`,

View File

@ -4,18 +4,16 @@ export type NotifiedTransaction = {
STANDARD_TX: string,
CONFIRMATION_TX: string,
CANCELLATION_TX: string,
OWNER_CHANGE_TX: string,
SETTINGS_CHANGE_TX: string,
SAFE_NAME_CHANGE_TX: string,
OWNER_NAME_CHANGE_TX: string,
THRESHOLD_CHANGE_TX: string,
}
export const TX_NOTIFICATION_TYPES: NotifiedTransaction = {
STANDARD_TX: 'STANDARD_TX',
CONFIRMATION_TX: 'CONFIRMATION_TX',
CANCELLATION_TX: 'CANCELLATION_TX',
OWNER_CHANGE_TX: 'OWNER_CHANGE_TX',
SETTINGS_CHANGE_TX: 'SETTINGS_CHANGE_TX',
SAFE_NAME_CHANGE_TX: 'SAFE_NAME_CHANGE_TX',
OWNER_NAME_CHANGE_TX: 'OWNER_NAME_CHANGE_TX',
THRESHOLD_CHANGE_TX: 'THRESHOLD_CHANGE_TX',
}

View File

@ -52,7 +52,7 @@ export const sendAddOwner = async (
safeAddress,
0,
txData,
TX_NOTIFICATION_TYPES.OWNER_CHANGE_TX,
TX_NOTIFICATION_TYPES.SETTINGS_CHANGE_TX,
enqueueSnackbar,
closeSnackbar,
)

View File

@ -64,7 +64,7 @@ export const sendRemoveOwner = async (
safeAddress,
0,
txData,
TX_NOTIFICATION_TYPES.OWNER_CHANGE_TX,
TX_NOTIFICATION_TYPES.SETTINGS_CHANGE_TX,
enqueueSnackbar,
closeSnackbar,
)

View File

@ -60,7 +60,7 @@ export const sendReplaceOwner = async (
safeAddress,
0,
txData,
TX_NOTIFICATION_TYPES.OWNER_CHANGE_TX,
TX_NOTIFICATION_TYPES.SETTINGS_CHANGE_TX,
enqueueSnackbar,
closeSnackbar,
)

View File

@ -52,7 +52,7 @@ const ThresholdSettings = ({
safeAddress,
0,
txData,
TX_NOTIFICATION_TYPES.THRESHOLD_CHANGE_TX,
TX_NOTIFICATION_TYPES.SETTINGS_CHANGE_TX,
enqueueSnackbar,
closeSnackbar,
)

View File

@ -16,7 +16,6 @@ import {
saveTxToHistory,
} from '~/logic/safe/transactions'
import {
type Notification,
type NotificationsQueue,
getNotificationsFromTxType,
showSnackbar,
@ -75,16 +74,8 @@ const createTransaction = (
.once('transactionHash', async (hash) => {
txHash = hash
closeSnackbar(beforeExecutionKey)
const pendingExecutionNotification: Notification = isExecution
? {
message: notificationsQueue.pendingExecution.noMoreConfirmationsNeeded.message,
options: notificationsQueue.pendingExecution.noMoreConfirmationsNeeded.options,
}
: {
message: notificationsQueue.pendingExecution.moreConfirmationsNeeded.message,
options: notificationsQueue.pendingExecution.moreConfirmationsNeeded.options,
}
pendingExecutionKey = showSnackbar(pendingExecutionNotification, enqueueSnackbar, closeSnackbar)
pendingExecutionKey = showSnackbar(notificationsQueue.pendingExecution, enqueueSnackbar, closeSnackbar)
try {
await saveTxToHistory(
@ -109,7 +100,13 @@ const createTransaction = (
closeSnackbar(pendingExecutionKey)
if (isExecution) {
showSnackbar(notificationsQueue.afterExecution, enqueueSnackbar, closeSnackbar)
showSnackbar(
isExecution
? notificationsQueue.afterExecution.noMoreConfirmationsNeeded
: notificationsQueue.afterExecution.moreConfirmationsNeeded,
enqueueSnackbar,
closeSnackbar,
)
}
dispatch(fetchTransactions(safeAddress))

View File

@ -17,7 +17,6 @@ import {
TX_TYPE_CONFIRMATION,
} from '~/logic/safe/transactions'
import {
type Notification,
type NotificationsQueue,
getNotificationsFromTxType,
showSnackbar,
@ -107,11 +106,8 @@ const processTransaction = (
.once('transactionHash', async (hash) => {
txHash = hash
closeSnackbar(beforeExecutionKey)
const notification: Notification = {
message: notificationsQueue.pendingExecution.noMoreConfirmationsNeeded.message,
options: notificationsQueue.pendingExecution.noMoreConfirmationsNeeded.options,
}
pendingExecutionKey = showSnackbar(notification, enqueueSnackbar, closeSnackbar)
pendingExecutionKey = showSnackbar(notificationsQueue.pendingExecution, enqueueSnackbar, closeSnackbar)
try {
await saveTxToHistory(
@ -135,7 +131,13 @@ const processTransaction = (
.then((receipt) => {
closeSnackbar(pendingExecutionKey)
showSnackbar(notificationsQueue.afterExecution, enqueueSnackbar, closeSnackbar)
showSnackbar(
shouldExecute
? notificationsQueue.afterExecution.noMoreConfirmationsNeeded
: notificationsQueue.afterExecution.moreConfirmationsNeeded,
enqueueSnackbar,
closeSnackbar,
)
dispatch(fetchTransactions(safeAddress))
return receipt.transactionHash