Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ngo committed Oct 22, 2024
1 parent 45fcfb1 commit 20663a1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 24 deletions.
15 changes: 15 additions & 0 deletions .changeset/seven-singers-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"thirdweb": minor
---

Add option to customize ViewAssets tabs

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
```tsx
<ConnectButton
client={client}
detailsModal={{
swapAssetTabsPositions: true,
}}
/>
```
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ export type ConnectButton_detailsModalOptions = {
* All wallet IDs included in this array will be hidden from wallet selection when connected.
*/
hiddenWallets?: WalletId[];

/**
* 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`
*/
swapAssetTabsPositions?: boolean;
};

/**
Expand Down
13 changes: 13 additions & 0 deletions packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ const TW_CONNECT_WALLET = "tw-connect-wallet";
* />
* ```
*
* ### Customizing the orders of the tabs in the [View Funds] screen
* 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`
*
* ```tsx
* <ConnectButton
* client={client}
* detailsModal={{
* swapAssetTabsPositions: true,
* }}
* />
* ```
*
* @param props
* Props for the `ConnectButton` component
*
Expand Down
10 changes: 10 additions & 0 deletions packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const ConnectedWalletDetails: React.FC<{
chains={props.chains}
displayBalanceToken={props.detailsButton?.displayBalanceToken}
connectOptions={props.connectOptions}
swapAssetTabsPositions={props.detailsModal?.swapAssetTabsPositions}

Check warning on line 173 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L173 was not covered by tests
/>,
);
}
Expand Down Expand Up @@ -286,6 +287,7 @@ function DetailsModal(props: {
chains: Chain[];
displayBalanceToken?: Record<number, string>;
connectOptions: DetailsModalConnectOptions | undefined;
swapAssetTabsPositions?: boolean;
}) {
const [screen, setScreen] = useState<WalletDetailsModalScreen>("main");
const { disconnect } = useDisconnect();
Expand Down Expand Up @@ -801,6 +803,7 @@ function DetailsModal(props: {
setScreen={setScreen}
client={client}
connectLocale={locale}
swapAssetTabsPositions={props.detailsModal?.swapAssetTabsPositions}

Check warning on line 806 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L806 was not covered by tests
/>
);
} else {
Expand Down Expand Up @@ -1460,6 +1463,12 @@ export type UseWalletDetailsModalOptions = {
* By default the "Buy Funds" button is shown.
*/
hideBuyFunds?: boolean;

/**
* 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`
*/
swapAssetTabsPositions?: boolean;
};

/**
Expand Down Expand Up @@ -1517,6 +1526,7 @@ export function useWalletDetailsModal() {
hideBuyFunds: props.hideBuyFunds,
hideReceiveFunds: props.hideReceiveFunds,
hideSendFunds: props.hideSendFunds,
swapAssetTabsPositions: props.swapAssetTabsPositions,

Check warning on line 1529 in packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1529 was not covered by tests
}}
displayBalanceToken={props.displayBalanceToken}
theme={props.theme || "dark"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useMemo, useState } from "react";
import type { ThirdwebClient } from "../../../../../client/client.js";
import { type Theme, iconSize } from "../../../../core/design-system/index.js";
import type {
Expand Down Expand Up @@ -26,10 +26,34 @@ export function ViewAssets(props: {
setScreen: (screen: WalletDetailsModalScreen) => void;
client: ThirdwebClient;
connectLocale: ConnectLocale;
swapAssetTabsPositions?: boolean;
}) {
const [activeTab, setActiveTab] = useState("Tokens");
const { connectLocale } = props;

const options = useMemo(() => {
const tabs = [
{
label: (
<span className="flex gap-2">
<CoinsIcon size={iconSize.sm} /> Tokens
</span>

Check warning on line 39 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx#L33-L39

Added lines #L33 - L39 were not covered by tests
),
value: "Tokens",
},
{
label: (
<span className="flex gap-2">
<ImageIcon size={iconSize.sm} /> NFTs
</span>

Check warning on line 47 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx#L41-L47

Added lines #L41 - L47 were not covered by tests
),
value: "NFTs",
},
];
if (props.swapAssetTabsPositions) {
tabs.reverse();
}
return tabs;
}, [props.swapAssetTabsPositions]);

Check warning on line 56 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx#L49-L56

Added lines #L49 - L56 were not covered by tests
return (
<Container
animate="fadein"
Expand All @@ -52,28 +76,7 @@ export function ViewAssets(props: {
}}
>
<Spacer y="md" />
<Tabs
options={[
{
label: (
<span className="flex gap-2">
<CoinsIcon size={iconSize.sm} /> Tokens
</span>
),
value: "Tokens",
},
{
label: (
<span className="flex gap-2">
<ImageIcon size={iconSize.sm} /> NFTs
</span>
),
value: "NFTs",
},
]}
selected={activeTab}
onSelect={setActiveTab}
>
<Tabs options={options} selected={activeTab} onSelect={setActiveTab}>

Check warning on line 79 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L79 was not covered by tests
<Container
scrollY
style={{
Expand Down

0 comments on commit 20663a1

Please sign in to comment.