From fcf8f89af43dafacfb54a6c8c884b6b3631d5a68 Mon Sep 17 00:00:00 2001 From: Alec Ananian <1013230+alecananian@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:58:51 -0700 Subject: [PATCH] react: add overrides for connected wallet name and avatar in details button and modal (#4271) Co-authored-by: Joaquim Verges --- .changeset/empty-dots-jam.md | 5 + .../hooks/connection/ConnectButtonProps.ts | 20 ++++ .../react/web/ui/ConnectWallet/Details.tsx | 91 +++++++++++-------- 3 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 .changeset/empty-dots-jam.md diff --git a/.changeset/empty-dots-jam.md b/.changeset/empty-dots-jam.md new file mode 100644 index 00000000000..c8674b526f0 --- /dev/null +++ b/.changeset/empty-dots-jam.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Added overrides for connected wallet name and avatar in details button and modal diff --git a/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts b/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts index aea1c190c7d..e331b22fb9a 100644 --- a/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts +++ b/packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts @@ -278,6 +278,16 @@ export type ConnectButton_detailsModalOptions = { * thirdweb Pay allows users to buy tokens using crypto or fiat currency. */ payOptions?: Extract; + + /** + * Render custom UI for the connected wallet name in the `ConnectButton` Details Modal, overriding ENS name or wallet address. + */ + connectedAccountName?: React.ReactNode; + + /** + * Use custom avatar URL for the connected wallet image in the `ConnectButton` Details Modal, overriding ENS avatar or Blobbie icon. + */ + connectedAccountAvatarUrl?: string; }; /** @@ -325,6 +335,16 @@ export type ConnectButton_detailsButtonOptions = { * ``` */ displayBalanceToken?: Record; + + /** + * Render custom UI for the connected wallet name in the `ConnectButton` details button, overriding ENS name or wallet address. + */ + connectedAccountName?: React.ReactNode; + + /** + * Use custom avatar URL for the connected wallet image in the `ConnectButton` details button, overriding ENS avatar or Blobbie icon. + */ + connectedAccountAvatarUrl?: string; }; /** diff --git a/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx b/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx index 793a5e0a7a6..f61b2e1e35f 100644 --- a/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx +++ b/packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx @@ -185,6 +185,9 @@ export const ConnectedWalletDetails: React.FC<{ ); } + const avatarSrc = + props.detailsButton?.connectedAccountAvatarUrl ?? ensAvatarQuery.data; + return ( - {ensAvatarQuery.data ? ( + {avatarSrc ? ( {/* Address */} - {addressOrENS ? ( - - {addressOrENS} - - ) : ( - - )} + + {props.detailsButton?.connectedAccountName ?? addressOrENS} + {/* Balance */} {balanceQuery.data ? ( @@ -371,6 +370,9 @@ function DetailsModal(props: { ); + const avatarSrc = + props.detailsModal?.connectedAccountAvatarUrl ?? ensAvatarQuery.data; + const avatarContent = ( - {ensAvatarQuery.data ? ( + {avatarSrc ? ( - - - {activeWallet && ( - - )} - - + + {activeWallet && ( + + )} + + + ) : null} ); @@ -465,7 +469,7 @@ function DetailsModal(props: { }} > - {addressOrENS} + {props.detailsModal?.connectedAccountName ?? addressOrENS}