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/eager-loops-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Token Selection UX improvements in SwapWidget
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { Buy, Sell } from "../../../../../bridge/index.js";
import type { prepare as SellPrepare } from "../../../../../bridge/Sell.js";
import type { TokenWithPrices } from "../../../../../bridge/types/Token.js";
import type { ThirdwebClient } from "../../../../../client/client.js";
import { NATIVE_TOKEN_ADDRESS } from "../../../../../constants/addresses.js";
import { getToken } from "../../../../../pay/convert/get-token.js";
import type { SupportedFiatCurrency } from "../../../../../pay/convert/type.js";
import { getAddress } from "../../../../../utils/address.js";
import { toTokens, toUnits } from "../../../../../utils/units.js";
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
import {
Expand Down Expand Up @@ -245,6 +247,18 @@ export function SwapUI(props: SwapUIProps) {
) {
props.setSellToken(undefined);
}

// if sell token is not selected, set it as native token of the buy token's chain if buy token is not a native token itself
if (
!props.sellToken &&
token.tokenAddress.toLowerCase() !==
NATIVE_TOKEN_ADDRESS.toLowerCase()
) {
props.setSellToken({
tokenAddress: getAddress(NATIVE_TOKEN_ADDRESS),
chainId: token.chainId,
});
}
}}
/>
)}
Expand All @@ -270,6 +284,18 @@ export function SwapUI(props: SwapUIProps) {
) {
props.setBuyToken(undefined);
}

// if buy token is not selected, set it as native token of the sell token's chain if sell token is not a native token itself
if (
!props.buyToken &&
token.tokenAddress.toLowerCase() !==
NATIVE_TOKEN_ADDRESS.toLowerCase()
) {
props.setBuyToken({
tokenAddress: getAddress(NATIVE_TOKEN_ADDRESS),
chainId: token.chainId,
});
}
}}
activeWalletInfo={props.activeWalletInfo}
/>
Expand Down
Loading