From 9b257d901ae6b7ba438c24c595ae942bc209a9ef Mon Sep 17 00:00:00 2001 From: fernandomg Date: Sat, 23 May 2020 15:51:23 -0300 Subject: [PATCH] fix: properly update txs status on safe's startup --- .../wallets/store/actions/fetchProvider.ts | 24 +++---------------- .../transactions/utils/transactionHelpers.ts | 20 ++++++++++++++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/logic/wallets/store/actions/fetchProvider.ts b/src/logic/wallets/store/actions/fetchProvider.ts index 39d56726..1d3006ab 100644 --- a/src/logic/wallets/store/actions/fetchProvider.ts +++ b/src/logic/wallets/store/actions/fetchProvider.ts @@ -1,5 +1,4 @@ import ReactGA from 'react-ga' -import { batch } from 'react-redux' import addProvider from './addProvider' @@ -8,29 +7,12 @@ 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' +import { updateStoredTransactionsStatus } 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) - - batch(() => { - dispatch(addProvider(walletRecord)) - dispatch( - addOrUpdateTransactions({ - safeAddress, - transactions: transactions.withMutations((list) => - list.map((tx) => tx.set('status', calculateTransactionStatus(tx, safe, walletRecord.account))), - ), - }), - ) - }) + dispatch(addProvider(walletRecord)) + updateStoredTransactionsStatus(dispatch, walletRecord) } const handleProviderNotification = (provider, dispatch) => { diff --git a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts index 3dd46b72..9b415471 100644 --- a/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts +++ b/src/routes/safe/store/actions/transactions/utils/transactionHelpers.ts @@ -14,6 +14,9 @@ import { makeTransaction } from 'src/routes/safe/store/models/transaction' import { CANCELLATION_TRANSACTIONS_REDUCER_ID } from 'src/routes/safe/store/reducer/cancellationTransactions' import { SAFE_REDUCER_ID } from 'src/routes/safe/store/reducer/safe' import { TRANSACTIONS_REDUCER_ID } from 'src/routes/safe/store/reducer/transactions' +import { store } from 'src/store' +import { safeSelector, safeTransactionsSelector } from 'src/routes/safe/store/selectors' +import { addOrUpdateTransactions } from 'src/routes/safe/store/actions/transactions/addOrUpdateTransactions' export const isEmptyData = (data?: string | null) => { return !data || data === EMPTY_DATA @@ -286,3 +289,20 @@ export const mockTransaction = (tx, safeAddress: string, state): Promise => txCode: EMPTY_DATA, }) } + +export const updateStoredTransactionsStatus = (dispatch, walletRecord) => { + const state = store.getState() + const safe = safeSelector(state) + if (safe) { + const safeAddress = safe.address + const transactions = safeTransactionsSelector(state) + dispatch( + addOrUpdateTransactions({ + safeAddress, + transactions: transactions.withMutations((list) => + list.map((tx) => tx.set('status', calculateTransactionStatus(tx, safe, walletRecord.account))), + ), + }), + ) + } +}