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