Skip to content

Conversation

0xAlunara
Copy link
Collaborator

@0xAlunara 0xAlunara commented Sep 24, 2025

Preparation work for future useMintMarket hook, which will replace the mint market collateral Zustand store which in turn is needed to add support for unified support for addresses in URL.

  • Rename 'useOneWayMarket' stuff to 'useLendMarket'
  • Simplify the mapping creation, add some docs as well
  • Remove unnecessary usage of hydratedChainId.
  • useLendMarkets is no more. There's only a useLendMarketMapping, which maps lend market controller addresses to the lend market ids. This hook is used internally for useLendMarket, and also useTvl. It is knows that useTvl could use prices API instead, but that's out of the scope of this ticket and I want to keep it small; that's for later.
  • I've tried solving some of the routing issues where if you click "Supply" it routs the URL to the version with the lend market. This, however, opened a can of worms outside of the scope of this ticket. It seems to work even though it's inconsistent. I'm keeping that as it for for later to deal with

Because there's so many pages and redirects already I've also not added redirecting from market id names to controller names yet

Copy link

vercel bot commented Sep 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
curve-dapp Ready Ready Preview Comment Sep 24, 2025 5:51pm
curve-dapp-storybook Ready Ready Preview Comment Sep 24, 2025 5:51pm

pilotvietnam
pilotvietnam previously approved these changes Sep 24, 2025
@0xAlunara 0xAlunara marked this pull request as draft September 24, 2025 17:41
@0xAlunara 0xAlunara marked this pull request as ready for review September 24, 2025 17:50
Comment on lines +26 to +27
// eslint-disable-next-line react-hooks/exhaustive-deps
[api?.hydrated, chainId],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please never disable this rule, it's always a bug waiting to happen

Suggested change
// eslint-disable-next-line react-hooks/exhaustive-deps
[api?.hydrated, chainId],
[api, api?.hydrated, chainId],

return useMemo(() => {
if (!api) return undefined

// If markets aren't found they throw an error, but we want to return undefined instead
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't do this, ignoring errors is bad. Why are we trying to retrieve a market if it's not found?
If the API is hydrated it should never throw an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because somebody might enter gibberish into the URL?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd argue that should crash the page with an error (or give a proper 404), instead of being ignored which could lead to the page being left in loading state.

api.lendMarkets
.getMarketList()
.filter((marketName) => !networks[chainId].hideMarketsInUI[marketName])
.map((name) => [api.getLendMarket(name).addresses.controller as Address, name]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The only reason we created the mapping like this was because we wanted to use a query.
If this is a normal hook, there is no reason to return the name only, we might as well return the class instance

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not a query, though? We only need the mapping for redirecting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could not reliably add the hydration validation in the query, reactivity for api.hydrated is wonky. But a hook with useMemo and api?.hydrated seemed to work, although you said it's still wonky in some way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah we need to properly use the state machine from React. Currently it works only when it re-renders for some other reasons. Changing a field of an object is not supported

push(getCollateralListPathname(params))
}
}, [isSuccess, market, params, push, rMarket])
}, [api?.hydrated, market, params, push, rMarket])
Copy link
Collaborator

Choose a reason for hiding this comment

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

this effect isn't triggered properly 😿
if you visit a market that doesn't exist, the hydration finishes but the redirect takes an unspecified amount of time to happen (when the page is re-rendered for some other reason)

@0xAlunara
Copy link
Collaborator Author

Might put this PR back to draft until hydration issues are better resolved

@0xAlunara 0xAlunara marked this pull request as draft September 26, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants