Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Add a ‘connect more’ menu item to the example app to exercise the `co…
Browse files Browse the repository at this point in the history
…nnect({ silent: false })` case
  • Loading branch information
steveluscher committed Jun 25, 2024
1 parent faee500 commit cf86525
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions examples/react-app/src/components/ConnectWalletMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,16 @@ export function ConnectWalletMenuItem({ onAccountSelect, onDisconnect, onError,
const isPending = isConnecting || isDisconnecting;
const isConnected = wallet.accounts.length > 0;
const [selectedWalletAccount] = useContext(SelectedWalletAccountContext);
const handleClick = useCallback(async () => {
const handleConnectClick = useCallback(async () => {
try {
if (isConnected) {
await disconnect();
onDisconnect(wallet);
} else {
const accounts = await connect();
if (accounts[0]) {
onAccountSelect(accounts[0]);
}
const accounts = await connect();
if (accounts[0]) {
onAccountSelect(accounts[0]);
}
} catch (e) {
onError(e);
}
}, [connect, disconnect, isConnected, onAccountSelect, onDisconnect, onError, wallet]);
}, [connect, onAccountSelect, onError]);
return (
<DropdownMenu.Sub open={!isConnected ? false : undefined}>
<DropdownMenuPrimitive.SubTrigger
Expand All @@ -46,7 +41,7 @@ export function ConnectWalletMenuItem({ onAccountSelect, onDisconnect, onError,
'rt-DropdownMenuSubTrigger',
].join(' ')}
disabled={isPending}
onClick={!isConnected ? handleClick : undefined}
onClick={!isConnected ? handleConnectClick : undefined}
>
<WalletMenuItemContent loading={isPending} wallet={wallet} />
{isConnected ? (
Expand All @@ -71,6 +66,14 @@ export function ConnectWalletMenuItem({ onAccountSelect, onDisconnect, onError,
))}
</DropdownMenu.RadioGroup>
<DropdownMenu.Separator />
<DropdownMenu.Item
onSelect={async e => {
e.preventDefault();
await handleConnectClick();
}}
>
Connect More
</DropdownMenu.Item>
<DropdownMenu.Item
color="red"
onSelect={async e => {
Expand Down

0 comments on commit cf86525

Please sign in to comment.