refactor: update tx status when provider changes

This commit is contained in:
fernandomg 2020-05-23 02:09:21 -03:00
parent 2c41105474
commit 46c9ac3e03
1 changed files with 20 additions and 1 deletions

View File

@ -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) => {