set type for dispatch actions in hooks
This commit is contained in:
parent
8209e950d6
commit
67c67f4569
|
@ -1,6 +1,8 @@
|
|||
import { useMemo } from 'react'
|
||||
import { batch, useDispatch } from 'react-redux'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { AnyAction } from 'redux'
|
||||
import { ThunkDispatch } from 'redux-thunk'
|
||||
|
||||
import fetchCollectibles from 'src/logic/collectibles/store/actions/fetchCollectibles'
|
||||
import { fetchCurrencyValues } from 'src/logic/currencyValues/store/actions/fetchCurrencyValues'
|
||||
|
@ -8,9 +10,12 @@ import activateAssetsByBalance from 'src/logic/tokens/store/actions/activateAsse
|
|||
import fetchSafeTokens from 'src/logic/tokens/store/actions/fetchSafeTokens'
|
||||
import { fetchTokens } from 'src/logic/tokens/store/actions/fetchTokens'
|
||||
import { COINS_LOCATION_REGEX, COLLECTIBLES_LOCATION_REGEX } from 'src/routes/safe/components/Balances'
|
||||
import { AppReduxState } from 'src/store'
|
||||
|
||||
type Dispatch = ThunkDispatch<AppReduxState, undefined, AnyAction>
|
||||
|
||||
export const useFetchTokens = (safeAddress: string): void => {
|
||||
const dispatch = useDispatch()
|
||||
const dispatch = useDispatch<Dispatch>()
|
||||
const location = useLocation()
|
||||
|
||||
useMemo(() => {
|
||||
|
@ -25,7 +30,7 @@ export const useFetchTokens = (safeAddress: string): void => {
|
|||
|
||||
if (COLLECTIBLES_LOCATION_REGEX.test(location.pathname)) {
|
||||
batch(() => {
|
||||
dispatch<any>(fetchCollectibles(safeAddress)).then(() => {
|
||||
dispatch(fetchCollectibles(safeAddress)).then(() => {
|
||||
dispatch(activateAssetsByBalance(safeAddress))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { useEffect } from 'react'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { AnyAction } from 'redux'
|
||||
import { ThunkDispatch } from 'redux-thunk'
|
||||
|
||||
import loadAddressBookFromStorage from 'src/logic/addressBook/store/actions/loadAddressBookFromStorage'
|
||||
import addViewedSafe from 'src/logic/currentSession/store/actions/addViewedSafe'
|
||||
|
@ -7,15 +9,18 @@ import fetchSafeTokens from 'src/logic/tokens/store/actions/fetchSafeTokens'
|
|||
import fetchLatestMasterContractVersion from 'src/routes/safe/store/actions/fetchLatestMasterContractVersion'
|
||||
import fetchSafe from 'src/routes/safe/store/actions/fetchSafe'
|
||||
import fetchTransactions from 'src/routes/safe/store/actions/transactions/fetchTransactions'
|
||||
import fetchSafeCreationTx from '../../store/actions/fetchSafeCreationTx'
|
||||
import fetchSafeCreationTx from 'src/routes/safe/store/actions/fetchSafeCreationTx'
|
||||
import { AppReduxState } from 'src/store'
|
||||
|
||||
export const useLoadSafe = (safeAddress) => {
|
||||
const dispatch = useDispatch()
|
||||
type Dispatch = ThunkDispatch<AppReduxState, undefined, AnyAction>
|
||||
|
||||
export const useLoadSafe = (safeAddress: string): void => {
|
||||
const dispatch = useDispatch<Dispatch>()
|
||||
|
||||
useEffect(() => {
|
||||
const fetchData = () => {
|
||||
const fetchData = async () => {
|
||||
if (safeAddress) {
|
||||
dispatch<any>(fetchLatestMasterContractVersion())
|
||||
dispatch(fetchLatestMasterContractVersion())
|
||||
.then(() => {
|
||||
dispatch(fetchSafe(safeAddress))
|
||||
return dispatch(fetchSafeTokens(safeAddress))
|
||||
|
@ -28,6 +33,7 @@ export const useLoadSafe = (safeAddress) => {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
fetchData()
|
||||
}, [dispatch, safeAddress])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue