From 67c67f4569d24e102c5c06f87bbd6e790d560ff3 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Wed, 15 Jul 2020 19:17:12 -0300 Subject: [PATCH] set type for dispatch actions in hooks --- .../safe/container/hooks/useFetchTokens.tsx | 9 +++++++-- src/routes/safe/container/hooks/useLoadSafe.tsx | 16 +++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/routes/safe/container/hooks/useFetchTokens.tsx b/src/routes/safe/container/hooks/useFetchTokens.tsx index fa50b3fb..ee424474 100644 --- a/src/routes/safe/container/hooks/useFetchTokens.tsx +++ b/src/routes/safe/container/hooks/useFetchTokens.tsx @@ -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 export const useFetchTokens = (safeAddress: string): void => { - const dispatch = useDispatch() + const dispatch = useDispatch() const location = useLocation() useMemo(() => { @@ -25,7 +30,7 @@ export const useFetchTokens = (safeAddress: string): void => { if (COLLECTIBLES_LOCATION_REGEX.test(location.pathname)) { batch(() => { - dispatch(fetchCollectibles(safeAddress)).then(() => { + dispatch(fetchCollectibles(safeAddress)).then(() => { dispatch(activateAssetsByBalance(safeAddress)) }) }) diff --git a/src/routes/safe/container/hooks/useLoadSafe.tsx b/src/routes/safe/container/hooks/useLoadSafe.tsx index 9b2b3d1c..d963e7a5 100644 --- a/src/routes/safe/container/hooks/useLoadSafe.tsx +++ b/src/routes/safe/container/hooks/useLoadSafe.tsx @@ -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 + +export const useLoadSafe = (safeAddress: string): void => { + const dispatch = useDispatch() useEffect(() => { - const fetchData = () => { + const fetchData = async () => { if (safeAddress) { - dispatch(fetchLatestMasterContractVersion()) + dispatch(fetchLatestMasterContractVersion()) .then(() => { dispatch(fetchSafe(safeAddress)) return dispatch(fetchSafeTokens(safeAddress)) @@ -28,6 +33,7 @@ export const useLoadSafe = (safeAddress) => { }) } } + fetchData() }, [dispatch, safeAddress]) }