Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ const App: React.FC = ({ children }) => {
const granted = useSelector(grantedSelector)
const sidebarItems = useSidebarItems()

useLoadSafe(safeAddress)
useSafeScheduledUpdates(safeAddress)
const safeLoaded = useLoadSafe(safeAddress)
useSafeScheduledUpdates(safeLoaded, safeAddress)

const sendFunds = safeActionsState.sendFunds
const formattedTotalBalance = currentSafeBalance ? formatAmountInUsFormat(currentSafeBalance) : ''
Expand Down
26 changes: 13 additions & 13 deletions src/logic/safe/hooks/useLoadSafe.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useDispatch } from 'react-redux'

import loadAddressBookFromStorage from 'src/logic/addressBook/store/actions/loadAddressBookFromStorage'
Expand All @@ -10,26 +10,26 @@ import fetchTransactions from 'src/logic/safe/store/actions/transactions/fetchTr
import fetchSafeCreationTx from 'src/logic/safe/store/actions/fetchSafeCreationTx'
import { Dispatch } from 'src/logic/safe/store/actions/types.d'

export const useLoadSafe = (safeAddress?: string): void => {
export const useLoadSafe = (safeAddress?: string): boolean => {
const dispatch = useDispatch<Dispatch>()
const [isSafeLoaded, setIsSafeLoaded] = useState(false)

useEffect(() => {
const fetchData = () => {
const fetchData = async () => {
if (safeAddress) {
dispatch(fetchLatestMasterContractVersion())
.then(() => {
dispatch(fetchSafe(safeAddress))
return dispatch(fetchSafeTokens(safeAddress))
})
.then(() => {
dispatch(fetchSafeCreationTx(safeAddress))
dispatch(fetchTransactions(safeAddress))
return dispatch(addViewedSafe(safeAddress))
})
await dispatch(fetchLatestMasterContractVersion())
await dispatch(fetchSafe(safeAddress))
setIsSafeLoaded(true)
await dispatch(fetchSafeTokens(safeAddress))
dispatch(fetchSafeCreationTx(safeAddress))
dispatch(fetchTransactions(safeAddress))
dispatch(addViewedSafe(safeAddress))
}
}
dispatch(loadAddressBookFromStorage())

fetchData()
}, [dispatch, safeAddress])

return isSafeLoaded
}
6 changes: 3 additions & 3 deletions src/logic/safe/hooks/useSafeScheduledUpdates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { checkAndUpdateSafe } from 'src/logic/safe/store/actions/fetchSafe'
import fetchTransactions from 'src/logic/safe/store/actions/transactions/fetchTransactions'
import { TIMEOUT } from 'src/utils/constants'

export const useSafeScheduledUpdates = (safeAddress?: string): void => {
export const useSafeScheduledUpdates = (safeLoaded: boolean, safeAddress?: string): void => {
const dispatch = useDispatch()
const timer = useRef<number>()

Expand All @@ -34,13 +34,13 @@ export const useSafeScheduledUpdates = (safeAddress?: string): void => {
}
}

if (safeAddress) {
if (safeAddress && safeLoaded) {
fetchSafeData(safeAddress)
}

return () => {
mounted = false
clearTimeout(timer.current)
}
}, [dispatch, safeAddress])
}, [dispatch, safeAddress, safeLoaded])
}