Skip to content
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

fix: stricter typing for router query #548

Merged
merged 3 commits into from
Mar 10, 2023
Merged

fix: stricter typing for router query #548

merged 3 commits into from
Mar 10, 2023

Conversation

zzmp
Copy link
Contributor

@zzmp zzmp commented Mar 10, 2023

Narrows typings for router queries, which avoids having to coerce types in useRouterTrade.
This will enable cleaner code for a planned perf event hook (see #549).

Also uncovers and fixes a bug for swaps with no quote (QuoteState.NOT_FOUND), which do not include a blockNumber but should still be rendered.

@zzmp zzmp requested review from tinaszheng, a team and cartcrom and removed request for a team March 10, 2023 01:55
@vercel
Copy link

vercel bot commented Mar 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
widgets ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 10, 2023 at 11:54PM (UTC)

@vercel vercel bot temporarily deployed to Preview March 10, 2023 02:00 Inactive
src/state/routing/types.ts Show resolved Hide resolved
@@ -111,13 +111,13 @@ async function getQuote(
const amount = CurrencyAmount.fromRawAmount(baseCurrency, JSBI.BigInt(amountRaw ?? '1')) // a null amountRaw should initialize the route
const route = await router.route(amount, quoteCurrency, tradeType, /*swapConfig=*/ undefined, routerConfig)

if (!amountRaw) return INITIALIZED
if (!route) return NO_ROUTE
if (!amountRaw) return { state: QuoteState.INITIALIZED }
Copy link
Contributor

Choose a reason for hiding this comment

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

when does this case happen? shouldn't this be part of the skipToken case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the slow part of CSSOR is initialization - that first time a token pair is checked. but it's not even getting the quote, it's initializing the data to get the quote.
so as soon as we have a pair, we make a query with a null amount, signifying that it's just an initialization. the client-side code will replace null with 1 so that it fetches the necessary initializing data, and then return QuoteState.INITIALIZED.
then, when we make a real query, it's nearly instant!

Copy link
Contributor

Choose a reason for hiding this comment

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

🤦‍♀️ oy VEY!

@zzmp zzmp merged commit ee653ee into main Mar 10, 2023
@zzmp zzmp deleted the query-typing branch March 10, 2023 23:50
@vercel vercel bot temporarily deployed to Preview March 10, 2023 23:54 Inactive
@github-actions
Copy link

🎉 This PR is included in version 2.47.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants