Skip to content

[SDK] Feature: Remove Switch Network button #7191

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

Merged
merged 1 commit into from
May 29, 2025

Conversation

gregfromstl
Copy link
Member

@gregfromstl gregfromstl commented May 29, 2025


PR-Codex overview

This PR focuses on improving the SwapScreenContent component by removing the unnecessary SwitchNetworkButton, streamlining the code and enhancing the user experience during the token swap process.

Detailed summary

  • Removed the import of SwitchNetworkButton from the component.
  • Eliminated the conditional rendering of SwitchNetworkButton.
  • Added a check for the current chain before invoking switchChain within the button click handler.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Improved the swap flow by automatically switching networks when needed, streamlining the process for users.
  • Refactor

    • Removed the redundant "Switch Network" button from the payment and swap interfaces, resulting in a cleaner and simpler user experience.

@gregfromstl gregfromstl requested review from a team as code owners May 29, 2025 00:29
Copy link

changeset-bot bot commented May 29, 2025

🦋 Changeset detected

Latest commit: 7303d90

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented May 29, 2025

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

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:41am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:41am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:41am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:41am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2025 0:41am

Copy link
Contributor

graphite-app bot commented May 29, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Contributor

coderabbitai bot commented May 29, 2025

Walkthrough

The changes remove the "Switch Network" button from the PayEmbed feature in the "thirdweb" component. The logic for switching networks, previously handled by a separate button, is now integrated into the main "Continue" button's flow, streamlining the user interface and consolidating the network-switching process.

Changes

File(s) Change Summary
.changeset/tricky-points-tease.md Added a changeset describing the removal of the "Switch Network" button from PayEmbed.
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx Removed SwitchNetworkButton import and usage; moved network switch logic into "Continue" button.

Suggested labels

packages, SDK

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels May 29, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx (1)

320-356: 🛠️ Refactor suggestion

Consider adding loading state during chain switching.

The Continue button doesn't provide visual feedback during the chain switching operation, which could leave users confused about what's happening, especially if the wallet prompts for network switching approval.

Consider adding a loading state for better UX:

+ const [isSwitchingChain, setIsSwitchingChain] = useState(false);

  <Button
    variant={disableContinue ? "outline" : "accent"}
    fullWidth
    data-disabled={disableContinue}
-   disabled={disableContinue}
+   disabled={disableContinue || isSwitchingChain}
    onClick={async () => {
      if (!disableContinue) {
        if (props.payer.wallet.getChain()?.id !== fromChain?.id) {
+         setIsSwitchingChain(true);
          try {
            await props.payer.wallet.switchChain(fromChain);
          } catch (error) {
            console.error("Failed to switch network:", error);
            return;
          } finally {
+           setIsSwitchingChain(false);
          }
        }
        showSwapFlow();
        // ... rest of the logic
      }
    }}
    gap="xs"
  >
