Skip to content

Commit a3ff757

Browse files
committed
[MNY-319] SDK: Add token details screen in token selection UI (#8608)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the token selection UI by adding a token details screen and improving the display of token information within the `SwapWidget` and `BridgeWidget`. ### Detailed summary - Added a token details screen in the token selection UI. - Enhanced the `SelectedTokenButton` to include a more flexible display of the token symbol. - Introduced `useTokenPrice` hook for fetching token prices. - Updated `TokenButton` to include an info button for showing token details. - Created `TokenInfoScreen` and `TokenInfoRow` components for displaying detailed token information. - Integrated token info functionality into `TokenSelectionScreen`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 01004e8 commit a3ff757

File tree

8 files changed

+380
-47
lines changed

8 files changed

+380
-47
lines changed

.changeset/two-pandas-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Add token details screen in token selection UI in SwapWidget, BridgeWidget

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export function FundWallet(props: FundWalletProps) {
213213
>
214214
<SelectToken
215215
type="buy"
216+
currency={props.currency}
216217
selections={{
217218
buyChainId: props.selectedToken?.chainId,
218219
sellChainId: undefined,

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,15 @@ export function SelectedTokenButton(props: {
128128
{props.selectedToken?.isFetching ? (
129129
<Skeleton width="60px" height={fontSize.md} />
130130
) : (
131-
<Text size="md" color="primaryText" weight={500}>
131+
<Text
132+
size="md"
133+
color="primaryText"
134+
weight={500}
135+
style={{
136+
whiteSpace: "nowrap",
137+
maxWidth: "200px",
138+
}}
139+
>
132140
{props.selectedToken?.data?.symbol}
133141
</Text>
134142
)}
@@ -138,8 +146,6 @@ export function SelectedTokenButton(props: {
138146
size="xs"
139147
color="secondaryText"
140148
style={{
141-
overflow: "hidden",
142-
textOverflow: "ellipsis",
143149
whiteSpace: "nowrap",
144150
}}
145151
>

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/hooks.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { useQuery } from "@tanstack/react-query";
12
import { useMemo } from "react";
3+
import type { ThirdwebClient } from "../../../../../client/client.js";
4+
import { getToken } from "../../../../../pay/convert/get-token.js";
25
import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
36
import { useActiveAccount } from "../../../../core/hooks/wallets/useActiveAccount.js";
47
import { useActiveWallet } from "../../../../core/hooks/wallets/useActiveWallet.js";
58
import { useActiveWalletChain } from "../../../../core/hooks/wallets/useActiveWalletChain.js";
6-
import type { ActiveWalletInfo } from "./types.js";
9+
import type { ActiveWalletInfo, TokenSelection } from "./types.js";
710

811
export function useActiveWalletInfo(
912
activeWalletOverride?: Wallet,
@@ -25,3 +28,26 @@ export function useActiveWalletInfo(
2528
: undefined;
2629
}, [activeAccount, activeWallet, activeChain, activeWalletOverride]);
2730
}
31+
32+
export function useTokenPrice(options: {
33+
token: TokenSelection | undefined;
34+
client: ThirdwebClient;
35+
}) {
36+
return useQuery({
37+
queryKey: ["token-price", options.token],
38+
enabled: !!options.token,
39+
queryFn: () => {
40+
if (!options.token) {
41+
throw new Error("Token is required");
42+
}
43+
return getToken(
44+
options.client,
45+
options.token.tokenAddress,
46+
options.token.chainId,
47+
);
48+
},
49+
refetchOnMount: false,
50+
retry: false,
51+
refetchOnWindowFocus: false,
52+
});
53+
}

0 commit comments

Comments
 (0)