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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-points-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Remove unnecessary Switch Network button in PayEmbed
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
} from "../../../../components/Drawer.js";
import { Spacer } from "../../../../components/Spacer.js";
import { Spinner } from "../../../../components/Spinner.js";
import { SwitchNetworkButton } from "../../../../components/SwitchNetwork.js";
import { Container } from "../../../../components/basic.js";
import { Button } from "../../../../components/buttons.js";
import { Text } from "../../../../components/text.js";
Expand Down Expand Up @@ -171,8 +170,6 @@
(swapRequired && !quoteQuery.data) ||
isNotEnoughBalance ||
allowanceQuery.isLoading;
const switchChainRequired =
props.payer.wallet.getChain()?.id !== fromChain?.id;

const errorMsg =
!quoteQuery.isLoading && quoteQuery.error
Expand Down Expand Up @@ -319,19 +316,6 @@
>
Pay with another token
</Button>
) : switchChainRequired &&
fromChain &&
!quoteQuery.isLoading &&
!allowanceQuery.isLoading &&
!isNotEnoughBalance &&
!quoteQuery.error ? (
<SwitchNetworkButton
variant="accent"
fullWidth
switchChain={async () => {
await props.payer.wallet.switchChain(fromChain);
}}
/>
) : (
<Button
variant={disableContinue ? "outline" : "accent"}
Expand All @@ -340,6 +324,9 @@
disabled={disableContinue}
onClick={async () => {
if (!disableContinue) {
if (props.payer.wallet.getChain()?.id !== fromChain?.id) {
await props.payer.wallet.switchChain(fromChain);
}

Check warning on line 329 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapScreenContent.tsx#L327-L329

Added lines #L327 - L329 were not covered by tests
Comment on lines +327 to +329
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.

showSwapFlow();
trackPayEvent({
event: "confirm_swap_quote",
Expand Down
Loading