-   {quoteQuery.isLoading ? (
+   {quoteQuery.isLoading || isSwitchingChain ? (
      <>
-       Getting price quote
+       {isSwitchingChain ? "Switching network..." : "Getting price quote"}
        <Spinner size="sm" />
      </>
    ) : (
      "Continue"
    )}
  </Button>
🧹 Nitpick comments (1)
.changeset/tricky-points-tease.md (1)

5-5: Consider minor grammatical improvement (optional).

The changeset description accurately captures the change. The static analysis tool suggests adding "the" before "PayEmbed" for better grammar, though the current phrasing is commonly used in changelog entries.

Optional improvement:

- Remove unnecessary Switch Network button in PayEmbed
+ Remove unnecessary Switch Network button in the PayEmbed
🧰 Tools
🪛 LanguageTool

[uncategorized] ~5-~5: You might be missing the article “the” here.
Context: --- "thirdweb": patch --- Remove unnecessary Switch Network button in PayEmbed

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0731831 and 7303d90.

📒 Files selected for processing (2)
  • .changeset/tricky-points-tease.md (1 hunks)
  • packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/tricky-points-tease.md

[uncategorized] ~5-~5: You might be missing the article “the” here.
Context: --- "thirdweb": patch --- Remove unnecessary Switch Network button in PayEmbed

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Build Packages
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Unit Tests
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx (1)

325-344: Approve the consolidation of network switching logic.

The integration of network switching directly into the Continue button's flow is a good UX improvement that eliminates the need for a separate "Switch Network" button. This streamlines the user experience by reducing the number of steps required.

.changeset/tricky-points-tease.md (1)

1-5: Changeset accurately documents the changes.

The changeset properly categorizes this as a patch update and provides a clear, concise description of the removed functionality.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~5-~5: You might be missing the article “the” here.
Context: --- "thirdweb": patch --- Remove unnecessary Switch Network button in PayEmbed

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

Comment on lines +327 to +329
if (props.payer.wallet.getChain()?.id !== fromChain?.id) {
await props.payer.wallet.switchChain(fromChain);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for the chain switching operation.

The network switching logic is correctly integrated into the Continue button, but the switchChain operation lacks error handling. If the chain switch fails (e.g., user rejects the request, RPC issues), it will throw an unhandled exception that could crash the component.

Consider adding error handling and user feedback:

  onClick={async () => {
    if (!disableContinue) {
      if (props.payer.wallet.getChain()?.id !== fromChain?.id) {
-       await props.payer.wallet.switchChain(fromChain);
+       try {
+         await props.payer.wallet.switchChain(fromChain);
+       } catch (error) {
+         console.error("Failed to switch network:", error);
+         // Consider showing an error message to the user
+         return;
+       }
      }
      showSwapFlow();
      // ... rest of the logic
    }
  }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (props.payer.wallet.getChain()?.id !== fromChain?.id) {
await props.payer.wallet.switchChain(fromChain);
}
onClick={async () => {
if (!disableContinue) {
if (props.payer.wallet.getChain()?.id !== fromChain?.id) {
try {
await props.payer.wallet.switchChain(fromChain);
} catch (error) {
console.error("Failed to switch network:", error);
// Consider showing an error message to the user
return;
}
}
showSwapFlow();
// ... rest of the logic
}
}}
🤖 Prompt for AI Agents
In
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx
around lines 327 to 329, the call to switchChain lacks error handling, which can
cause unhandled exceptions if the chain switch fails. Wrap the switchChain call
in a try-catch block to catch any errors, handle them gracefully, and provide
user feedback such as an error message or notification to inform the user about
the failure.

Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 61.7 KB (0%) 1.3 s (0%) 274 ms (+132.99% 🔺) 1.6 s
thirdweb (cjs) 344.53 KB (0%) 6.9 s (0%) 928 ms (+0.26% 🔺) 7.9 s
thirdweb (minimal + tree-shaking) 5.69 KB (0%) 114 ms (0%) 83 ms (+1039.31% 🔺) 196 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 22 ms (+280.79% 🔺) 32 ms
thirdweb/react (minimal + tree-shaking) 19.54 KB (0%) 391 ms (0%) 140 ms (+675.35% 🔺) 531 ms

Copy link

codecov bot commented May 29, 2025

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 55.67%. Comparing base (0731831) to head (7303d90).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...nnectWallet/screens/Buy/swap/SwapScreenContent.tsx 0.00% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7191      +/-   ##
==========================================
+ Coverage   55.66%   55.67%   +0.01%     
==========================================
  Files         904      904              
  Lines       58404    58391      -13     
  Branches     4118     4119       +1     
==========================================
- Hits        32511    32510       -1     
+ Misses      25788    25776      -12     
  Partials      105      105              
Flag Coverage Δ
packages 55.67% <0.00%> (+0.01%) ⬆️
Files with missing lines Coverage Δ
...nnectWallet/screens/Buy/swap/SwapScreenContent.tsx 7.97% <0.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gregfromstl gregfromstl merged commit 44a7460 into main May 29, 2025
24 of 25 checks passed
@gregfromstl gregfromstl deleted the greg/switch-network-button branch May 29, 2025 00:45
@joaquim-verges joaquim-verges mentioned this pull request May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant