* Fixs duplicated notifications * Implements feedback, now the displayed txHash are stored on localstorage and once the first time we notify the user about it, they won't never appear again * Uses the last time the user logged in * Fix safe version null check Fixs date string comparison Adds the safe address to the check of last time logged in
This commit is contained in:
parent
6b6aba041b
commit
5d7fa6428f
|
@ -18,9 +18,49 @@ import { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/addTransactions'
|
||||||
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||||
import { safeParamAddressFromStateSelector, safesMapSelector } from '~/routes/safe/store/selectors'
|
import { safeParamAddressFromStateSelector, safesMapSelector } from '~/routes/safe/store/selectors'
|
||||||
import { type GlobalState } from '~/store/'
|
import { type GlobalState } from '~/store/'
|
||||||
|
import { loadFromStorage, saveToStorage } from '~/utils/storage'
|
||||||
|
|
||||||
const watchedActions = [ADD_TRANSACTIONS, ADD_INCOMING_TRANSACTIONS, ADD_SAFE]
|
const watchedActions = [ADD_TRANSACTIONS, ADD_INCOMING_TRANSACTIONS, ADD_SAFE]
|
||||||
|
|
||||||
|
const sendAwaitingTransactionNotification = async (
|
||||||
|
dispatch: Function,
|
||||||
|
safeAddress: string,
|
||||||
|
awaitingTxsSubmissionDateList: List[],
|
||||||
|
notificationKey: string,
|
||||||
|
notificationClickedCb: Function,
|
||||||
|
) => {
|
||||||
|
const LAST_TIME_USED_LOGGED_IN_ID = 'LAST_TIME_USED_LOGGED_IN_ID'
|
||||||
|
if (!dispatch || !safeAddress || !awaitingTxsSubmissionDateList || !notificationKey) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (awaitingTxsSubmissionDateList.size === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let lastTimeUserLoggedInForSafes = (await loadFromStorage(LAST_TIME_USED_LOGGED_IN_ID)) || []
|
||||||
|
let lastTimeUserLoggedIn =
|
||||||
|
lastTimeUserLoggedInForSafes && lastTimeUserLoggedInForSafes[safeAddress]
|
||||||
|
? lastTimeUserLoggedInForSafes[safeAddress]
|
||||||
|
: null
|
||||||
|
|
||||||
|
const filteredDuplicatedAwaitingTxList = awaitingTxsSubmissionDateList.filter(submissionDate => {
|
||||||
|
return lastTimeUserLoggedIn ? new Date(submissionDate) > new Date(lastTimeUserLoggedIn) : true
|
||||||
|
})
|
||||||
|
|
||||||
|
if (filteredDuplicatedAwaitingTxList.size === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dispatch(
|
||||||
|
enqueueSnackbar(enhanceSnackbarForAction(NOTIFICATIONS.TX_WAITING_MSG, notificationKey, notificationClickedCb)),
|
||||||
|
)
|
||||||
|
|
||||||
|
lastTimeUserLoggedInForSafes = {
|
||||||
|
...lastTimeUserLoggedInForSafes,
|
||||||
|
[safeAddress]: lastTimeUserLoggedIn || new Date(),
|
||||||
|
}
|
||||||
|
await saveToStorage(LAST_TIME_USED_LOGGED_IN_ID, lastTimeUserLoggedInForSafes)
|
||||||
|
}
|
||||||
|
|
||||||
const notificationsMiddleware = (store: Store<GlobalState>) => (next: Function) => async (action: Action<*>) => {
|
const notificationsMiddleware = (store: Store<GlobalState>) => (next: Function) => async (action: Action<*>) => {
|
||||||
const handledAction = next(action)
|
const handledAction = next(action)
|
||||||
const { dispatch } = store
|
const { dispatch } = store
|
||||||
|
@ -41,23 +81,28 @@ const notificationsMiddleware = (store: Store<GlobalState>) => (next: Function)
|
||||||
cancellationTransactionsByNonce,
|
cancellationTransactionsByNonce,
|
||||||
userAddress,
|
userAddress,
|
||||||
)
|
)
|
||||||
const awaitingTransactionsList = awaitingTransactions.get(safeAddress, List([]))
|
const awaitingTxsSubmissionDateList = awaitingTransactions
|
||||||
|
.get(safeAddress, List([]))
|
||||||
|
.map(tx => tx.submissionDate)
|
||||||
|
|
||||||
const safes = safesMapSelector(state)
|
const safes = safesMapSelector(state)
|
||||||
const currentSafe = safes.get(safeAddress)
|
const currentSafe = safes.get(safeAddress)
|
||||||
|
|
||||||
if (!isUserOwner(currentSafe, userAddress) || awaitingTransactionsList.size === 0) {
|
if (!isUserOwner(currentSafe, userAddress) || awaitingTxsSubmissionDateList.size === 0) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
const notificationKey = `${safeAddress}-awaiting`
|
||||||
const notificationKey = `${safeAddress}-${userAddress}`
|
|
||||||
const onNotificationClicked = () => {
|
const onNotificationClicked = () => {
|
||||||
dispatch(closeSnackbarAction({ key: notificationKey }))
|
dispatch(closeSnackbarAction({ key: notificationKey }))
|
||||||
dispatch(push(`/safes/${safeAddress}/transactions`))
|
dispatch(push(`/safes/${safeAddress}/transactions`))
|
||||||
}
|
}
|
||||||
dispatch(
|
|
||||||
enqueueSnackbar(
|
await sendAwaitingTransactionNotification(
|
||||||
enhanceSnackbarForAction(NOTIFICATIONS.TX_WAITING_MSG, notificationKey, onNotificationClicked),
|
dispatch,
|
||||||
),
|
safeAddress,
|
||||||
|
awaitingTxsSubmissionDateList,
|
||||||
|
notificationKey,
|
||||||
|
onNotificationClicked,
|
||||||
)
|
)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue