Merge pull request #257 from gnosis/158-notifications-improvements
Feature #158: Notifications improvements
This commit is contained in:
commit
c93529b21c
|
@ -1,6 +1,5 @@
|
|||
// @flow
|
||||
import React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import Web3Connect from 'web3connect'
|
||||
import Torus from '@toruslabs/torus-embed'
|
||||
import WalletConnectProvider from '@walletconnect/web3-provider'
|
||||
|
@ -54,15 +53,11 @@ web3Connect.on('connect', (provider: any) => {
|
|||
})
|
||||
|
||||
type Props = {
|
||||
registerProvider: Function,
|
||||
enqueueSnackbar: Function,
|
||||
closeSnackbar: Function,
|
||||
}
|
||||
|
||||
const ConnectButton = ({
|
||||
registerProvider, ...props
|
||||
}: Props) => (
|
||||
|
||||
const ConnectButton = (props: Props) => (
|
||||
<Button
|
||||
color="primary"
|
||||
variant="contained"
|
||||
|
@ -76,7 +71,4 @@ const ConnectButton = ({
|
|||
</Button>
|
||||
)
|
||||
|
||||
export default connect(
|
||||
null,
|
||||
{ registerProvider: fetchProvider },
|
||||
)(ConnectButton)
|
||||
export default ConnectButton
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
|
||||
<g fill="none" fill-rule="evenodd">
|
||||
<rect width="2" height="8" x="9" y="8" fill="#B2B5B2" rx="1"/>
|
||||
<rect width="2" height="2" x="9" y="4" fill="#B2B5B2" stroke="#B2B5B2" stroke-width=".5" rx="1"/>
|
||||
<circle cx="10" cy="10" r="9" stroke="#B2B5B2" stroke-width="2"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 391 B |
|
@ -6,9 +6,10 @@ import SidebarProvider from '~/components/Sidebar'
|
|||
import Header from '~/components/Header'
|
||||
import Img from '~/components/layout/Img'
|
||||
import Notifier from '~/components/Notifier'
|
||||
import AlertLogo from './assets/alert.svg'
|
||||
import CheckLogo from './assets/check.svg'
|
||||
import ErrorLogo from './assets/error.svg'
|
||||
import AlertIcon from './assets/alert.svg'
|
||||
import CheckIcon from './assets/check.svg'
|
||||
import ErrorIcon from './assets/error.svg'
|
||||
import InfoIcon from './assets/info.svg'
|
||||
import styles from './index.scss'
|
||||
|
||||
const notificationStyles = {
|
||||
|
@ -40,11 +41,11 @@ 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,
|
||||
color: '#ffffff',
|
||||
color: '#001428',
|
||||
minHeight: '58px',
|
||||
boxShadow: '0 0 10px 0 rgba(212, 212, 211, 0.59)',
|
||||
},
|
||||
|
@ -67,10 +68,10 @@ const PageFrame = ({ children, classes }: Props) => (
|
|||
variantInfo: classes.info,
|
||||
}}
|
||||
iconVariant={{
|
||||
success: <Img src={CheckLogo} alt="Success" />,
|
||||
error: <Img src={ErrorLogo} alt="Error" />,
|
||||
warning: <Img src={AlertLogo} alt="Warning" />,
|
||||
info: '',
|
||||
success: <Img src={CheckIcon} alt="Success" />,
|
||||
error: <Img src={ErrorIcon} alt="Error" />,
|
||||
warning: <Img src={AlertIcon} alt="Warning" />,
|
||||
info: <Img src={InfoIcon} alt="Info" />,
|
||||
}}
|
||||
>
|
||||
<Notifier />
|
||||
|
|
|
@ -8,101 +8,90 @@ import closeSnackbarAction from '~/logic/notifications/store/actions/closeSnackb
|
|||
import { type Notification, NOTIFICATIONS } from './notificationTypes'
|
||||
|
||||
export type NotificationsQueue = {
|
||||
beforeExecution: Notification,
|
||||
pendingExecution: {
|
||||
noMoreConfirmationsNeeded: Notification,
|
||||
moreConfirmationsNeeded: Notification,
|
||||
beforeExecution: Notification | null,
|
||||
pendingExecution: Notification | null,
|
||||
afterExecution: {
|
||||
noMoreConfirmationsNeeded: Notification | null,
|
||||
moreConfirmationsNeeded: Notification | null,
|
||||
},
|
||||
afterExecution: Notification,
|
||||
afterExecutionError: Notification,
|
||||
afterRejection: Notification,
|
||||
afterExecutionError: Notification | null,
|
||||
afterRejection: Notification | null,
|
||||
}
|
||||
|
||||
const standardTxNotificationsQueue: 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,
|
||||
}
|
||||
|
||||
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,8 +136,8 @@ export const enhanceSnackbarForAction = (notification: Notification) => ({
|
|||
...notification,
|
||||
options: {
|
||||
...notification.options,
|
||||
action: (key) => (
|
||||
<IconButton onClick={() => store.dispatch(closeSnackbarAction(key))}>
|
||||
action: (key: number) => (
|
||||
<IconButton onClick={() => store.dispatch(closeSnackbarAction({ key }))}>
|
||||
<IconClose />
|
||||
</IconButton>
|
||||
),
|
||||
|
|
|
@ -34,9 +34,9 @@ export type Notifications = {
|
|||
// Regular/Custom Transactions
|
||||
SIGN_TX_MSG: Notification,
|
||||
TX_PENDING_MSG: Notification,
|
||||
TX_PENDING_MORE_CONFIRMATIONS_MSG: Notification,
|
||||
TX_REJECTED_MSG: Notification,
|
||||
TX_EXECUTED_MSG: Notification,
|
||||
TX_EXECUTED_MORE_CONFIRMATIONS_MSG: Notification,
|
||||
TX_FAILED_MSG: Notification,
|
||||
|
||||
// Approval Transactions
|
||||
|
@ -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,
|
||||
|
@ -109,15 +100,11 @@ export const NOTIFICATIONS: Notifications = {
|
|||
// Regular/Custom Transactions
|
||||
SIGN_TX_MSG: {
|
||||
message: 'Please sign the transaction',
|
||||
options: { variant: SUCCESS, persist: true },
|
||||
options: { variant: INFO, persist: true },
|
||||
},
|
||||
TX_PENDING_MSG: {
|
||||
message: 'Transaction pending',
|
||||
options: { variant: SUCCESS, persist: true },
|
||||
},
|
||||
TX_PENDING_MORE_CONFIRMATIONS_MSG: {
|
||||
message: 'Transaction pending: More confirmations required to execute',
|
||||
options: { variant: SUCCESS, persist: true },
|
||||
options: { variant: INFO, persist: true },
|
||||
},
|
||||
TX_REJECTED_MSG: {
|
||||
message: 'Transaction rejected',
|
||||
|
@ -127,6 +114,10 @@ export const NOTIFICATIONS: Notifications = {
|
|||
message: 'Transaction successfully executed',
|
||||
options: { variant: SUCCESS, persist: false, autoHideDuration: longDuration },
|
||||
},
|
||||
TX_EXECUTED_MORE_CONFIRMATIONS_MSG: {
|
||||
message: 'Transaction successfully created. More confirmations needed to execute',
|
||||
options: { variant: SUCCESS, persist: false, autoHideDuration: longDuration },
|
||||
},
|
||||
TX_FAILED_MSG: {
|
||||
message: 'Transaction failed',
|
||||
options: { variant: ERROR, persist: false, autoHideDuration: longDuration },
|
||||
|
@ -135,7 +126,7 @@ export const NOTIFICATIONS: Notifications = {
|
|||
// Approval Transactions
|
||||
TX_CONFIRMATION_PENDING_MSG: {
|
||||
message: 'Confirmation transaction pending',
|
||||
options: { variant: SUCCESS, persist: true },
|
||||
options: { variant: INFO, persist: true },
|
||||
},
|
||||
TX_CONFIRMATION_EXECUTED_MSG: {
|
||||
message: 'Confirmation transaction succesful',
|
||||
|
@ -158,62 +149,36 @@ export const NOTIFICATIONS: Notifications = {
|
|||
options: { variant: SUCCESS, persist: false, autoHideDuration: shortDuration },
|
||||
},
|
||||
|
||||
// Owners
|
||||
SIGN_OWNER_CHANGE_MSG: {
|
||||
message: 'Please sign the owner change',
|
||||
options: { variant: SUCCESS, persist: true },
|
||||
// Settings
|
||||
SIGN_SETTINGS_CHANGE_MSG: {
|
||||
message: 'Please sign the settings change',
|
||||
options: { variant: INFO, persist: true },
|
||||
},
|
||||
OWNER_CHANGE_PENDING_MSG: {
|
||||
message: 'Owner change pending',
|
||||
options: { variant: SUCCESS, persist: true },
|
||||
SETTINGS_CHANGE_PENDING_MSG: {
|
||||
message: 'Settings change pending',
|
||||
options: { variant: INFO, persist: true },
|
||||
},
|
||||
OWNER_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: {
|
||||
message: 'Owner change pending: More confirmations required to execute',
|
||||
options: { variant: SUCCESS, persist: true },
|
||||
},
|
||||
OWNER_CHANGE_REJECTED_MSG: {
|
||||
message: 'Owner change rejected',
|
||||
SETTINGS_CHANGE_REJECTED_MSG: {
|
||||
message: 'Settings change rejected',
|
||||
options: { variant: ERROR, persist: false, autoHideDuration: longDuration },
|
||||
},
|
||||
OWNER_CHANGE_EXECUTED_MSG: {
|
||||
message: 'Owner change successfully executed',
|
||||
SETTINGS_CHANGE_EXECUTED_MSG: {
|
||||
message: 'Settings change successfully executed',
|
||||
options: { variant: SUCCESS, persist: false, autoHideDuration: longDuration },
|
||||
},
|
||||
OWNER_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: SUCCESS, persist: true },
|
||||
},
|
||||
THRESHOLD_CHANGE_PENDING_MORE_CONFIRMATIONS_MSG: {
|
||||
message: 'Required confirmations change pending: More confirmations required to execute',
|
||||
options: { variant: SUCCESS, 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',
|
||||
SETTINGS_CHANGE_EXECUTED_MORE_CONFIRMATIONS_MSG: {
|
||||
message: 'Settings change successfully created. More confirmations needed to execute',
|
||||
options: { variant: SUCCESS, persist: false, autoHideDuration: longDuration },
|
||||
},
|
||||
THRESHOLD_CHANGE_FAILED_MSG: {
|
||||
message: 'Required confirmations change failed',
|
||||
SETTINGS_CHANGE_FAILED_MSG: {
|
||||
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())}`,
|
||||
|
|
|
@ -18,9 +18,20 @@ export default handleActions<NotificationReducerState, *>(
|
|||
return state.set(notification.key, makeNotification(notification))
|
||||
},
|
||||
[CLOSE_SNACKBAR]: (state: NotificationReducerState, action: ActionType<Function>): NotificationReducerState => {
|
||||
const key = action.payload
|
||||
const { key, dismissAll } = action.payload
|
||||
|
||||
return state.update(key, (prev) => prev.set('dismissed', true))
|
||||
if (key) {
|
||||
return state.update(key, (prev) => prev.set('dismissed', true))
|
||||
}
|
||||
if (dismissAll) {
|
||||
return state.withMutations((map) => {
|
||||
map.forEach((notification, notificationKey) => {
|
||||
map.set(notificationKey, notification.set('dismissed', true))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return state
|
||||
},
|
||||
[REMOVE_SNACKBAR]: (state: NotificationReducerState, action: ActionType<Function>): NotificationReducerState => {
|
||||
const key = action.payload
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
// @flow
|
||||
import { List } from 'immutable'
|
||||
import { type Transaction } from '~/routes/safe/store/models/transaction'
|
||||
import { executeTransaction, approveTransaction } from '~/logic/safe/transactions'
|
||||
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
|
||||
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
||||
import { type Safe } from '~/routes/safe/store/models/safe'
|
||||
import { storeSubject } from '~/utils/storage/transactions'
|
||||
|
||||
export const TX_NAME_PARAM = 'txName'
|
||||
export const TX_DESTINATION_PARAM = 'txDestination'
|
||||
export const TX_VALUE_PARAM = 'txValue'
|
||||
|
||||
export const EXECUTED_CONFIRMATION_HASH = 'EXECUTED'
|
||||
|
||||
const hasOneOwner = (safe: Safe) => {
|
||||
const owners = safe.get('owners')
|
||||
if (!owners) {
|
||||
throw new Error('Received a Safe without owners when creating a tx')
|
||||
}
|
||||
|
||||
return owners.count() === 1
|
||||
}
|
||||
|
||||
export const createTransaction = async (
|
||||
safe: Safe,
|
||||
name: string,
|
||||
to: string,
|
||||
value: string,
|
||||
nonce: number,
|
||||
sender: string,
|
||||
data: string = EMPTY_DATA,
|
||||
) => {
|
||||
const web3 = getWeb3()
|
||||
const safeAddress = safe.get('address')
|
||||
const threshold = safe.get('threshold')
|
||||
const valueInWei = web3.utils.toWei(value, 'ether')
|
||||
const CALL = 0
|
||||
|
||||
const isExecution = hasOneOwner(safe) || threshold === 1
|
||||
|
||||
const txHash = isExecution
|
||||
? await executeTransaction(safeAddress, to, valueInWei, data, CALL, nonce, sender, List([]))
|
||||
: await approveTransaction(safeAddress, to, valueInWei, data, CALL, nonce, sender)
|
||||
|
||||
storeSubject(safeAddress, nonce, name)
|
||||
|
||||
return txHash
|
||||
}
|
||||
|
||||
export const processTransaction = async (
|
||||
safeAddress: string,
|
||||
tx: Transaction,
|
||||
alreadyConfirmed: number,
|
||||
sender: string,
|
||||
threshold: number,
|
||||
usersConfirmed: List<string>,
|
||||
) => {
|
||||
const nonce = tx.get('nonce')
|
||||
const valueInWei = tx.get('value')
|
||||
const to = tx.get('destination')
|
||||
const data = tx.get('data')
|
||||
const CALL = 0
|
||||
|
||||
const thresholdReached = threshold === alreadyConfirmed + 1
|
||||
const txHash = thresholdReached
|
||||
? await executeTransaction(safeAddress, to, valueInWei, data, CALL, nonce, sender, usersConfirmed)
|
||||
: await approveTransaction(safeAddress, to, valueInWei, data, CALL, nonce, sender)
|
||||
|
||||
return txHash
|
||||
}
|
|
@ -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',
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
import type { Store, AnyAction } from 'redux'
|
||||
import { type GlobalState } from '~/store/'
|
||||
import { ADD_PROVIDER, REMOVE_PROVIDER } from '../actions'
|
||||
import { getWeb3, getProviderInfo } from '~/logic/wallets/getWeb3'
|
||||
import { getWeb3, getProviderInfo, WALLET_PROVIDER } from '~/logic/wallets/getWeb3'
|
||||
import { fetchProvider } from '~/logic/wallets/store/actions'
|
||||
import { loadFromStorage, saveToStorage, removeFromStorage } from '~/utils/storage'
|
||||
import closeSnackbar from '~/logic/notifications/store/actions/closeSnackbar'
|
||||
|
||||
const watchedActions = [ADD_PROVIDER, REMOVE_PROVIDER]
|
||||
|
||||
|
@ -30,17 +31,24 @@ const providerWatcherMware = (store: Store<GlobalState>) => (next: Function) =>
|
|||
clearInterval(watcherInterval)
|
||||
}
|
||||
|
||||
if (currentProviderProps.name === WALLET_PROVIDER.METAMASK && window.ethereum) {
|
||||
window.ethereum.autoRefreshOnNetworkChange = false
|
||||
}
|
||||
|
||||
saveToStorage(LAST_USED_PROVIDER_KEY, currentProviderProps.name)
|
||||
|
||||
watcherInterval = setInterval(async () => {
|
||||
const web3 = getWeb3()
|
||||
const providerInfo = await getProviderInfo(web3)
|
||||
|
||||
if (
|
||||
currentProviderProps.account !== providerInfo.account
|
||||
|| currentProviderProps.network !== providerInfo.network
|
||||
) {
|
||||
store.dispatch(fetchProvider(web3, () => {}, () => {}))
|
||||
const networkChanged = currentProviderProps.network !== providerInfo.network
|
||||
|
||||
if (networkChanged) {
|
||||
store.dispatch(closeSnackbar({ dismissAll: true }))
|
||||
}
|
||||
|
||||
if (currentProviderProps.account !== providerInfo.account || networkChanged) {
|
||||
store.dispatch(fetchProvider(web3))
|
||||
}
|
||||
}, 2000)
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ const ChangeSafeName = (props: Props) => {
|
|||
updateSafe({ address: safeAddress, name: values.safeName })
|
||||
|
||||
const notification = getNotificationsFromTxType(TX_NOTIFICATION_TYPES.SAFE_NAME_CHANGE_TX)
|
||||
showSnackbar(notification.afterExecution, enqueueSnackbar, closeSnackbar)
|
||||
showSnackbar(notification.afterExecution.noMoreConfirmationsNeeded, enqueueSnackbar, closeSnackbar)
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -52,7 +52,7 @@ const EditOwnerComponent = ({
|
|||
editSafeOwner({ safeAddress, ownerAddress, ownerName: values.ownerName })
|
||||
|
||||
const notification = getNotificationsFromTxType(TX_NOTIFICATION_TYPES.OWNER_NAME_CHANGE_TX)
|
||||
showSnackbar(notification.afterExecution, enqueueSnackbar, closeSnackbar)
|
||||
showSnackbar(notification.afterExecution.noMoreConfirmationsNeeded, enqueueSnackbar, closeSnackbar)
|
||||
|
||||
onClose()
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -52,7 +52,7 @@ const ThresholdSettings = ({
|
|||
safeAddress,
|
||||
0,
|
||||
txData,
|
||||
TX_NOTIFICATION_TYPES.THRESHOLD_CHANGE_TX,
|
||||
TX_NOTIFICATION_TYPES.SETTINGS_CHANGE_TX,
|
||||
enqueueSnackbar,
|
||||
closeSnackbar,
|
||||
)
|
||||
|
|
|
@ -15,12 +15,7 @@ import {
|
|||
TX_TYPE_EXECUTION,
|
||||
saveTxToHistory,
|
||||
} from '~/logic/safe/transactions'
|
||||
import {
|
||||
type Notification,
|
||||
type NotificationsQueue,
|
||||
getNotificationsFromTxType,
|
||||
showSnackbar,
|
||||
} from '~/logic/notifications'
|
||||
import { type NotificationsQueue, getNotificationsFromTxType, showSnackbar } from '~/logic/notifications'
|
||||
import { getErrorMessage } from '~/test/utils/ethereumErrors'
|
||||
import { ZERO_ADDRESS } from '~/logic/wallets/ethAddresses'
|
||||
import { SAFELIST_ADDRESS } from '~/routes/routes'
|
||||
|
@ -75,16 +70,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(
|
||||
|
@ -108,9 +95,14 @@ const createTransaction = (
|
|||
.then((receipt) => {
|
||||
closeSnackbar(pendingExecutionKey)
|
||||
|
||||
if (isExecution) {
|
||||
showSnackbar(notificationsQueue.afterExecution, enqueueSnackbar, closeSnackbar)
|
||||
}
|
||||
showSnackbar(
|
||||
isExecution
|
||||
? notificationsQueue.afterExecution.noMoreConfirmationsNeeded
|
||||
: notificationsQueue.afterExecution.moreConfirmationsNeeded,
|
||||
enqueueSnackbar,
|
||||
closeSnackbar,
|
||||
)
|
||||
|
||||
dispatch(fetchTransactions(safeAddress))
|
||||
|
||||
return receipt.transactionHash
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue