I make an API call to ContractService.getAppData(). The object it returns, appDataResult
will always contain a success key which will be a boolean.
The issue is that the request succeeds, but before it prints console.log('success'), it prints console.log('failure'). Meaning the request is interpreted as failed at first, which effects the related logic which is important to the app state.
const fetchAppData = async () => {
try {
const appDataResult = await ContractService.getAppData()
if (appDataResult.success) {
console.log('success')
// Related logic
} else {
console.log('failure')
// Related logic
}
} catch (e) {
console.error(e)
}
}
The fetchAppData function is called from a useEffect like so:
useEffect(() => {
if(isLoggedIn && isSelectedAsset) {
fetchAppData()
}
}, [isLoggedIn, isSelectedAsset])
What am I missing?