Skip to content

Commit 467ba50

Browse files
committed
[BLD-125] SDK: Fix missing props for details modal on useWalletDetailsModal hook (#7865)
<!-- ## 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 `useWalletDetailsModal` hook by adding missing properties for better configuration of the details modal, along with adjustments to the UI components for displaying wallet details. ### Detailed summary - Added missing props for the details modal in the `useWalletDetailsModal` hook. - Updated `DetailsModal` to include `manageWallet`, `showBalanceInFiat`, and `hiddenWallets` props. - Modified the `TokenTab` and `NftTab` components to use inline styles instead of utility classes. - Enhanced storybook stories for `useWalletDetailsModal` with various configurations and examples. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Wallet Details modal: show balances in fiat, configure manage-wallet options, hide specific wallets, and pass connect options from the switcher. - Assets view: default active tab now adapts dynamically based on available tabs. - Documentation - Added comprehensive Storybook examples for the wallet details modal covering configuration, theming, locales, and callbacks. - Clarified notes to keep related modal options in sync. - Style - Updated tab label styling to inline CSS for consistent layout. - Chores - Added a patch-level changeset. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 2f627e1 commit 467ba50

File tree

5 files changed

+245
-2
lines changed

5 files changed

+245
-2
lines changed

.changeset/swift-toes-build.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 missing props for details modal on `useWalletDetailsModal` hook

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ export type TransactionOptions = {
198198
transaction: PreparedTransaction;
199199
};
200200

201+
// Note: When adding props to ConnectButton_connectButtonOptions,
202+
// make sure to also add it in UseWalletDetailsModalOptions for useWalletDetailsModal hook
203+
201204
/**
202205
* Options for configuring the `ConnectButton`'s Connect Button
203206
* @connectWallet

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export const ConnectedWalletDetails: React.FC<{
179179
supportedNFTs={props.supportedNFTs}
180180
supportedTokens={props.supportedTokens}
181181
theme={props.theme}
182+
showBalanceInFiat={props.detailsButton?.showBalanceInFiat}
182183
/>,
183184
);
184185
}
@@ -898,6 +899,7 @@ export function DetailsModal(props: {
898899
onBack={() => {
899900
setScreen("main");
900901
}}
902+
manageWallet={props.detailsModal?.manageWallet}
901903
setScreen={setScreen}
902904
/>
903905
);
@@ -975,6 +977,7 @@ export function DetailsModal(props: {
975977
client={client}
976978
hiddenWallets={props.detailsModal?.hiddenWallets}
977979
locale={locale.id}
980+
connectOptions={props.connectOptions}
978981
onCancel={() => setScreen("main")}
979982
onSuccess={() => setScreen("main")}
980983
supportedTokens={props.supportedTokens}
@@ -1594,6 +1597,26 @@ export type UseWalletDetailsModalOptions = {
15941597

15951598
/**
15961599
* Render custom UI at the bottom of the Details Modal
1600+
* @param props - props passed to the footer component which includes a function to close the modal
1601+
* @example
1602+
* ```tsx
1603+
* function Example() {
1604+
* const detailsModal = useWalletDetailsModal();
1605+
*
1606+
* return (
1607+
* <button onClick={() => detailsModal.open({
1608+
* client,
1609+
* footer: CustomFooter,
1610+
* })}>
1611+
* wallet details
1612+
* </button>
1613+
* )
1614+
* }
1615+
*
1616+
* function CustomFooter(props: { close: () => void }) {
1617+
* return <div> ... </div>
1618+
* }
1619+
* ```
15971620
*/
15981621
footer?: (props: { close: () => void }) => JSX.Element;
15991622

@@ -1653,6 +1676,11 @@ export type UseWalletDetailsModalOptions = {
16531676
*/
16541677
hideBuyFunds?: boolean;
16551678

1679+
/**
1680+
* All wallet IDs included in this array will be hidden from wallet selection when connected.
1681+
*/
1682+
hiddenWallets?: WalletId[];
1683+
16561684
/**
16571685
* When you click on "View Assets", by default the "Tokens" tab is shown first.
16581686
* If you want to show the "NFTs" tab first, change the order of the asset tabs to: ["nft", "token"]
@@ -1666,6 +1694,18 @@ export type UseWalletDetailsModalOptions = {
16661694
*/
16671695
showBalanceInFiat?: SupportedFiatCurrency;
16681696

1697+
/**
1698+
* Configure options for managing the connected wallet.
1699+
*/
1700+
manageWallet?: {
1701+
/**
1702+
* Allow linking other profiles to the connected wallet.
1703+
*
1704+
* By default it is `true`.
1705+
*/
1706+
allowLinkingProfiles?: boolean;
1707+
};
1708+
16691709
/**
16701710
* The callback function for when the modal is closed
16711711
* @param screen The name of the screen that was being shown when user closed the modal
@@ -1729,6 +1769,9 @@ export function useWalletDetailsModal() {
17291769
closeModal={closeModal}
17301770
connectOptions={props.connectOptions}
17311771
detailsModal={{
1772+
showBalanceInFiat: props.showBalanceInFiat,
1773+
hiddenWallets: props.hiddenWallets,
1774+
manageWallet: props.manageWallet,
17321775
assetTabs: props.assetTabs,
17331776
connectedAccountAvatarUrl: props.connectedAccountAvatarUrl,
17341777
connectedAccountName: props.connectedAccountName,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type AssetTabs = "token" | "nft";
2222

2323
const TokenTab = {
2424
label: (
25-
<span className="flex gap-2">
25+
<span style={{ display: "flex", gap: "8px", alignItems: "center" }}>
2626
<CoinsIcon size={iconSize.sm} /> Tokens
2727
</span>
2828
),
@@ -31,7 +31,7 @@ const TokenTab = {
3131

3232
const NftTab = {
3333
label: (
34-
<span className="flex gap-2">
34+
<span style={{ display: "flex", gap: "8px", alignItems: "center" }}>
3535
<ImageIcon size={iconSize.sm} /> NFTs
3636
</span>
3737
),
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import type { Meta } from "@storybook/react-vite";
2+
import { base } from "../../chains/chain-definitions/base.js";
3+
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
4+
import { polygon } from "../../chains/chain-definitions/polygon.js";
5+
import { lightTheme } from "../../react/core/design-system/index.js";
6+
import { useActiveAccount } from "../../react/core/hooks/wallets/useActiveAccount.js";
7+
import { ConnectButton } from "../../react/web/ui/ConnectWallet/ConnectButton.js";
8+
import {
9+
type UseWalletDetailsModalOptions,
10+
useWalletDetailsModal,
11+
} from "../../react/web/ui/ConnectWallet/Details.js";
12+
import { storyClient } from "../utils.js";
13+
14+
const meta: Meta = {
15+
parameters: {
16+
layout: "centered",
17+
},
18+
tags: ["autodocs"],
19+
title: "Hooks/useWalletDetailsModal",
20+
decorators: [
21+
(Story) => {
22+
return (
23+
<div style={{ display: "flex", flexDirection: "column", gap: "10px" }}>
24+
<ConnectButton client={storyClient} autoConnect={true} />
25+
<Story />
26+
</div>
27+
);
28+
},
29+
],
30+
};
31+
export default meta;
32+
33+
export function BasicUsage() {
34+
return <Variant client={storyClient} />;
35+
}
36+
37+
export function DisableLinkingProfiles() {
38+
return (
39+
<Variant
40+
client={storyClient}
41+
manageWallet={{ allowLinkingProfiles: false }}
42+
/>
43+
);
44+
}
45+
46+
export function HideSwitchWallet() {
47+
return <Variant client={storyClient} hideSwitchWallet={true} />;
48+
}
49+
50+
export function HideDisconnect() {
51+
return <Variant client={storyClient} hideDisconnect={true} />;
52+
}
53+
54+
export function HideSendFunds() {
55+
return <Variant client={storyClient} hideSendFunds={true} />;
56+
}
57+
58+
export function HideReceiveFunds() {
59+
return <Variant client={storyClient} hideReceiveFunds={true} />;
60+
}
61+
62+
export function HideBuyFunds() {
63+
return <Variant client={storyClient} hideBuyFunds={true} />;
64+
}
65+
66+
export function HideAllTopButtons() {
67+
return (
68+
<Variant
69+
client={storyClient}
70+
hideSendFunds={true}
71+
hideReceiveFunds={true}
72+
hideBuyFunds={true}
73+
/>
74+
);
75+
}
76+
77+
export function Chains() {
78+
return <Variant client={storyClient} chains={[ethereum, polygon, base]} />;
79+
}
80+
81+
export function Locale() {
82+
return <Variant client={storyClient} locale="ja_JP" />;
83+
}
84+
85+
export function ConnectedAccountAvatarUrl() {
86+
return (
87+
<Variant
88+
client={storyClient}
89+
connectedAccountAvatarUrl="https://thirdweb.com/favicon.ico"
90+
/>
91+
);
92+
}
93+
94+
export function ConnectedAccountName() {
95+
return <Variant client={storyClient} connectedAccountName="test" />;
96+
}
97+
98+
export function ShowBalanceInFiat() {
99+
return <Variant client={storyClient} showBalanceInFiat="usd" />;
100+
}
101+
102+
export function AssetTabs() {
103+
return <Variant client={storyClient} assetTabs={["nft", "token"]} />;
104+
}
105+
106+
export function OnClose() {
107+
return (
108+
<Variant
109+
client={storyClient}
110+
onClose={() => {
111+
alert("onClose");
112+
}}
113+
/>
114+
);
115+
}
116+
117+
export function Footer() {
118+
return (
119+
<Variant
120+
client={storyClient}
121+
footer={(props) => (
122+
<div
123+
style={{
124+
outline: "1px solid red",
125+
padding: "16px",
126+
display: "flex",
127+
justifyContent: "space-between",
128+
alignItems: "center",
129+
gap: "10px",
130+
}}
131+
>
132+
custom footer
133+
<button onClick={props.close} type="button">
134+
close
135+
</button>
136+
</div>
137+
)}
138+
/>
139+
);
140+
}
141+
142+
export function ConnectOptions() {
143+
return (
144+
<Variant
145+
client={storyClient}
146+
connectOptions={{
147+
showAllWallets: false,
148+
}}
149+
/>
150+
);
151+
}
152+
153+
export function LightTheme() {
154+
return <Variant client={storyClient} theme="light" />;
155+
}
156+
157+
export function CustomLightTheme() {
158+
return (
159+
<Variant
160+
client={storyClient}
161+
theme={lightTheme({
162+
colors: {
163+
modalBg: "#FFFFF0",
164+
tertiaryBg: "#DBE4C9",
165+
borderColor: "#8AA624",
166+
secondaryText: "#3E3F29",
167+
accentText: "#E43636",
168+
},
169+
})}
170+
/>
171+
);
172+
}
173+
174+
function Variant(params: UseWalletDetailsModalOptions) {
175+
const account = useActiveAccount();
176+
const detailsModal = useWalletDetailsModal();
177+
178+
if (!account) {
179+
return <p> no account </p>;
180+
}
181+
182+
return (
183+
<button
184+
type="button"
185+
onClick={() => {
186+
detailsModal.open(params);
187+
}}
188+
>
189+
test
190+
</button>
191+
);
192+
}

0 commit comments

Comments
 (0)