fix: properly update txs status on safe's startup
This commit is contained in:
parent
e9153c54d4
commit
9b257d901a
|
@ -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))),
|
||||
),
|
||||
}),
|
||||
)
|
||||
})
|
||||
updateStoredTransactionsStatus(dispatch, walletRecord)
|
||||
}
|
||||
|
||||
const handleProviderNotification = (provider, dispatch) => {
|
||||
|
|
|
@ -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<any> =>
|
|||
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))),
|
||||
),
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue