Handle data loading without listeners
Feature
Merge Request
Related Issue
resolves #409 (closed)
Description of Feature
Changes
One single initial data-loading function (ConnectData in loading reducer) and one single loading component for the whole app that loads after PersistStoreInstatiator and before App
- gets web3
- gets currentBlock
- loadFathomNetworkParams (async)
- await loadConceptsFromConceptRegistery(currentBlock)(dispatch, getState) // (async) => now uses 'extend' to update conept state, in order for them to be persisted, resolves https://gitlab.com/fathom/app/issues/411
- await fetchLatestAssessments(currentBlock)(dispatch, getState) // (async) resolves
- receiveVariable('lastUpdatedAt', currentBlock)
- setInterval to loop call fetchLatestAssessments every 5seconds
Initial ConnectData function,loadConceptsFromConceptRegistery and fetchLatestAssessments are async and set a lastUpdatedAt block number variable in persisted state along with the concepts and assessments. all sub-loading-functions (subfunctions of ConnectData) need to be async as well
fetchLatestAssessments
- fetchLatestAssessments takes a blocknumber as input and checks all events between the lastUpdated block and the current block, the rest is like it used to be before (but async)
- called periodically to refresh assessments state (concepts are only refreshed on reload)
What we won't be needing anymore:
- We get rid of all loader components except the PersistStoreInstatiator (includes initial MM loading and saved into window.web3), the Data-Initializer (runs loadConceptsFromConceptRegistery and fetchLatestAssessments once, displays app, starts interval call to loadConceptsFromConceptRegistery and fetchLatestAssessments)
event related
- processEvents
- the 'connect' and 'initializeEventWatcher' function that were starting event watching
- separate loading status for assessments and concepts
persist related
- persist deployedFathomTokenAt and deployedConceptRegistryAt (what if they were redeployed! will be changed in https://gitlab.com/fathom/app/issues/411)
Motivation and Context
Following https://gitlab.com/fathom/app/issues/399
we decided it would be easier to not use event listeners
NB
MetaMask sometimes returns empty arrays of events
What's Next?
- Display different loading stages between initial and Loaded
- Calculate the blocktime depending on network
- Get web3 from initial loading
Edited by Antoine Estienne