Skip to content

Commit 20663a1

Browse files
committed
Update
1 parent 45fcfb1 commit 20663a1

File tree

5 files changed

+71
-24
lines changed

5 files changed

+71
-24
lines changed

.changeset/seven-singers-bathe.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Add option to customize ViewAssets tabs
6+
7+
When you click on "View Assets", by default the "Tokens" tab is shown first. If you want to show the "NFTs" tab first, set this prop to true
8+
```tsx
9+
<ConnectButton
10+
client={client}
11+
detailsModal={{
12+
swapAssetTabsPositions: true,
13+
}}
14+
/>
15+
```

packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ export type ConnectButton_detailsModalOptions = {
311311
* All wallet IDs included in this array will be hidden from wallet selection when connected.
312312
*/
313313
hiddenWallets?: WalletId[];
314+
315+
/**
316+
* When you click on "View Assets", by default the "Tokens" tab is shown first.
317+
* If you want to show the "NFTs" tab first, set this prop to `true`
318+
*/
319+
swapAssetTabsPositions?: boolean;
314320
};
315321

316322
/**

packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ const TW_CONNECT_WALLET = "tw-connect-wallet";
247247
* />
248248
* ```
249249
*
250+
* ### Customizing the orders of the tabs in the [View Funds] screen
251+
* When you click on "View Assets", by default the "Tokens" tab is shown first.
252+
* If you want to show the "NFTs" tab first, set this prop to `true`
253+
*
254+
* ```tsx
255+
* <ConnectButton
256+
* client={client}
257+
* detailsModal={{
258+
* swapAssetTabsPositions: true,
259+
* }}
260+
* />
261+
* ```
262+
*
250263
* @param props
251264
* Props for the `ConnectButton` component
252265
*

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const ConnectedWalletDetails: React.FC<{
170170
chains={props.chains}
171171
displayBalanceToken={props.detailsButton?.displayBalanceToken}
172172
connectOptions={props.connectOptions}
173+
swapAssetTabsPositions={props.detailsModal?.swapAssetTabsPositions}
173174
/>,
174175
);
175176
}
@@ -286,6 +287,7 @@ function DetailsModal(props: {
286287
chains: Chain[];
287288
displayBalanceToken?: Record<number, string>;
288289
connectOptions: DetailsModalConnectOptions | undefined;
290+
swapAssetTabsPositions?: boolean;
289291
}) {
290292
const [screen, setScreen] = useState<WalletDetailsModalScreen>("main");
291293
const { disconnect } = useDisconnect();
@@ -801,6 +803,7 @@ function DetailsModal(props: {
801803
setScreen={setScreen}
802804
client={client}
803805
connectLocale={locale}
806+
swapAssetTabsPositions={props.detailsModal?.swapAssetTabsPositions}
804807
/>
805808
);
806809
} else {
@@ -1460,6 +1463,12 @@ export type UseWalletDetailsModalOptions = {
14601463
* By default the "Buy Funds" button is shown.
14611464
*/
14621465
hideBuyFunds?: boolean;
1466+
1467+
/**
1468+
* When you click on "View Assets", by default the "Tokens" tab is shown first.
1469+
* If you want to show the "NFTs" tab first, set this prop to `true`
1470+
*/
1471+
swapAssetTabsPositions?: boolean;
14631472
};
14641473

14651474
/**
@@ -1517,6 +1526,7 @@ export function useWalletDetailsModal() {
15171526
hideBuyFunds: props.hideBuyFunds,
15181527
hideReceiveFunds: props.hideReceiveFunds,
15191528
hideSendFunds: props.hideSendFunds,
1529+
swapAssetTabsPositions: props.swapAssetTabsPositions,
15201530
}}
15211531
displayBalanceToken={props.displayBalanceToken}
15221532
theme={props.theme || "dark"}

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useMemo, useState } from "react";
22
import type { ThirdwebClient } from "../../../../../client/client.js";
33
import { type Theme, iconSize } from "../../../../core/design-system/index.js";
44
import type {
@@ -26,10 +26,34 @@ export function ViewAssets(props: {
2626
setScreen: (screen: WalletDetailsModalScreen) => void;
2727
client: ThirdwebClient;
2828
connectLocale: ConnectLocale;
29+
swapAssetTabsPositions?: boolean;
2930
}) {
3031
const [activeTab, setActiveTab] = useState("Tokens");
3132
const { connectLocale } = props;
32-
33+
const options = useMemo(() => {
34+
const tabs = [
35+
{
36+
label: (
37+
<span className="flex gap-2">
38+
<CoinsIcon size={iconSize.sm} /> Tokens
39+
</span>
40+
),
41+
value: "Tokens",
42+
},
43+
{
44+
label: (
45+
<span className="flex gap-2">
46+
<ImageIcon size={iconSize.sm} /> NFTs
47+
</span>
48+
),
49+
value: "NFTs",
50+
},
51+
];
52+
if (props.swapAssetTabsPositions) {
53+
tabs.reverse();
54+
}
55+
return tabs;
56+
}, [props.swapAssetTabsPositions]);
3357
return (
3458
<Container
3559
animate="fadein"
@@ -52,28 +76,7 @@ export function ViewAssets(props: {
5276
}}
5377
>
5478
<Spacer y="md" />
55-
<Tabs
56-
options={[
57-
{
58-
label: (
59-
<span className="flex gap-2">
60-
<CoinsIcon size={iconSize.sm} /> Tokens
61-
</span>
62-
),
63-
value: "Tokens",
64-
},
65-
{
66-
label: (
67-
<span className="flex gap-2">
68-
<ImageIcon size={iconSize.sm} /> NFTs
69-
</span>
70-
),
71-
value: "NFTs",
72-
},
73-
]}
74-
selected={activeTab}
75-
onSelect={setActiveTab}
76-
>
79+
<Tabs options={options} selected={activeTab} onSelect={setActiveTab}>
7780
<Container
7881
scrollY
7982
style={{

0 commit comments

Comments
 (0)