Skip to content

fix params to anyspend modal#386

Open
aqt-dev wants to merge 1 commit intomainfrom
fix-params-to-anyspend-modal
Open

fix params to anyspend modal#386
aqt-dev wants to merge 1 commit intomainfrom
fix-params-to-anyspend-modal

Conversation

@aqt-dev
Copy link
Contributor

@aqt-dev aqt-dev commented Dec 9, 2025

Summary

This PR enhances the AnySpend component by improving the handling of URL parameters for chain and token selection, ensuring that the application state correctly reflects the parameters provided in the URL.

Changes

• Added logic to synchronize destination chain and token from URL parameters, improving state management during server-side rendering (SSR) hydration.
• Implemented synchronization for source chain and token based on URL parameters, ensuring accurate token selection.

@aqt-dev aqt-dev requested a review from a team as a code owner December 9, 2025 22:43
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @aqt-dev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the AnySpend component by enhancing its ability to parse and apply URL parameters for chain and token selections. The changes ensure that the application's internal state for both source and destination chains and tokens is correctly initialized and synchronized with the URL, particularly improving the user experience during server-side rendering hydration by preventing state mismatches.

Highlights

  • URL Parameter Synchronization for Destination Chain/Token: Implemented logic to synchronize the destination chain and token from URL parameters ("toChainId", "toCurrency"), specifically addressing state management during server-side rendering (SSR) hydration.
  • URL Parameter Synchronization for Source Chain/Token: Added logic to synchronize the source chain and token from URL parameters ("fromChainId", "fromCurrency"), ensuring accurate token selection based on the URL.
  • Dependency Array Update: Updated the dependency array of the useEffect hook to include isBuyMode, selectedDstChainId, and selectedSrcChainId for proper re-evaluation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the handling of URL parameters for chain and token selection in the AnySpend component. The added logic for synchronizing state after SSR hydration is a good enhancement. However, I've identified a couple of issues in the implementation where the token selection logic is not fully robust. It currently fails to handle non-default tokens specified in the URL and doesn't update the token if the chain remains the same. My review includes suggestions to fix these issues to ensure the component state always reflects the URL parameters correctly.

Comment on lines +340 to +355
const urlDstChainId = parseInt(toChainIdParam);
if (urlDstChainId && urlDstChainId !== selectedDstChainId) {
setSelectedDstChainId(urlDstChainId);

// Get the default token for this chain
const chainDefaultToken = getDefaultToken(urlDstChainId);

// If URL currency matches the default token address (like zero address for native tokens),
// use the full default token with all metadata
if (
toCurrencyParam &&
toCurrencyParam.toLowerCase() === chainDefaultToken.address.toLowerCase()
) {
setSelectedDstToken(chainDefaultToken);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current logic for synchronizing the destination token doesn't handle cases where a non-default token is specified in the URL, or when the token changes but the chain ID remains the same. This can lead to an inconsistent UI state that doesn't match the URL parameters. The suggested change ensures that any token specified in toCurrency is correctly set, and also handles token changes on the same chain.

        const urlDstChainId = parseInt(toChainIdParam);
        if (urlDstChainId) {
          const urlTokenAddress = toCurrencyParam?.toLowerCase();
          const stateTokenAddress = selectedDstToken.address.toLowerCase();

          if (urlDstChainId !== selectedDstChainId || (urlTokenAddress && urlTokenAddress !== stateTokenAddress)) {
            if (urlDstChainId !== selectedDstChainId) {
              setSelectedDstChainId(urlDstChainId);
            }

            if (toCurrencyParam) {
              setSelectedDstToken({
                chainId: urlDstChainId,
                address: toCurrencyParam,
                symbol: "",
                name: "",
                decimals: 18, // Default, will be updated by useTokenData
                metadata: {},
              });
            } else {
              setSelectedDstToken(getDefaultToken(urlDstChainId));
            }
          }
        }

Comment on lines +363 to +377
const urlSrcChainId = parseInt(fromChainIdParam);
if (urlSrcChainId && urlSrcChainId !== selectedSrcChainId) {
setSelectedSrcChainId(urlSrcChainId);

// Get the default token for this chain
const chainDefaultToken = getDefaultToken(urlSrcChainId);

// If URL currency matches the default token address, use the full default token
if (
fromCurrencyParam &&
fromCurrencyParam.toLowerCase() === chainDefaultToken.address.toLowerCase()
) {
setSelectedSrcToken(chainDefaultToken);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Similar to the destination token logic, the source token synchronization is also not fully robust. It fails to update the source token if it's not the default for the chain, or if only the token (and not the chain) changes in the URL. This fix ensures the source token state is always correctly synchronized with the fromCurrency URL parameter.

        const urlSrcChainId = parseInt(fromChainIdParam);
        if (urlSrcChainId) {
          const urlTokenAddress = fromCurrencyParam?.toLowerCase();
          const stateTokenAddress = selectedSrcToken.address.toLowerCase();

          if (urlSrcChainId !== selectedSrcChainId || (urlTokenAddress && urlTokenAddress !== stateTokenAddress)) {
            if (urlSrcChainId !== selectedSrcChainId) {
              setSelectedSrcChainId(urlSrcChainId);
            }

            if (fromCurrencyParam) {
              setSelectedSrcToken({
                chainId: urlSrcChainId,
                address: fromCurrencyParam,
                symbol: "",
                name: "",
                decimals: 18, // Default, will be updated by useTokenData
                metadata: {},
              });
            } else {
              setSelectedSrcToken(getDefaultToken(urlSrcChainId));
            }
          }
        }

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.

1 participant