(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:
Agustin Pane 2020-12-12 10:39:50 -03:00 committed by GitHub
parent 1bb3ebce63
commit 0f592111e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 18 deletions

View File

@ -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) : ''

View File

@ -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(() => {
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
}

View File

@ -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])
}