Add notification categories

This commit is contained in:
Germán Martínez 2019-09-18 17:50:59 +02:00
parent 97348ca1a2
commit 5b5d76b476
6 changed files with 37 additions and 29 deletions

View File

@ -14,10 +14,10 @@ import Layout from './component/Layout'
import actions, { type Actions } from './actions' import actions, { type Actions } from './actions'
import selector, { type SelectorProps } from './selector' import selector, { type SelectorProps } from './selector'
const SUCCESS = 'SUCCESS' export const SUCCESS = 'success'
const ERROR = 'ERROR' export const ERROR = 'error'
const WARNING = 'WARNING' export const WARNING = 'warning'
const INFO = 'INFO' export const INFO = 'info'
export type Variant = SUCCESS | ERROR | WARNING | INFO export type Variant = SUCCESS | ERROR | WARNING | INFO
@ -49,7 +49,7 @@ class HeaderComponent extends React.PureComponent<Props, State> {
const { enqueueSnackbar } = this.props const { enqueueSnackbar } = this.props
this.setState({ hasError: true }) this.setState({ hasError: true })
enqueueSnackbar(WALLET_ERROR_MSG, 'error') enqueueSnackbar(WALLET_ERROR_MSG, { variant: ERROR })
logComponentStack(error, info) logComponentStack(error, info)
} }

View File

@ -3,7 +3,9 @@ import type { Dispatch as ReduxDispatch } from 'redux'
import { ETHEREUM_NETWORK_IDS, ETHEREUM_NETWORK } from '~/logic/wallets/getWeb3' import { ETHEREUM_NETWORK_IDS, ETHEREUM_NETWORK } from '~/logic/wallets/getWeb3'
import type { ProviderProps } from '~/logic/wallets/store/model/provider' import type { ProviderProps } from '~/logic/wallets/store/model/provider'
import { makeProvider } from '~/logic/wallets/store/model/provider' import { makeProvider } from '~/logic/wallets/store/model/provider'
import { type Variant } from '~/components/Header' import {
type Variant, SUCCESS, ERROR, WARNING,
} from '~/components/Header'
import addProvider from './addProvider' import addProvider from './addProvider'
export const processProviderResponse = (dispatch: ReduxDispatch<*>, provider: ProviderProps) => { export const processProviderResponse = (dispatch: ReduxDispatch<*>, provider: ProviderProps) => {
@ -22,9 +24,12 @@ export const processProviderResponse = (dispatch: ReduxDispatch<*>, provider: Pr
dispatch(addProvider(walletRecord)) dispatch(addProvider(walletRecord))
} }
const SUCCESS_MSG = 'Wallet connected sucessfully'
const CONNECT_WALLET_MSG = 'Please connect wallet to continue'
const CONNECT_WALLET_READ_MODE_MSG = 'You are in read-only mode: Please connect wallet'
const UNLOCK_MSG = 'Unlock your wallet to connect' const UNLOCK_MSG = 'Unlock your wallet to connect'
const WRONG_NETWORK = 'You are connected to wrong network. Please use RINKEBY' const WRONG_NETWORK_RINKEBY_MSG = 'Wrong network: Please use Rinkeby'
const SUCCESS_MSG = 'Wallet connected'
export const WALLET_ERROR_MSG = 'Error connecting to your wallet' export const WALLET_ERROR_MSG = 'Error connecting to your wallet'
const handleProviderNotification = ( const handleProviderNotification = (
@ -34,17 +39,17 @@ const handleProviderNotification = (
const { loaded, available, network } = provider const { loaded, available, network } = provider
if (!loaded) { if (!loaded) {
enqueueSnackbar(WALLET_ERROR_MSG, 'error') enqueueSnackbar(WALLET_ERROR_MSG, { variant: ERROR })
return return
} }
if (ETHEREUM_NETWORK_IDS[network] !== ETHEREUM_NETWORK.RINKEBY) { if (ETHEREUM_NETWORK_IDS[network] !== ETHEREUM_NETWORK.RINKEBY) {
enqueueSnackbar(WRONG_NETWORK, 'error') enqueueSnackbar(WRONG_NETWORK_RINKEBY_MSG, { variant: ERROR, persist: true })
return return
} }
const msg = available ? SUCCESS_MSG : UNLOCK_MSG const msg = available ? SUCCESS_MSG : UNLOCK_MSG
const variant = available ? 'success' : 'warning' const variant = { variant: (available ? SUCCESS : WARNING) }
enqueueSnackbar(msg, variant) enqueueSnackbar(msg, variant)
} }

View File

@ -1,7 +1,7 @@
// @flow // @flow
import type { Dispatch as ReduxDispatch } from 'redux' import type { Dispatch as ReduxDispatch } from 'redux'
import { makeProvider, type ProviderProps, type Provider } from '~/logic/wallets/store/model/provider' import { makeProvider, type ProviderProps, type Provider } from '~/logic/wallets/store/model/provider'
import { type Variant } from '~/components/Header' import { type Variant, INFO } from '~/components/Header'
import addProvider from './addProvider' import addProvider from './addProvider'
export default (enqueueSnackbar: (message: string, variant: Variant) => void) => async (dispatch: ReduxDispatch<*>) => { export default (enqueueSnackbar: (message: string, variant: Variant) => void) => async (dispatch: ReduxDispatch<*>) => {
@ -14,7 +14,7 @@ export default (enqueueSnackbar: (message: string, variant: Variant) => void) =>
} }
const provider: Provider = makeProvider(providerProps) const provider: Provider = makeProvider(providerProps)
enqueueSnackbar('Wallet disconnected succesfully', 'info') enqueueSnackbar('Wallet disconnected succesfully', { variant: INFO })
dispatch(addProvider(provider)) dispatch(addProvider(provider))
} }

