Fix notification re-appears (#1925)

Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
This commit is contained in:
nicolas 2021-02-22 07:09:48 -03:00 committed by GitHub
parent 45b24e98fd
commit 8e52ec5f60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,6 +32,8 @@ const watchedActions = [
ADD_QUEUED_TRANSACTIONS, ADD_QUEUED_TRANSACTIONS,
] ]
const LAST_TIME_USED_LOGGED_IN_ID = 'LAST_TIME_USED_LOGGED_IN_ID'
const sendAwaitingTransactionNotification = async ( const sendAwaitingTransactionNotification = async (
dispatch, dispatch,
safeAddress, safeAddress,
@ -39,7 +41,6 @@ const sendAwaitingTransactionNotification = async (
notificationKey, notificationKey,
notificationClickedCb, notificationClickedCb,
) => { ) => {
const LAST_TIME_USED_LOGGED_IN_ID = 'LAST_TIME_USED_LOGGED_IN_ID'
if (!dispatch || !safeAddress || !awaitingTxsSubmissionDateList || !notificationKey) { if (!dispatch || !safeAddress || !awaitingTxsSubmissionDateList || !notificationKey) {
return return
} }
@ -48,8 +49,7 @@ const sendAwaitingTransactionNotification = async (
} }
let lastTimeUserLoggedInForSafes = (await loadFromStorage<Record<string, string>>(LAST_TIME_USED_LOGGED_IN_ID)) || {} let lastTimeUserLoggedInForSafes = (await loadFromStorage<Record<string, string>>(LAST_TIME_USED_LOGGED_IN_ID)) || {}
const lastTimeUserLoggedIn = const lastTimeUserLoggedIn = lastTimeUserLoggedInForSafes[safeAddress]
lastTimeUserLoggedInForSafes && lastTimeUserLoggedInForSafes[safeAddress]
? lastTimeUserLoggedInForSafes[safeAddress] ? lastTimeUserLoggedInForSafes[safeAddress]
: null : null
@ -57,16 +57,17 @@ const sendAwaitingTransactionNotification = async (
return lastTimeUserLoggedIn ? new Date(submissionDate) > new Date(lastTimeUserLoggedIn) : true return lastTimeUserLoggedIn ? new Date(submissionDate) > new Date(lastTimeUserLoggedIn) : true
}) })
if (filteredDuplicatedAwaitingTxList.length === 0) { if (!filteredDuplicatedAwaitingTxList.length) {
return return
} }
dispatch( dispatch(
enqueueSnackbar(enhanceSnackbarForAction(NOTIFICATIONS.TX_WAITING_MSG, notificationKey, notificationClickedCb)), enqueueSnackbar(enhanceSnackbarForAction(NOTIFICATIONS.TX_WAITING_MSG, notificationKey, notificationClickedCb)),
) )
lastTimeUserLoggedInForSafes = { lastTimeUserLoggedInForSafes = {
...lastTimeUserLoggedInForSafes, ...lastTimeUserLoggedInForSafes,
[safeAddress]: lastTimeUserLoggedIn || new Date(), [safeAddress]: new Date(),
} }
await saveToStorage(LAST_TIME_USED_LOGGED_IN_ID, lastTimeUserLoggedInForSafes) await saveToStorage(LAST_TIME_USED_LOGGED_IN_ID, lastTimeUserLoggedInForSafes)
} }