fix: properly update txs status on safe's startup

This commit is contained in:
fernandomg 2020-05-23 15:51:23 -03:00
parent e9153c54d4
commit 9b257d901a
2 changed files with 23 additions and 21 deletions

View File

@ -1,5 +1,4 @@
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
import { batch } from 'react-redux'
import addProvider from './addProvider' 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 enqueueSnackbar from 'src/logic/notifications/store/actions/enqueueSnackbar'
import { ETHEREUM_NETWORK, ETHEREUM_NETWORK_IDS, getProviderInfo, getWeb3 } from 'src/logic/wallets/getWeb3' import { ETHEREUM_NETWORK, ETHEREUM_NETWORK_IDS, getProviderInfo, getWeb3 } from 'src/logic/wallets/getWeb3'
import { makeProvider } from 'src/logic/wallets/store/model/provider' import { makeProvider } from 'src/logic/wallets/store/model/provider'
import { addOrUpdateTransactions } from 'src/routes/safe/store/actions/transactions/addOrUpdateTransactions' import { updateStoredTransactionsStatus } from 'src/routes/safe/store/actions/transactions/utils/transactionHelpers'
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) => { export const processProviderResponse = (dispatch, provider) => {
const walletRecord = makeProvider(provider) const walletRecord = makeProvider(provider)
const state = store.getState() dispatch(addProvider(walletRecord))
const safe = safeSelector(state) updateStoredTransactionsStatus(dispatch, walletRecord)
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))),
),
}),
)
})
} }
const handleProviderNotification = (provider, dispatch) => { const handleProviderNotification = (provider, dispatch) => {

View File

@ -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 { CANCELLATION_TRANSACTIONS_REDUCER_ID } from 'src/routes/safe/store/reducer/cancellationTransactions'
import { SAFE_REDUCER_ID } from 'src/routes/safe/store/reducer/safe' import { SAFE_REDUCER_ID } from 'src/routes/safe/store/reducer/safe'
import { TRANSACTIONS_REDUCER_ID } from 'src/routes/safe/store/reducer/transactions' 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) => { export const isEmptyData = (data?: string | null) => {
return !data || data === EMPTY_DATA return !data || data === EMPTY_DATA
@ -286,3 +289,20 @@ export const mockTransaction = (tx, safeAddress: string, state): Promise<any> =>
txCode: EMPTY_DATA, 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))),
),
}),
)
}
}