View File

@ -12,7 +12,8 @@ import GnoForm from '~/components/forms/GnoForm'
import Row from '~/components/layout/Row' import Row from '~/components/layout/Row'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import { type Variant } from '~/components/Header' import { type Variant, SUCCESS } from '~/components/Header'
import { NOTIFICATIONS } from '~/logic/notifications'
import { styles } from './style' import { styles } from './style'
export const SAFE_NAME_INPUT_TEST_ID = 'safe-name-input' export const SAFE_NAME_INPUT_TEST_ID = 'safe-name-input'
@ -33,7 +34,7 @@ const ChangeSafeName = (props: Props) => {
const handleSubmit = (values) => { const handleSubmit = (values) => {
updateSafe({ address: safeAddress, name: values.safeName }) updateSafe({ address: safeAddress, name: values.safeName })
enqueueSnackbar('Safe name changed', 'success') enqueueSnackbar(NOTIFICATIONS.SAFE_NAME_CHANGED_MSG, { variant: SUCCESS })
} }
return ( return (

View File

@ -9,10 +9,12 @@ import {
approveTransaction, approveTransaction,
executeTransaction, executeTransaction,
CALL, CALL,
type Notifications,
DEFAULT_NOTIFICATIONS,
} from '~/logic/safe/transactions' } from '~/logic/safe/transactions'
import { type Variant } from '~/components/Header' import {
type Notifications,
NOTIFICATIONS,
} from '~/logic/notifications'
import { type Variant, SUCCESS, ERROR } from '~/components/Header'
const createTransaction = ( const createTransaction = (
safeAddress: string, safeAddress: string,
@ -21,7 +23,7 @@ const createTransaction = (
txData: string = EMPTY_DATA, txData: string = EMPTY_DATA,
enqueueSnackbar: (message: string, variant: Variant) => void, enqueueSnackbar: (message: string, variant: Variant) => void,
shouldExecute?: boolean, shouldExecute?: boolean,
notifications?: Notifications = DEFAULT_NOTIFICATIONS, notifications?: Notifications = NOTIFICATIONS,
) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState<GlobalState>) => { ) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState<GlobalState>) => {
const state: GlobalState = getState() const state: GlobalState = getState()
@ -34,16 +36,16 @@ const createTransaction = (
let txHash let txHash
try { try {
if (isExecution) { if (isExecution) {
const showNotification = () => enqueueSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success') const showNotification = () => enqueueSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, { variant: SUCCESS })
txHash = await executeTransaction(showNotification, safeInstance, to, valueInWei, txData, CALL, nonce, from) txHash = await executeTransaction(showNotification, safeInstance, to, valueInWei, txData, CALL, nonce, from)
enqueueSnackbar(notifications.AFTER_EXECUTION, 'success') enqueueSnackbar(notifications.AFTER_EXECUTION, { variant: SUCCESS })
} else { } else {
const showNotification = () => enqueueSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success') const showNotification = () => enqueueSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, { variant: SUCCESS })
txHash = await approveTransaction(showNotification, safeInstance, to, valueInWei, txData, CALL, nonce, from) txHash = await approveTransaction(showNotification, safeInstance, to, valueInWei, txData, CALL, nonce, from)
enqueueSnackbar(notifications.CREATED_MORE_CONFIRMATIONS_NEEDED, 'success') enqueueSnackbar(notifications.CREATED_MORE_CONFIRMATIONS_NEEDED, { variant: SUCCESS })
} }
} catch (err) { } catch (err) {
enqueueSnackbar(notifications.ERROR, 'error') enqueueSnackbar(notifications.ERROR, { variant: ERROR })
console.error(`Error while creating transaction: ${err}`) console.error(`Error while creating transaction: ${err}`)
} }

View File

@ -6,7 +6,7 @@ import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { type GlobalState } from '~/store' import { type GlobalState } from '~/store'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { approveTransaction, executeTransaction, CALL } from '~/logic/safe/transactions' import { approveTransaction, executeTransaction, CALL } from '~/logic/safe/transactions'
import { type Variant } from '~/components/Header' import { type Variant, SUCCESS } from '~/components/Header'
// https://gnosis-safe.readthedocs.io/en/latest/contracts/signatures.html#pre-validated-signatures // https://gnosis-safe.readthedocs.io/en/latest/contracts/signatures.html#pre-validated-signatures
// https://github.com/gnosis/safe-contracts/blob/master/test/gnosisSafeTeamEdition.js#L26 // https://github.com/gnosis/safe-contracts/blob/master/test/gnosisSafeTeamEdition.js#L26
@ -47,7 +47,7 @@ const processTransaction = (
let txHash let txHash
if (shouldExecute) { if (shouldExecute) {
const showNotification = () => enqueueSnackbar('Transaction has been submitted', 'success') const showNotification = () => enqueueSnackbar('Transaction has been submitted', { variant: SUCCESS })
txHash = await executeTransaction( txHash = await executeTransaction(
showNotification, showNotification,
safeInstance, safeInstance,
@ -59,9 +59,9 @@ const processTransaction = (
from, from,
sigs, sigs,
) )
enqueueSnackbar('Transaction has been confirmed', 'success') enqueueSnackbar('Transaction has been confirmed', { variant: SUCCESS })
} else { } else {
const showNotification = () => enqueueSnackbar('Approval transaction has been submitted', 'success') const showNotification = () => enqueueSnackbar('Approval transaction has been submitted', { variant: SUCCESS })
txHash = await approveTransaction( txHash = await approveTransaction(
showNotification, showNotification,
safeInstance, safeInstance,
@ -72,7 +72,7 @@ const processTransaction = (
nonce, nonce,
from, from,
) )
enqueueSnackbar('Approval transaction has been confirmed', 'success') enqueueSnackbar('Approval transaction has been confirmed', { variant: SUCCESS })
} }
dispatch(fetchTransactions(safeAddress)) dispatch(fetchTransactions(safeAddress))