-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Futures refactor continued #1702
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Tburm
previously approved these changes
Dec 2, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this, but note that I'm working a branch which will fix the duplicated testnet markets.
avclarke
commented
Dec 3, 2022
use market keys to index
Tburm
reviewed
Dec 12, 2022
@avclarke All is good other than one comment I left here with a suggestion. Can approve once we commit that. |
Co-authored-by: troyb.eth <me@troyb.xyz>
Tburm
approved these changes
Dec 12, 2022
platschi
approved these changes
Dec 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Transaction pattern
Started to use a pattern where inside the action you set the transaction status but then a single monitor function sitting at the app level monitors the transaction and resolves the state. This enables us to react to transaction statuses in components while allowing the monitoring and resolution to be managed in a single place.
The action part looks like this
And then a single monitor hooks resolves the tx as seen here
Queries pattern
In the existing setup with the RefetchProvider it was handling app wide query management, which was nice for not having to worry about some data not being populated but resulted in a lot of unnecessary queries and network requests. So moving forward I’ve started to transition to the pages being responsible for kicking off the queries they need and any polling. I added some helpers for polling actions you can find here https://github.com/Kwenta/kwenta/blob/f1aab83c798520045fb44447ff501fb729eac822/state/hooks.ts
The polling hooks include:
usePollWhenReady
which will only start the polling once provider has been set, which prevents a premature fetch and error from the sdk of no provider.useStartPolling
hook which returns a startPolling function allowing you more control over when you’d like polling to begin, for example in futures we need to wait for some other data and account / wallet info before kicking off the polling.Then at the higher level I’ve created a hooks folder under states/futures which has a simple pollFuturesData that is currently being used in both the markets page and futures page. https://github.com/Kwenta/kwenta/blob/f1aab83c798520045fb44447ff501fb729eac822/state/futures/hooks.ts
I’ve also added some tracking (outside the component tree) within the polling hook to check if there are duplicate actions being polled, this might happen if a dev adds some polling within a component, which is also being handled by the parent page. If we get to this state it will print a warning in the console so we can easily be aware when this occurs and make sure we clean it up.
It's not a perfect pattern but it seems to work well so far. So the general pattern would be:
state/<page>
you want to fetch forusePollFuturesData
which calls a polling hook passing the query action you needOther solutions I’ve been considering are: