Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

refactor: #513 migrate <AllTrades/> to react-query. #515

Merged
merged 4 commits into from
Sep 10, 2020
Merged

refactor: #513 migrate <AllTrades/> to react-query. #515

merged 4 commits into from
Sep 10, 2020

Conversation

jwineman
Copy link
Contributor

@jwineman jwineman commented Aug 26, 2020

Fixes #513.

@vercel
Copy link

vercel bot commented Aug 26, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/synthetixio/synthetix-exchange/j7agpbq8b
✅ Preview: https://synthetix-exchange-git-fork-jwineman-jwineman-snx513.synthetixio.vercel.app

@jwineman
Copy link
Contributor Author

I didn't get any compile errors removing src/ducks/trades/allTrades.js so I assume its not used, if Im wrong let me know.

@evgenyboxer
Copy link
Contributor

evgenyboxer commented Aug 26, 2020

@jwineman awesome work! lgtm!

There is just one minor formatting issue with prettier (if you run npm run lint you should see it), and running npm run lint:fix should fix it. Please push this change, and it's good to merge!

Later on, we can add something like lint-staged with husky to apply the formatting to the committed files.

@jwineman
Copy link
Contributor Author

Can't remove the myTrades duck because its still used on <Exchanges/> and <Chart/>.

max: MAX_TRADES,
});
for (let i = 0; i < trades.length; i++) {
if (!!settledTradesQuery.data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I allowed to mutate state inside of react-query before I return it or does this code need to be modified to be immutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this settledTradesQuery logic is essentially duplicated from the myTrades.js duck. Is it worth consolidating down to a single function?

fetchMyTradesRequest();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
type SettledTrade = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I be getting this type from somewhere else?

@evgenyboxer
Copy link
Contributor

evgenyboxer commented Aug 31, 2020

@jwineman great work.

The next thing to do is to remove the rest of the instances of "myTrades" that use the sagas. Reusing react-query queries is fairly easy - so you should just use them in those places. (it has a global cache)

There is a new pattern which I'm using now (in Kwenta for queries)

All queries reside in -
/src/queries (so, for example, you got a file named useMyTradesQuery.ts)

Then, whenever you want to use myTrades query, you just do const myTradesQuery = useMyTradesQuery(). So like, let's say you got 2 pages that use this query, you put them in those 2 places.

If a couple of components on the same page need to use the same query, then perhaps their shared parent can own it (or put it in context so you don't have to drill down the props). Sometimes you can just use the cache... but it really depends, because you need a component to first trigger the query.

Let me know if you have any questions.

src/queries/myTrades.ts Outdated Show resolved Hide resolved
@evgenyboxer
Copy link
Contributor

@jwineman lgtm! awesome work! 👍 👍

I've invited @dvd-schwrtz to have a look as well (especially around the chart stuff, since he was the one implementing it)

@jwineman jwineman merged commit 1ea3e17 into Synthetixio:dev Sep 10, 2020
@jwineman jwineman deleted the jwineman/snx513 branch September 10, 2020 22:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants