Skip to content

Commit d2b967b

Browse files
committed
update
1 parent a1b518c commit d2b967b

File tree

9 files changed

+538
-64
lines changed

9 files changed

+538
-64
lines changed

apps/dashboard/src/@/components/blocks/wallet-address.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,13 @@ function WalletAvatar(props: {
191191
className="size-6"
192192
/>
193193
) : (
194-
<Blobbie address={props.address} size={24} />
194+
<Blobbie
195+
address={props.address}
196+
style={{
197+
width: "24px",
198+
height: "24px",
199+
}}
200+
/>
195201
)}
196202
</div>
197203
);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use client";
2+
3+
import { Button } from "@/components/ui/button";
4+
import { THIRDWEB_CLIENT } from "@/lib/client";
5+
import { Suspense } from "react";
6+
import { sepolia } from "thirdweb/chains";
7+
import { Account, Blobbie, ThirdwebProvider } from "thirdweb/react";
8+
import { shortenAddress } from "thirdweb/utils";
9+
10+
export default function Page() {
11+
return (
12+
<ThirdwebProvider>
13+
<div className="flex h-full w-full flex-col items-center gap-3">
14+
<div>
15+
<div>Let&apos;s rebuild a basic ConnectButton-details component</div>
16+
<BasicConnectedButton />
17+
</div>
18+
</div>
19+
</ThirdwebProvider>
20+
);
21+
}
22+
23+
const BasicConnectedButton = () => {
24+
const roundUpBalance = (num: number) => Math.round(num * 10) / 10;
25+
return (
26+
<Account
27+
address="0x12345674b599ce99958242b3D3741e7b01841DF3"
28+
client={THIRDWEB_CLIENT}
29+
>
30+
<Button className="flex h-12 w-40 flex-row justify-start gap-3 px-2">
31+
<Suspense
32+
fallback={
33+
<Blobbie
34+
address="0x12345674b599ce99958242b3D3741e7b01841DF3"
35+
className="h-10 w-10 rounded-full"
36+
/>
37+
}
38+
>
39+
<Account.Avatar className="h-10 w-10 rounded-full" />
40+
</Suspense>
41+
<div className="flex flex-col items-start">
42+
<Suspense fallback={<Account.Address formatFn={shortenAddress} />}>
43+
<Account.Name />
44+
</Suspense>
45+
<Suspense fallback={"skeleton"}>
46+
<Account.Balance chain={sepolia} formatFn={roundUpBalance} />
47+
</Suspense>
48+
</div>
49+
</Button>
50+
</Account>
51+
);
52+
};

packages/thirdweb/src/exports/react.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,6 @@ export type {
199199
// Site Embed and Linking
200200
export { SiteEmbed } from "../react/web/ui/SiteEmbed.js";
201201
export { SiteLink } from "../react/web/ui/SiteLink.js";
202+
203+
// Account
204+
export { Account } from "../react/web/ui/prebuilt/Account/index.js";

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ const COLOR_OPTIONS = [
2525
* A unique gradient avatar based on the provided address.
2626
* @param props The component props.
2727
* @param props.address The address to generate the gradient with.
28-
* @param props.size The size of each side of the square avatar (in pixels)
28+
* @param props.style The CSS style for the component - excluding `backgroundImage`
29+
* @param props.className The className for the component
2930
*/
30-
export function Blobbie(props: { address: Address; size: number }) {
31+
export function Blobbie(props: {
32+
address: Address;
33+
style?: Omit<React.CSSProperties, "backgroundImage">;
34+
className?: string;
35+
}) {
3136
const id = useId();
3237
const colors = useMemo(
3338
() =>
@@ -41,10 +46,10 @@ export function Blobbie(props: { address: Address; size: number }) {
4146
<div
4247
id={id}
4348
style={{
44-
width: `${props.size}px`,
45-
height: `${props.size}px`,
49+
...props.style,
4650
backgroundImage: `radial-gradient(ellipse at left bottom, ${colors[0]}, ${colors[1]})`,
4751
}}
52+
className={props.className}
4853
/>
4954
);
5055
}

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

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Spinner } from "../components/Spinner.js";
2323
import { Container } from "../components/basic.js";
2424
import { Button } from "../components/buttons.js";
2525
import { fadeInAnimation } from "../design-system/animations.js";
26+
import { Account } from "../prebuilt/Account/index.js";
2627
import { ConnectedWalletDetails } from "./Details.js";
2728
import ConnectModal from "./Modal/ConnectModal.js";
2829
import { LockIcon } from "./icons/LockIcon.js";
@@ -531,37 +532,39 @@ function ConnectButtonInner(
531532
}
532533

533534
return (
534-
<ConnectedWalletDetails
535-
theme={theme}
536-
detailsButton={props.detailsButton}
537-
detailsModal={props.detailsModal}
538-
supportedTokens={supportedTokens}
539-
supportedNFTs={props.supportedNFTs}
540-
onDisconnect={(info) => {
541-
// logout on explicit disconnect!
542-
if (siweAuth.requiresAuth) {
543-
siweAuth.doLogout();
544-
}
545-
props.onDisconnect?.(info);
546-
}}
547-
chains={props?.chains || []}
548-
chain={props.chain}
549-
switchButton={props.switchButton}
550-
client={props.client}
551-
connectLocale={locale}
552-
connectOptions={{
553-
accountAbstraction: props.accountAbstraction,
554-
appMetadata: props.appMetadata,
555-
chain: props.chain,
556-
chains: props.chains,
557-
connectModal: props.connectModal,
558-
recommendedWallets: props.recommendedWallets,
559-
showAllWallets: props.showAllWallets,
560-
walletConnect: props.walletConnect,
561-
wallets: props.wallets,
562-
hiddenWallets: props.detailsModal?.hiddenWallets,
563-
}}
564-
/>
535+
<Account address={activeAccount.address} client={props.client}>
536+
<ConnectedWalletDetails
537+
theme={theme}
538+
detailsButton={props.detailsButton}
539+
detailsModal={props.detailsModal}
540+
supportedTokens={supportedTokens}
541+
supportedNFTs={props.supportedNFTs}
542+
onDisconnect={(info) => {
543+
// logout on explicit disconnect!
544+
if (siweAuth.requiresAuth) {
545+
siweAuth.doLogout();
546+
}
547+
props.onDisconnect?.(info);
548+
}}
549+
chains={props?.chains || []}
550+
chain={props.chain}
551+
switchButton={props.switchButton}
552+
client={props.client}
553+
connectLocale={locale}
554+
connectOptions={{
555+
accountAbstraction: props.accountAbstraction,
556+
appMetadata: props.appMetadata,
557+
chain: props.chain,
558+
chains: props.chains,
559+
connectModal: props.connectModal,
560+
recommendedWallets: props.recommendedWallets,
561+
showAllWallets: props.showAllWallets,
562+
walletConnect: props.walletConnect,
563+
wallets: props.wallets,
564+
hiddenWallets: props.detailsModal?.hiddenWallets,
565+
}}
566+
/>
567+
</Account>
565568
);
566569
}
567570

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

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TextAlignJustifyIcon,
1010
} from "@radix-ui/react-icons";
1111
import { useQuery } from "@tanstack/react-query";
12-
import { type JSX, useContext, useEffect, useState } from "react";
12+
import { type JSX, Suspense, useContext, useEffect, useState } from "react";
1313
import { trackPayEvent } from "../../../../analytics/track/pay.js";
1414
import type { Chain } from "../../../../chains/types.js";
1515
import type { ThirdwebClient } from "../../../../client/client.js";
@@ -20,7 +20,10 @@ import { formatNumber } from "../../../../utils/formatNumber.js";
2020
import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
2121
import { isEcosystemWallet } from "../../../../wallets/ecosystem/is-ecosystem-wallet.js";
2222
import type { Ecosystem } from "../../../../wallets/in-app/core/wallet/types.js";
23-
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
23+
import type {
24+
Account as AccountType,
25+
Wallet,
26+
} from "../../../../wallets/interfaces/wallet.js";
2427
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
2528
import {
2629
type AppMetadata,
@@ -86,6 +89,7 @@ import { Button, IconButton } from "../components/buttons.js";
8689
import { Link, Text } from "../components/text.js";
8790
import { fadeInAnimation } from "../design-system/animations.js";
8891
import { StyledButton } from "../design-system/elements.js";
92+
import { Account } from "../prebuilt/Account/index.js";
8993
import type { LocaleId } from "../types.js";
9094
import { Blobbie } from "./Blobbie.js";
9195
import { MenuButton, MenuLink } from "./MenuButton.js";
@@ -125,7 +129,7 @@ const LocalhostChainId = 1337;
125129
export const ConnectedWalletDetails: React.FC<{
126130
onDisconnect: (info: {
127131
wallet: Wallet;
128-
account: Account;
132+
account: AccountType;
129133
}) => void;
130134
detailsButton?: ConnectButton_detailsButtonOptions;
131135
detailsModal?: ConnectButton_detailsModalOptions;
@@ -145,7 +149,7 @@ export const ConnectedWalletDetails: React.FC<{
145149
const activeAccount = useActiveAccount();
146150
const walletChain = useActiveWalletChain();
147151

148-
const { pfp, name, balanceQuery } = useConnectedWalletDetails(
152+
const { pfp, name } = useConnectedWalletDetails(
149153
client,
150154
walletChain,
151155
activeAccount,
@@ -229,7 +233,15 @@ export const ConnectedWalletDetails: React.FC<{
229233
}}
230234
/>
231235
) : (
232-
activeAccount && <Blobbie address={activeAccount.address} size={35} />
236+
activeAccount && (
237+
<Blobbie
238+
address={activeAccount.address}
239+
style={{
240+
width: "35px",
241+
height: "35px",
242+
}}
243+
/>
244+
)
233245
)}
234246
</Container>
235247
<Container
@@ -250,21 +262,24 @@ export const ConnectedWalletDetails: React.FC<{
250262
>
251263
{props.detailsButton?.connectedAccountName ?? name}
252264
</Text>
253-
254-
{/* Balance */}
255-
{balanceQuery.data ? (
265+
<Suspense fallback={<Skeleton height={fontSize.xs} width="70px" />}>
256266
<Text
257267
className={`${TW_CONNECTED_WALLET}__balance`}
258268
size="xs"
259269
color="secondaryText"
260270
weight={400}
261271
>
262-
{formatBalanceOnButton(Number(balanceQuery.data.displayValue))}{" "}
263-
{balanceQuery.data.symbol}
272+
<Account.Balance
273+
chain={walletChain}
274+
tokenAddress={
275+
props.detailsButton?.displayBalanceToken?.[
276+
walletChain?.id || -1
277+
]
278+
}
279+
formatFn={formatBalanceOnButton}
280+
/>
264281
</Text>
265-
) : (
266-
<Skeleton height={fontSize.xs} width="70px" />
267-
)}
282+
</Suspense>
268283
</Container>
269284
</WalletInfoButton>
270285
);
@@ -280,7 +295,7 @@ function DetailsModal(props: {
280295
closeModal: () => void;
281296
onDisconnect: (info: {
282297
wallet: Wallet;
283-
account: Account;
298+
account: AccountType;
284299
}) => void;
285300
chains: Chain[];
286301
displayBalanceToken?: Record<number, string>;
@@ -294,7 +309,7 @@ function DetailsModal(props: {
294309
const { client, locale } = props;
295310
const walletChain = useActiveWalletChain();
296311
const activeAccount = useActiveAccount();
297-
const { pfp, name, balanceQuery } = useConnectedWalletDetails(
312+
const { pfp, name } = useConnectedWalletDetails(
298313
client,
299314
walletChain,
300315
activeAccount,
@@ -322,12 +337,14 @@ function DetailsModal(props: {
322337
});
323338
}
324339

325-
function handleDisconnect(info: { wallet: Wallet; account: Account }) {
340+
function handleDisconnect(info: { wallet: Wallet; account: AccountType }) {
326341
setIsOpen(false);
327342
props.closeModal();
328343
props.onDisconnect(info);
329344
}
330345

346+
const formatBalance = (num: number) => formatNumber(num, 9);
347+
331348
const networkSwitcherButton = (
332349
<MenuButton
333350
type="button"
@@ -361,14 +378,23 @@ function DetailsModal(props: {
361378
) : (
362379
<Text color="primaryText" size="md" multiline>
363380
{chainNameQuery.name || `Unknown chain #${walletChain?.id}`}
364-
<Text color="secondaryText" size="xs">
365-
{balanceQuery.data ? (
366-
formatNumber(Number(balanceQuery.data.displayValue), 9)
367-
) : (
368-
<Skeleton height="1em" width="100px" />
369-
)}{" "}
370-
{balanceQuery.data?.symbol}
371-
</Text>
381+
<Suspense
382+
fallback={
383+
<Text color="secondaryText" size="xs">
384+
<Skeleton height="1em" width="100px" />
385+
</Text>
386+
}
387+
>
388+
<Text color="secondaryText" size="xs">
389+
<Account.Balance
390+
chain={walletChain}
391+
tokenAddress={
392+
props.displayBalanceToken?.[walletChain?.id || -1]
393+
}
394+
formatFn={formatBalance}
395+
/>
396+
</Text>
397+
</Suspense>
372398
</Text>
373399
)}
374400

@@ -419,7 +445,10 @@ function DetailsModal(props: {
419445
activeAccount && (
420446
<Blobbie
421447
address={activeAccount.address}
422-
size={Number(iconSize.xxl)}
448+
style={{
449+
width: `${iconSize.xxl}px`,
450+
height: `${iconSize.xxl}px`,
451+
}}
423452
/>
424453
)
425454
)}
@@ -1401,7 +1430,7 @@ export type UseWalletDetailsModalOptions = {
14011430
*/
14021431
onDisconnect?: (info: {
14031432
wallet: Wallet;
1404-
account: Account;
1433+
account: AccountType;
14051434
}) => void;
14061435

14071436
/**

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/WalletSelectorButton.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ export function WalletRow(props: {
171171
border: `1px solid ${theme.colors.borderColor}`,
172172
}}
173173
>
174-
<Blobbie address={props.address} size={Number(iconSize.md)} />
174+
<Blobbie
175+
address={props.address}
176+
style={{ width: `${iconSize.md}px`, height: `${iconSize.md}px` }}
177+
/>
175178
</Container>
176179
)}
177180

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ function LinkedProfile({
148148
overflow: "hidden",
149149
}}
150150
>
151-
<Blobbie address={profile.details.address} size={32} />
151+
<Blobbie
152+
address={profile.details.address}
153+
style={{
154+
width: "32px",
155+
height: "32px",
156+
}}
157+
/>
152158
</Container>
153159
) : profile.type === "passkey" ? (
154160
<FingerPrintIcon size={iconSize.lg} />

0 commit comments

Comments
 (0)