Skip to content

[READY] Fix URL Params#1065

Open
Sharqiewicz wants to merge 6 commits intostagingfrom
fix/params
Open

[READY] Fix URL Params#1065
Sharqiewicz wants to merge 6 commits intostagingfrom
fix/params

Conversation

@Sharqiewicz
Copy link
Member

@Sharqiewicz Sharqiewicz commented Feb 12, 2026

We could create a zustand store for storing the tokens data but we need the data also in the apps/api for the getTokenUSDPrice. That's why we use an object to store the data and useSyncExternalStore on the frontend to reactively subscribe to it.

@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for vortex-sandbox ready!

Name Link
🔨 Latest commit f908533
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/698f5877ce5f35000800c71c
😎 Deploy Preview https://deploy-preview-1065--vortex-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for vortexfi ready!

Name Link
🔨 Latest commit f908533
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/698f58777eba9d000811dc44
😎 Deploy Preview https://deploy-preview-1065--vortexfi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Sharqiewicz Sharqiewicz requested a review from ebma February 12, 2026 14:13
@Sharqiewicz Sharqiewicz changed the title wip [READY] Fix URL Params Feb 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates ramp URL/search-param handling to better support dynamically loaded EVM tokens (e.g., WETH/WBTC) by making the frontend react to the “dynamic tokens loaded” state, and loosens route search validation to accept a wider range of URL values.

Changes:

  • Added an external-store style subscription API in shared dynamic EVM token state to support React useSyncExternalStore.
  • Updated useRampUrlParams to re-evaluate cryptoLocked once dynamic EVM tokens finish loading and apply the token to the quote form store.
  • Relaxed TanStack Router search-param schema for paymentMethod/rampType from enum validation to plain strings.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
packages/shared/src/tokens/evm/dynamicEvmTokens.ts Adds listeners + snapshot/subscribe helpers and notifies subscribers when token loading completes.
apps/frontend/src/types/searchParams.ts Adjusts route search schema to accept string params for paymentMethod and rampType.
apps/frontend/src/hooks/useRampUrlParams.ts Subscribes to dynamic token loaded state and re-applies cryptoLocked after token config becomes available.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 84 to 90
if (isNetworkEVM(networkType as Networks)) {
const dynamicConfig = getEvmTokenConfig();
const networkTokens = dynamicConfig[networkType as EvmNetworks];
if (networkTokens && tokenStr in networkTokens) {
return tokenStr as OnChainToken;
}
}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

findOnChainToken returns tokenStr as OnChainToken for dynamically loaded EVM tokens (e.g. WETH/WBTC), but OnChainToken is currently EvmToken | AssetHubToken in shared, so this cast makes the type inaccurate and can hide downstream logic errors. Consider widening the type used for URL params/store state (e.g. string token symbol) or updating the shared token types to represent dynamic EVM symbols explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines 22 to 27
network: z.string().optional(),
partnerId: z.string().optional(),
paymentMethod: z.nativeEnum(EPaymentMethod).optional().catch(undefined),
paymentMethod: z.string().optional(),
quoteId: z.string().optional(),
rampType: z.nativeEnum(RampDirection).optional().catch(undefined),
rampType: z.string().optional(),
walletAddressLocked: z.string().optional()
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Changing paymentMethod and rampType to z.string() removes validation/normalization. This can cause invalid values (e.g. rampType=foo) to be treated as “present” and make hasAllQuoteRefreshParams skip the quote form incorrectly. Keep schema validation but make it case-insensitive (e.g., preprocess to upper/lower then z.nativeEnum(...).optional().catch(undefined)).

Copilot uses AI. Check for mistakes.
Comment on lines 299 to 307
for (const listener of evmTokenListeners) listener();
} catch (err) {
console.error("[DynamicEvmTokens] Failed to fetch tokens from SquidRouter, using fallback:", err);

state.tokensByNetwork = buildFallbackFromStaticConfig();
state.priceBySymbol = buildPriceLookup(state.tokensByNetwork);
state.isLoaded = true;
for (const listener of evmTokenListeners) listener();
}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

Calling listeners inside the try block means any exception thrown by a subscriber will be caught by this try/catch and incorrectly trigger the fallback path, overwriting successfully fetched token data. Wrap listener invocations so subscriber errors can’t affect initialization (e.g., notify in a separate try/finally or catch per-listener).

Suggested change
for (const listener of evmTokenListeners) listener();
} catch (err) {
console.error("[DynamicEvmTokens] Failed to fetch tokens from SquidRouter, using fallback:", err);
state.tokensByNetwork = buildFallbackFromStaticConfig();
state.priceBySymbol = buildPriceLookup(state.tokensByNetwork);
state.isLoaded = true;
for (const listener of evmTokenListeners) listener();
}
} catch (err) {
console.error("[DynamicEvmTokens] Failed to fetch tokens from SquidRouter, using fallback:", err);
state.tokensByNetwork = buildFallbackFromStaticConfig();
state.priceBySymbol = buildPriceLookup(state.tokensByNetwork);
state.isLoaded = true;
}
for (const listener of evmTokenListeners) {
try {
listener();
} catch (listenerErr) {
logger.error("[DynamicEvmTokens] Error in EVM token listener", listenerErr);
}
}

Copilot uses AI. Check for mistakes.
Comment on lines 303 to 307
state.tokensByNetwork = buildFallbackFromStaticConfig();
state.priceBySymbol = buildPriceLookup(state.tokensByNetwork);
state.isLoaded = true;
for (const listener of evmTokenListeners) listener();
}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

In the fallback path, if any listener throws here it will cause initializeEvmTokens() to reject and prevent other listeners from being notified. Consider isolating notifications (catch per-listener) so one bad subscriber can’t break initialization.

Copilot uses AI. Check for mistakes.
Comment on lines 208 to 214
return {
apiKey: apiKeyParam || undefined,
callbackUrl: callbackUrlParam || undefined,
countryCode: countryCodeParam || undefined,
cryptoLocked,
evmTokensLoaded,
externalSessionId: externalSessionIdParam || undefined,
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

useRampUrlParams is declared to return RampUrlParams, but the returned object includes evmTokensLoaded, which is not part of the RampUrlParams interface. This will fail excess-property checks; either add evmTokensLoaded to the interface (if it’s intentionally part of the public shape) or don’t include it in the returned object and only use it as a dependency to force recomputation.

Copilot uses AI. Check for mistakes.
try {
listener();
} catch (listenerErr) {
console.error("[DynamicEvmTokens] Error in EVM token listener", listenerErr);
Copy link
Member

Choose a reason for hiding this comment

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

Nice. Just one final nitpick: Let's use our logger instance so that these logs are automatically formatted etc. Please replace the console.error calls with logger.current.error and import the logger instance from logger.ts.

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.

2 participants