Skip to content

Commit

Permalink
react: add overrides for connected wallet name and avatar in details …
Browse files Browse the repository at this point in the history
…button and modal (#4271)

Co-authored-by: Joaquim Verges <[email protected]>
  • Loading branch information
alecananian and joaquim-verges authored Aug 28, 2024
1 parent db2ee85 commit fcf8f89
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-dots-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Added overrides for connected wallet name and avatar in details button and modal
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ export type ConnectButton_detailsModalOptions = {
* thirdweb Pay allows users to buy tokens using crypto or fiat currency.
*/
payOptions?: Extract<PayUIOptions, { mode?: "fund_wallet" }>;

/**
* 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;
};

/**
Expand Down Expand Up @@ -325,6 +335,16 @@ export type ConnectButton_detailsButtonOptions = {
* ```
*/
displayBalanceToken?: Record<number, string>;

/**
* 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;
};

/**
Expand Down
91 changes: 54 additions & 37 deletions packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export const ConnectedWalletDetails: React.FC<{
);
}

const avatarSrc =
props.detailsButton?.connectedAccountAvatarUrl ?? ensAvatarQuery.data;

return (
<WalletInfoButton
type="button"
Expand All @@ -203,10 +206,10 @@ export const ConnectedWalletDetails: React.FC<{
height: "35px",
}}
>
{ensAvatarQuery.data ? (
{avatarSrc ? (
<img
alt=""
src={ensAvatarQuery.data}
src={avatarSrc}
style={{
width: "100%",
height: "100%",
Expand All @@ -226,18 +229,14 @@ export const ConnectedWalletDetails: React.FC<{
}}
>
{/* Address */}
{addressOrENS ? (
<Text
size="xs"
color="primaryText"
weight={500}
className={`${TW_CONNECTED_WALLET}__address`}
>
{addressOrENS}
</Text>
) : (
<Skeleton height={fontSize.xs} width="80px" />
)}
<Text
size="xs"
color="primaryText"
weight={500}
className={`${TW_CONNECTED_WALLET}__address`}
>
{props.detailsButton?.connectedAccountName ?? addressOrENS}
</Text>

{/* Balance */}
{balanceQuery.data ? (
Expand Down Expand Up @@ -371,6 +370,9 @@ function DetailsModal(props: {
</MenuButton>
);

const avatarSrc =
props.detailsModal?.connectedAccountAvatarUrl ?? ensAvatarQuery.data;

const avatarContent = (
<Container
style={{
Expand All @@ -387,9 +389,9 @@ function DetailsModal(props: {
overflow: "hidden",
}}
>
{ensAvatarQuery.data ? (
{avatarSrc ? (
<img
src={ensAvatarQuery.data}
src={avatarSrc}
style={{
width: iconSize.xxl,
height: iconSize.xxl,
Expand All @@ -405,29 +407,31 @@ function DetailsModal(props: {
)
)}
</Container>
<Container
style={{
position: "absolute",
bottom: -2,
right: -2,
}}
>
<IconContainer
{!props.detailsModal?.hideSwitchWallet ? (
<Container
style={{
background: theme.colors.modalBg,
position: "absolute",
bottom: -2,
right: -2,
}}
padding="4px"
>
{activeWallet && (
<WalletImage
style={{ borderRadius: 0 }}
id={activeWallet.id}
client={client}
size="12"
/>
)}
</IconContainer>
</Container>
<IconContainer
style={{
background: theme.colors.modalBg,
}}
padding="4px"
>
{activeWallet && (
<WalletImage
style={{ borderRadius: 0 }}
id={activeWallet.id}
client={client}
size="12"
/>
)}
</IconContainer>
</Container>
) : null}
</Container>
);

Expand Down Expand Up @@ -465,7 +469,7 @@ function DetailsModal(props: {
}}
>
<Text color="primaryText" weight={500} size="md">
{addressOrENS}
{props.detailsModal?.connectedAccountName ?? addressOrENS}
</Text>
<IconButton>
<CopyIcon
Expand Down Expand Up @@ -1039,6 +1043,7 @@ function InAppWalletUserInfo(props: {

return email || phone || null;
},
enabled: !isSmartWallet,
});

if (isSmartWallet) {
Expand Down Expand Up @@ -1330,6 +1335,16 @@ export type UseWalletDetailsModalOptions = {
* Options to configure the Connect UI shown when user clicks the "Connect Wallet" button in the Wallet Switcher screen.
*/
connectOptions?: DetailsModalConnectOptions;

/**
* 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;
};

/**
Expand Down Expand Up @@ -1382,6 +1397,8 @@ export function useWalletDetailsModal() {
networkSelector: props.networkSelector,
payOptions: props.payOptions,
showTestnetFaucet: props.showTestnetFaucet,
connectedAccountName: props.connectedAccountName,
connectedAccountAvatarUrl: props.connectedAccountAvatarUrl,
}}
displayBalanceToken={props.displayBalanceToken}
theme={props.theme || "dark"}
Expand Down

0 comments on commit fcf8f89

Please sign in to comment.