Skip to content
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/rare-buckets-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Show error in BuyWidget and SwapWidget UI if fetching token details fails
40 changes: 33 additions & 7 deletions packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,14 @@
? tokenQuery.data.token
: undefined,
isFetching: tokenQuery.isFetching,
isError:
tokenQuery.isError ||
tokenQuery.data?.type === "unsupported_token",

Check warning on line 256 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L254-L256

Added lines #L254 - L256 were not covered by tests
}
: undefined
}
balance={{
data: tokenBalanceQuery.data?.value,
data: tokenBalanceQuery.data,

Check warning on line 261 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L261

Added line #L261 was not covered by tests
isFetching: tokenBalanceQuery.isFetching,
}}
client={props.client}
Expand All @@ -279,6 +282,22 @@

<Spacer y="md" />

{(tokenQuery.isError ||
tokenQuery.data?.type === "unsupported_token") && (
<div
style={{
border: `1px solid ${theme.colors.borderColor}`,
borderRadius: radius.full,
padding: spacing.xs,
marginBottom: spacing.md,
}}

Check warning on line 293 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L285-L293

Added lines #L285 - L293 were not covered by tests
>
<Text size="sm" color="danger" center>

Check warning on line 295 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L295

Added line #L295 was not covered by tests
Failed to fetch token details
</Text>
</div>

Check warning on line 298 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L297-L298

Added lines #L297 - L298 were not covered by tests
)}

{/* Continue Button */}
{activeWalletInfo ? (
<Button
Expand Down Expand Up @@ -373,6 +392,7 @@
| {
data: TokenWithPrices | undefined;
isFetching: boolean;
isError: boolean;
}
| undefined;
currency: SupportedFiatCurrency;
Expand All @@ -381,7 +401,14 @@
title: string;
isConnected: boolean;
balance: {
data: bigint | undefined;
data:
| {
value: bigint;
decimals: number;
symbol: string;
name: string;
}
| undefined;
isFetching: boolean;
};
onWalletClick: () => void;
Expand Down Expand Up @@ -565,17 +592,16 @@
<Text size="xs" color="secondaryText">
Current Balance
</Text>
{props.balance.data === undefined ||
props.selectedToken.data === undefined ? (
{props.balance.data === undefined ? (

Check warning on line 595 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L595

Added line #L595 was not covered by tests
<Skeleton height={fontSize.xs} width="100px" />
) : (
<Text size="xs" color="primaryText">
{formatTokenAmount(
props.balance.data,
props.selectedToken.data.decimals,
props.balance.data.value,
props.balance.data.decimals,

Check warning on line 601 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L600-L601

Added lines #L600 - L601 were not covered by tests
5,
)}{" "}
{props.selectedToken.data.symbol}
{props.balance.data.symbol}

Check warning on line 604 in packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/FundWallet.tsx#L604

Added line #L604 was not covered by tests
</Text>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
| {
data: TokenWithPrices | undefined;
isFetching: boolean;
isError: boolean;
}
| undefined;
client: ThirdwebClient;
Expand All @@ -47,7 +48,7 @@
{/* icons */}
<Container relative color="secondaryText">
{/* token icon */}
{props.selectedToken ? (
{props.selectedToken && !props.selectedToken.isError ? (

Check warning on line 51 in packages/thirdweb/src/react/web/ui/Bridge/common/selected-token-button.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/common/selected-token-button.tsx#L51

Added line #L51 was not covered by tests
<Img
key={props.selectedToken?.data?.iconUri}
src={
Expand Down Expand Up @@ -112,7 +113,7 @@
</Container>

{/* token symbol and chain name */}
{props.selectedToken ? (
{props.selectedToken && !props.selectedToken.isError ? (

Check warning on line 116 in packages/thirdweb/src/react/web/ui/Bridge/common/selected-token-button.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/Bridge/common/selected-token-button.tsx#L116

Added line #L116 was not covered by tests
<Container flex="column" style={{ gap: "3px" }}>
{props.selectedToken?.isFetching ? (
<Skeleton width="60px" height={fontSize.md} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function useTokenPrice(options: {
);
},
refetchOnMount: false,
retry: false,
refetchOnWindowFocus: false,
});
}
Expand Down Expand Up @@ -320,6 +321,7 @@ export function SwapUI(props: SwapUIProps) {
? {
data: sellTokenQuery.data,
isFetching: sellTokenQuery.isFetching,
isError: sellTokenQuery.isError,
}
: undefined
}
Expand Down Expand Up @@ -372,6 +374,7 @@ export function SwapUI(props: SwapUIProps) {
? {
data: buyTokenQuery.data,
isFetching: buyTokenQuery.isFetching,
isError: buyTokenQuery.isError,
}
: undefined
}
Expand All @@ -389,7 +392,9 @@ export function SwapUI(props: SwapUIProps) {
/>

{/* error message */}
{preparedResultQuery.error ? (
{preparedResultQuery.error ||
buyTokenQuery.isError ||
sellTokenQuery.isError ? (
<Text
size="sm"
color="danger"
Expand All @@ -398,7 +403,13 @@ export function SwapUI(props: SwapUIProps) {
paddingBlock: spacing.md,
}}
>
Failed to get a quote
{preparedResultQuery.error
? "Failed to get a quote"
: buyTokenQuery.isError
? "Failed to fetch buy token details"
: sellTokenQuery.isError
? "Failed to fetch sell token details"
: "Failed to get a quote"}
</Text>
) : (
<Spacer y="md" />
Expand Down Expand Up @@ -626,6 +637,7 @@ function TokenSection(props: {
| {
data: TokenWithPrices | undefined;
isFetching: boolean;
isError: boolean;
}
| undefined;
currency: SupportedFiatCurrency;
Expand Down
Loading