-
Notifications
You must be signed in to change notification settings - Fork 142
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
feat: sync chains with url #398
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
5 Skipped Deployments
|
return useMemo(() => { | ||
const firstToken = warpCore.tokens[0]; | ||
const connectedToken = firstToken.connections?.[0]; | ||
|
||
if (!isReady) return null; |
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.
router needs to be ready before we can actually check if any of the URL queries are available, if this is not done, it will override the URL query using the fallback
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.
Just curious, why does it need to be ready? Does the URL not have the params in it regardless of the router status?
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.
Also what happens if you return the default values here instead of null (i.e. the ones that we use when the param isn't set)?
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.
removed dependency from next router and instead default to browser native URL handling
Deployment failed with the following error:
|
return useMemo(() => { | ||
const firstToken = warpCore.tokens[0]; | ||
const connectedToken = firstToken.connections?.[0]; | ||
|
||
if (!isReady) return null; |
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.
Just curious, why does it need to be ready? Does the URL not have the params in it regardless of the router status?
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.
Your general approach to solving the problem here is good but there IMO there are some subtle code smells here (see comments). These aren't obvious issues, just subtleties related to code quality and organization that may possibly hurt maintainability in the long run. But don't be discouraged. You'll naturally get better at nuances like naming, organization, and consistency with more experience.
src/consts/app.ts
Outdated
@@ -13,3 +13,9 @@ export const APP_URL = 'hyperlane-warp-template.vercel.app'; | |||
export const BRAND_COLOR = Color.primary['500']; | |||
export const BACKGROUND_COLOR = Color.primary['500']; | |||
export const BACKGROUND_IMAGE = 'url(/backgrounds/main.svg)'; | |||
|
|||
export enum WARP_QUERY_PARAMS { |
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.
Move this somewhere else. These are consts that we expect people to change to customize the app. Consts for core functionality should probably be somewhere else
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.
Moved under a new file inside const called core.ts
, I was debating to put it in common.ts
too, but felt like it didn't really match what the enum meant to do
/** | ||
* Check if given chainName has valid chain metadata and return chainName if chain is valid | ||
*/ | ||
export function getValidChain( |
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.
Your former isValidChain
was more clear IMO
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.
The reason for this change is that I want to make sure to get the chainName
or undefined
if the chain does not exist, instead of a boolean
, but I am happy to make adjustments if needed
handleSwapChain, | ||
}: { | ||
disabled?: boolean; | ||
handleSwapChain(origin: string, destination: string): void; |
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.
I don't see this syntax often. To clarify, is this equivalent to:
handleSwapChain: (origin: string, destination: string)=> void
?
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.
Also nit but I think onSwapChain
would be more consistent with the nomenclature we use elsewhere
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.
Kinda derped here, fixed
updateQueryParam(WARP_QUERY_PARAMS.ORIGIN, origin); | ||
updateQueryParam(WARP_QUERY_PARAMS.DESTINATION, destination); |
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.
For the TokenSelectField, you handle the query param setting in the component. But for these others, you're doing it in TransferTokenForm. Let's be consistent to keep code cohesion high
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.
Moved the logic inside TransferTokenForm for consistency
const handleChange = (chainName: string, fieldName: string) => { | ||
if (fieldName === 'origin') handleGetTokensRoute(chainName, values.destination); | ||
else handleGetTokensRoute(values.origin, chainName); | ||
updateQueryParam(fieldName, chainName); |
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.
You've already decided to make a separate WARP_QUERY_PARAMS
enum which defines the param name, but here you're assuming that fieldName === WARP_QUERY_PARAMS. If you can assume they're always the same, remove WARP_QUERY_PARAMS. If you can't, use WARP_QUERY_PARAMS
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.
done, did a check for fieldName === WARP_QUERY_PARAMS
@@ -449,17 +492,36 @@ function WarningBanners() { | |||
|
|||
function useFormInitialValues(): TransferFormValues { | |||
const warpCore = useWarpCore(); | |||
const parameters = new URLSearchParams(window.location.search); |
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.
Consider maybe moving the interactions with URLSearchParams to your query params file since you're already doing that with the update
function and it's better to be consistent. When you introduce a layer of abstraction, it's better to always use it as much as possible instead of creating two paths to the same thing.
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.
created a function called getQueryParams
for this, also use this function in the updateQueryParams
function
fixes #397