mirror of
https://github.com/status-im/safe-react.git
synced 2025-01-12 19:14:08 +00:00
(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 granted = useSelector(grantedSelector)
|
||||||
const sidebarItems = useSidebarItems()
|
const sidebarItems = useSidebarItems()
|
||||||
|
|
||||||
useLoadSafe(safeAddress)
|
const safeLoaded = useLoadSafe(safeAddress)
|
||||||
useSafeScheduledUpdates(safeAddress)
|
useSafeScheduledUpdates(safeLoaded, safeAddress)
|
||||||
|
|
||||||
const sendFunds = safeActionsState.sendFunds
|
const sendFunds = safeActionsState.sendFunds
|
||||||
const formattedTotalBalance = currentSafeBalance ? formatAmountInUsFormat(currentSafeBalance) : ''
|
const formattedTotalBalance = currentSafeBalance ? formatAmountInUsFormat(currentSafeBalance) : ''
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
|
|
||||||
import loadAddressBookFromStorage from 'src/logic/addressBook/store/actions/loadAddressBookFromStorage'
|
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 fetchSafeCreationTx from 'src/logic/safe/store/actions/fetchSafeCreationTx'
|
||||||
import { Dispatch } from 'src/logic/safe/store/actions/types.d'
|
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 dispatch = useDispatch<Dispatch>()
|
||||||
|
const [isSafeLoaded, setIsSafeLoaded] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = () => {
|
const fetchData = async () => {
|
||||||
if (safeAddress) {
|
if (safeAddress) {
|
||||||
dispatch(fetchLatestMasterContractVersion())
|
await dispatch(fetchLatestMasterContractVersion())
|
||||||
.then(() => {
|
await dispatch(fetchSafe(safeAddress))
|
||||||
dispatch(fetchSafe(safeAddress))
|
setIsSafeLoaded(true)
|
||||||
return dispatch(fetchSafeTokens(safeAddress))
|
await dispatch(fetchSafeTokens(safeAddress))
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
dispatch(fetchSafeCreationTx(safeAddress))
|
dispatch(fetchSafeCreationTx(safeAddress))
|
||||||
dispatch(fetchTransactions(safeAddress))
|
dispatch(fetchTransactions(safeAddress))
|
||||||
return dispatch(addViewedSafe(safeAddress))
|
dispatch(addViewedSafe(safeAddress))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dispatch(loadAddressBookFromStorage())
|
dispatch(loadAddressBookFromStorage())
|
||||||
|
|
||||||
fetchData()
|
fetchData()
|
||||||
}, [dispatch, safeAddress])
|
}, [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 fetchTransactions from 'src/logic/safe/store/actions/transactions/fetchTransactions'
|
||||||
import { TIMEOUT } from 'src/utils/constants'
|
import { TIMEOUT } from 'src/utils/constants'
|
||||||
|
|
||||||
export const useSafeScheduledUpdates = (safeAddress?: string): void => {
|
export const useSafeScheduledUpdates = (safeLoaded: boolean, safeAddress?: string): void => {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const timer = useRef<number>()
|
const timer = useRef<number>()
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ export const useSafeScheduledUpdates = (safeAddress?: string): void => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (safeAddress) {
|
if (safeAddress && safeLoaded) {
|
||||||
fetchSafeData(safeAddress)
|
fetchSafeData(safeAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,5 +42,5 @@ export const useSafeScheduledUpdates = (safeAddress?: string): void => {
|
|||||||
mounted = false
|
mounted = false
|
||||||
clearTimeout(timer.current)
|
clearTimeout(timer.current)
|
||||||
}
|
}
|
||||||
}, [dispatch, safeAddress])
|
}, [dispatch, safeAddress, safeLoaded])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user