(Feature) Safe owners not loaded (#1710)
* Makes getGasEstimationTxResponse exportable * Removes the race condition between useLoadSafe and useSafeScheduledUpdates * Reword safeLoaded * Improve check for setIsSafeLoaded
This commit is contained in:
parent
1bb3ebce63
commit
0f592111e9
|
@ -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) : ''
|
||||
|
|
|
@ -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'
|
||||
|
@ -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(() => {
|
||||
await dispatch(fetchLatestMasterContractVersion())
|
||||
await dispatch(fetchSafe(safeAddress))
|
||||
setIsSafeLoaded(true)
|
||||
await dispatch(fetchSafeTokens(safeAddress))
|
||||
dispatch(fetchSafeCreationTx(safeAddress))
|
||||
dispatch(fetchTransactions(safeAddress))
|
||||
return dispatch(addViewedSafe(safeAddress))
|
||||
})
|
||||
dispatch(addViewedSafe(safeAddress))
|
||||
}
|
||||
}
|
||||
dispatch(loadAddressBookFromStorage())
|
||||
|
||||
fetchData()
|
||||
}, [dispatch, safeAddress])
|
||||
|
||||
return isSafeLoaded
|
||||
}
|
||||
|
|
|
@ -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>()
|
||||
|
||||
|
@ -34,7 +34,7 @@ export const useSafeScheduledUpdates = (safeAddress?: string): void => {
|
|||
}
|
||||
}
|
||||
|
||||
if (safeAddress) {
|
||||
if (safeAddress && safeLoaded) {
|
||||
fetchSafeData(safeAddress)
|
||||
}
|
||||
|
||||
|
@ -42,5 +42,5 @@ export const useSafeScheduledUpdates = (safeAddress?: string): void => {
|
|||
mounted = false
|
||||
clearTimeout(timer.current)
|
||||
}
|
||||
}, [dispatch, safeAddress])
|
||||
}, [dispatch, safeAddress, safeLoaded])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue