moonstream-to / api

Building blocks for your blockchain economy
https://moonstream.to
Apache License 2.0
135 stars 49 forks source link

useStream refactoring #264

Open peersky opened 2 years ago

peersky commented 2 years ago

Right now useStream hook contains inside various logic components:

All these three logic blocks are quite and it might have sense to make them generic in separate files.

Possible issues to work on:

To solve it we should use react query instead.

Beside that there are code style that has to be fixed:

1.

if (!ignoreStart) {
      if (
        !newBoundary.start_time ||
        (extensionBoundary.start_time &&
          extensionBoundary.start_time <= newBoundary.start_time)
      ) {
        newBoundary.start_time = extensionBoundary.start_time;
        newBoundary.include_start =
          newBoundary.include_start || extensionBoundary.include_start;
      }
      newBoundary.include_start =
        newBoundary.include_start || extensionBoundary.include_start;
    }

This code has lint warning: Property 'start_time' does not exist on type '{}'.ts(2339)

This can potentially crash frontend if later code changes and function is called before start_time is defined in object.

Possible solution: Define object fields in constructor

  1. In react-query v3 better practice is to define query object as one const.
 const streamCache = useQuery(...)
return {streamCache}
// component.js
const { streamCache } = useStream()
if(streamCache.isLoading) ....
Andrei-Dolgolev commented 2 years ago

Okay finally: The problem of stream_boundary is that stream_boundary is not depend on data wich it requested.