From 46c9ac3e03ea53640d35900790e222ac38723eab Mon Sep 17 00:00:00 2001 From: fernandomg Date: Sat, 23 May 2020 02:09:21 -0300 Subject: [PATCH] refactor: update tx status when provider changes --- .../wallets/store/actions/fetchProvider.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/logic/wallets/store/actions/fetchProvider.ts b/src/logic/wallets/store/actions/fetchProvider.ts index e535f7d0..8bae7327 100644 --- a/src/logic/wallets/store/actions/fetchProvider.ts +++ b/src/logic/wallets/store/actions/fetchProvider.ts @@ -1,4 +1,5 @@ import ReactGA from 'react-ga' +import { batch } from 'react-redux' import addProvider from './addProvider' @@ -7,11 +8,29 @@ import { NOTIFICATIONS, enhanceSnackbarForAction } from 'src/logic/notifications import enqueueSnackbar from 'src/logic/notifications/store/actions/enqueueSnackbar' import { ETHEREUM_NETWORK, ETHEREUM_NETWORK_IDS, getProviderInfo, getWeb3 } from 'src/logic/wallets/getWeb3' import { makeProvider } from 'src/logic/wallets/store/model/provider' +import { addOrUpdateTransactions } from 'src/routes/safe/store/actions/transactions/addOrUpdateTransactions' +import { store } from 'src/store' +import { safeSelector, safeTransactionsSelector } from 'src/routes/safe/store/selectors' +import { calculateTransactionStatus } from 'src/routes/safe/store/actions/transactions/utils/transactionHelpers' export const processProviderResponse = (dispatch, provider) => { const walletRecord = makeProvider(provider) + const state = store.getState() + const safe = safeSelector(state) + const safeAddress = safe.address + const transactions = safeTransactionsSelector(state) - dispatch(addProvider(walletRecord)) + batch(() => { + dispatch(addProvider(walletRecord)) + dispatch( + addOrUpdateTransactions({ + safeAddress, + transactions: transactions.withMutations((list) => + list.map((tx) => tx.set('status', calculateTransactionStatus(tx, safe, provider.account))), + ), + }), + ) + }) } const handleProviderNotification = (provider, dispatch) => {