Skip to content

Commit f9b8179

Browse files
committed
Update
1 parent 68ce724 commit f9b8179

File tree

7 files changed

+136
-40
lines changed

7 files changed

+136
-40
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+
```

apps/playground-web/src/app/connect/sign-in/button/RightSection.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ export function RightSection(props: {
110110
}
111111
: undefined
112112
}
113+
supportedNFTs={{
114+
"84532": ["0x638263e3eAa3917a53630e61B1fBa685308024fa"],
115+
"11155111": ["0x7196e8Fb8DDb8b1Da9133BD876C6aEDB8f5D7995"],
116+
}}
117+
supportedTokens={{
118+
11155111: [
119+
{
120+
name: "TWCOIN",
121+
symbol: "TWCON",
122+
address: "0x7196e8Fb8DDb8b1Da9133BD876C6aEDB8f5D7995",
123+
},
124+
],
125+
}}
126+
detailsModal={{ assetTabs: ["nft", "token"] }}
113127
/>
114128
);
115129

apps/playground-web/src/components/styled-connect-button.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,18 @@ export function StyledConnectButton(
3030
wallets={WALLETS}
3131
supportedNFTs={{
3232
"84532": ["0x638263e3eAa3917a53630e61B1fBa685308024fa"],
33+
"11155111": ["0x7196e8Fb8DDb8b1Da9133BD876C6aEDB8f5D7995"],
3334
}}
35+
supportedTokens={{
36+
11155111: [
37+
{
38+
name: "TWCOIN",
39+
symbol: "TWCON",
40+
address: "0x7196e8Fb8DDb8b1Da9133BD876C6aEDB8f5D7995",
41+
},
42+
],
43+
}}
44+
detailsModal={{ assetTabs: ["nft", "token"] }}
3445
client={THIRDWEB_CLIENT}
3546
theme={theme === "light" ? "light" : "dark"}
3647
{...props}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
33
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
44
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
55
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
6+
import type { AssetTabs } from "../../../../react/web/ui/ConnectWallet/screens/ViewAssets.js";
67
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
78
import type { Prettify } from "../../../../utils/type-utils.js";
89
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
@@ -311,6 +312,13 @@ export type ConnectButton_detailsModalOptions = {
311312
* All wallet IDs included in this array will be hidden from wallet selection when connected.
312313
*/
313314
hiddenWallets?: WalletId[];
315+
316+
/**
317+
* When you click on "View Assets", by default the "Tokens" tab is shown first.
318+
* If you want to show the "NFTs" tab first, change the order of the asset tabs to: ["nft", "token"]
319+
* Note: If an empty array is passed, the [View Funds] button will be hidden
320+
*/
321+
assetTabs?: AssetTabs[];
314322
};
315323

316324
/**

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ 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, change the order of the asset tabs to: ["nft", "token"]
253+
* Note: If an empty array is passed, the [View Funds] button will be hidden
254+
*
255+
* ```tsx
256+
* <ConnectButton
257+
* client={client}
258+
* detailsModal={{
259+
* assetTabs: ["nft", "token"],
260+
* }}
261+
* />
262+
* ```
263+
*
250264
* @param props
251265
* Props for the `ConnectButton` component
252266
*

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import { ManageWalletScreen } from "./screens/ManageWalletScreen.js";
109109
import { PrivateKey } from "./screens/PrivateKey.js";
110110
import { ReceiveFunds } from "./screens/ReceiveFunds.js";
111111
import { SendFunds } from "./screens/SendFunds.js";
112-
import { ViewAssets } from "./screens/ViewAssets.js";
112+
import { type AssetTabs, ViewAssets } from "./screens/ViewAssets.js";
113113
import { ViewNFTs } from "./screens/ViewNFTs.js";
114114
import { ViewTokens } from "./screens/ViewTokens.js";
115115
import { WalletConnectReceiverScreen } from "./screens/WalletConnectReceiverScreen.js";
@@ -170,6 +170,7 @@ export const ConnectedWalletDetails: React.FC<{
170170
chains={props.chains}
171171
displayBalanceToken={props.detailsButton?.displayBalanceToken}
172172
connectOptions={props.connectOptions}
173+
assetTabs={props.detailsModal?.assetTabs}
173174
/>,
174175
);
175176
}
@@ -284,6 +285,7 @@ function DetailsModal(props: {
284285
chains: Chain[];
285286
displayBalanceToken?: Record<number, string>;
286287
connectOptions: DetailsModalConnectOptions | undefined;
288+
assetTabs?: AssetTabs[];
287289
}) {
288290
const [screen, setScreen] = useState<WalletDetailsModalScreen>("main");
289291
const { disconnect } = useDisconnect();
@@ -627,21 +629,25 @@ function DetailsModal(props: {
627629
</MenuButton>
628630

629631
{/* View Funds */}
630-
<MenuButton
631-
onClick={() => {
632-
setScreen("view-assets");
633-
}}
634-
style={{
635-
fontSize: fontSize.sm,
636-
}}
637-
>
638-
<CoinsIcon size={iconSize.md} />
639-
<Text color="primaryText">
640-
{props.supportedNFTs
641-
? locale.viewFunds.viewAssets
642-
: locale.viewFunds.title}
643-
</Text>
644-
</MenuButton>
632+
{/* Hide the View Funds button if the assetTabs props is set to an empty array */}
633+
{!props.assetTabs ||
634+
(props.assetTabs?.length && (
635+
<MenuButton
636+
onClick={() => {
637+
setScreen("view-assets");
638+
}}
639+
style={{
640+
fontSize: fontSize.sm,
641+
}}
642+
>
643+
<CoinsIcon size={iconSize.md} />
644+
<Text color="primaryText">
645+
{props.supportedNFTs
646+
? locale.viewFunds.viewAssets
647+
: locale.viewFunds.title}
648+
</Text>
649+
</MenuButton>
650+
))}
645651

646652
{/* Manage Wallet */}
647653
<MenuButton
@@ -799,6 +805,7 @@ function DetailsModal(props: {
799805
setScreen={setScreen}
800806
client={client}
801807
connectLocale={locale}
808+
assetTabs={props.detailsModal?.assetTabs}
802809
/>
803810
);
804811
} else {
@@ -1458,6 +1465,13 @@ export type UseWalletDetailsModalOptions = {
14581465
* By default the "Buy Funds" button is shown.
14591466
*/
14601467
hideBuyFunds?: boolean;
1468+
1469+
/**
1470+
* When you click on "View Assets", by default the "Tokens" tab is shown first.
1471+
* If you want to show the "NFTs" tab first, change the order of the asset tabs to: ["nft", "token"]
1472+
* Note: If an empty array is passed, the [View Funds] button will be hidden
1473+
*/
1474+
assetTabs?: AssetTabs[];
14611475
};
14621476

14631477
/**
@@ -1515,6 +1529,7 @@ export function useWalletDetailsModal() {
15151529
hideBuyFunds: props.hideBuyFunds,
15161530
hideReceiveFunds: props.hideReceiveFunds,
15171531
hideSendFunds: props.hideSendFunds,
1532+
assetTabs: props.assetTabs,
15181533
}}
15191534
displayBalanceToken={props.displayBalanceToken}
15201535
theme={props.theme || "dark"}

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

Lines changed: 43 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 {
@@ -15,6 +15,29 @@ import { ViewNFTsContent } from "./ViewNFTs.js";
1515
import { ViewTokensContent } from "./ViewTokens.js";
1616
import type { WalletDetailsModalScreen } from "./types.js";
1717

18+
/**
19+
* @internal
20+
*/
21+
export type AssetTabs = "token" | "nft";
22+
23+
const TokenTab = {
24+
label: (
25+
<span className="flex gap-2">
26+
<CoinsIcon size={iconSize.sm} /> Tokens
27+
</span>
28+
),
29+
value: "Tokens",
30+
};
31+
32+
const NftTab = {
33+
label: (
34+
<span className="flex gap-2">
35+
<ImageIcon size={iconSize.sm} /> NFTs
36+
</span>
37+
),
38+
value: "NFTs",
39+
};
40+
1841
/**
1942
* @internal
2043
*/
@@ -26,10 +49,27 @@ export function ViewAssets(props: {
2649
setScreen: (screen: WalletDetailsModalScreen) => void;
2750
client: ThirdwebClient;
2851
connectLocale: ConnectLocale;
52+
assetTabs?: AssetTabs[];
2953
}) {
3054
const [activeTab, setActiveTab] = useState("Tokens");
3155
const { connectLocale } = props;
32-
56+
const options = useMemo(() => {
57+
if (!props.assetTabs) {
58+
return [TokenTab, NftTab];
59+
}
60+
if (!props.assetTabs.length) {
61+
return [];
62+
}
63+
const tabs = [];
64+
for (const item of props.assetTabs) {
65+
if (item === "token") {
66+
tabs.push(TokenTab);
67+
} else if (item === "nft") {
68+
tabs.push(NftTab);
69+
}
70+
}
71+
return tabs;
72+
}, [props.assetTabs]);
3373
return (
3474
<Container
3575
animate="fadein"
@@ -52,28 +92,7 @@ export function ViewAssets(props: {
5292
}}
5393
>
5494
<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-
>
95+
<Tabs options={options} selected={activeTab} onSelect={setActiveTab}>
7796
<Container
7897
scrollY
7998
style={{

0 commit comments

Comments
 (0)