Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hideDisconnect prop to ConnectWallet #2122

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/empty-pillows-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@thirdweb-dev/react": patch
---

Add `hideDisconnect` prop on `ConnectWallet` component to hide the "Disconnect Wallet" option from the ConnectWallet dropdown

```tsx
<ConnectWallet hideDisconnect={true} />
```
21 changes: 21 additions & 0 deletions packages/react/src/wallet/ConnectWallet/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,18 @@ export type ConnectWalletProps = {
* ```
*/
hideSwitchToPersonalWallet?: boolean;

/**
* Hide the "Disconnect Wallet" button in the ConnectWallet Dropdown.
*
* By default it is `false`
*
* @example
* ```tsx
* <ConnectWallet hideDisconnect={true} />
* ```
*/
hideDisconnect?: boolean;
};

const TW_CONNECT_WALLET = "tw-connect-wallet";
Expand Down Expand Up @@ -535,6 +547,14 @@ const TW_CONNECT_WALLET = "tw-connect-wallet";
* <ConnectWallet hideSwitchToPersonalWallet={true} />
* ```
*
* ### hideDisconnect
* Hide the "Disconnect Wallet" button in the ConnectWallet dropdown
*
* By default it is `false`
*
* ```tsx
* <ConnectWallet hideDisconnect={true} />
* ```
*/
export function ConnectWallet(props: ConnectWalletProps) {
const activeWallet = useWallet();
Expand Down Expand Up @@ -732,6 +752,7 @@ export function ConnectWallet(props: ConnectWalletProps) {
}
}}
hideSwitchToPersonalWallet={props.hideSwitchToPersonalWallet}
hideDisconnect={props.hideDisconnect}
/>
);
})()}
Expand Down
33 changes: 18 additions & 15 deletions packages/react/src/wallet/ConnectWallet/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const ConnectedWalletDetails: React.FC<{
supportedTokens: SupportedTokens;
displayBalanceToken?: Record<number, string>;
hideSwitchToPersonalWallet?: boolean;
hideDisconnect?: boolean;
}> = (props) => {
const locale = useTWLocale().connectWallet;
const chain = useChain();
Expand Down Expand Up @@ -331,22 +332,24 @@ export const ConnectedWalletDetails: React.FC<{
</IconButton>
</div>

<ToolTip
tip={locale.disconnectWallet}
side="bottom"
align={"end"}
sideOffset={10}
>
<DisconnectIconButton
type="button"
onClick={() => {
disconnect();
props.onDisconnect();
}}
{!props.hideDisconnect && (
<ToolTip
tip={locale.disconnectWallet}
side="bottom"
align={"end"}
sideOffset={10}
>
<ExitIcon size={iconSize.md} />
</DisconnectIconButton>
</ToolTip>
<DisconnectIconButton
type="button"
onClick={() => {
disconnect();
props.onDisconnect();
}}
>
<ExitIcon size={iconSize.md} />
</DisconnectIconButton>
</ToolTip>
)}
</Container>

{/* row 2 */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const ConnectModalInline = (
| "switchToActiveChain"
| "supportedTokens"
| "hideSwitchToPersonalWallet"
| "hideDisconnect"
> & {
onModalHide?: () => void;
},
Expand Down