From 62cfbb7441e66156c55c76d73f5b481f5ea576bc Mon Sep 17 00:00:00 2001 From: MananTank Date: Tue, 7 Oct 2025 21:36:48 +0000 Subject: [PATCH] SDK: Show error in BuyWidget and SwapWidget UI if fetching token details fails (#8215) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR introduces error handling in the `BuyWidget` and `SwapWidget` UIs, displaying appropriate error messages when fetching token details fails. ### Detailed summary - Added `isError` state to handle errors in token fetching. - Updated `SelectedTokenButton` to check for errors before rendering. - Enhanced `SwapUI` to show error messages based on different query states. - Implemented error display in `FundWallet` for unsupported tokens. - Modified balance display logic to accommodate new error handling. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit - New Features - Inline error banners in Buy and Swap widgets when token details fail to load. - Clear, specific messages for quote, buy-token, and sell-token fetch failures. - Improvements - Selected token UI now falls back gracefully on errors instead of showing partial data. - Balance display uses richer token info (value, decimals, symbol, name) for accuracy. - More consistent handling of unsupported tokens across the flow. - Bug Fixes - Prevents stale token icons/details from appearing during error states. - Disables auto-retry on token price fetches to reduce UI flicker. --- .changeset/rare-buckets-fly.md | 5 +++ .../src/react/web/ui/Bridge/FundWallet.tsx | 40 +++++++++++++++---- .../Bridge/common/selected-token-button.tsx | 5 ++- .../web/ui/Bridge/swap-widget/swap-ui.tsx | 16 +++++++- 4 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 .changeset/rare-buckets-fly.md diff --git a/.changeset/rare-buckets-fly.md b/.changeset/rare-buckets-fly.md new file mode 100644 index 00000000000..997f2083019 --- /dev/null +++ b/.changeset/rare-buckets-fly.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Show error in BuyWidget and SwapWidget UI if fetching token details fails diff --git a/packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx b/packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx index f3489c637ae..c69b7bb6c1d 100644 --- a/packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx +++ b/packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx @@ -251,11 +251,14 @@ export function FundWallet(props: FundWalletProps) { ? tokenQuery.data.token : undefined, isFetching: tokenQuery.isFetching, + isError: + tokenQuery.isError || + tokenQuery.data?.type === "unsupported_token", } : undefined } balance={{ - data: tokenBalanceQuery.data?.value, + data: tokenBalanceQuery.data, isFetching: tokenBalanceQuery.isFetching, }} client={props.client} @@ -279,6 +282,22 @@ export function FundWallet(props: FundWalletProps) { + {(tokenQuery.isError || + tokenQuery.data?.type === "unsupported_token") && ( +
+ + Failed to fetch token details + +
+ )} + {/* Continue Button */} {activeWalletInfo ? (