Skip to content

Commit cd5ea3d

Browse files
authored
Merge pull request #584 from Buks05/fix/issue-548-wallet-connection-ui
feat: add wallet connection UI with address display
2 parents 6907383 + 94acf5e commit cd5ea3d

1 file changed

Lines changed: 71 additions & 20 deletions

File tree

src/components/common/ConnectWalletButton.tsx

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { useEffect, useRef, useState } from 'react';
22
import { useAccount, useConnect, useDisconnect } from 'wagmi';
33
import { Copy, Check } from 'lucide-react';
4+
import {
5+
Dialog,
6+
DialogClose,
7+
DialogContent,
8+
DialogDescription,
9+
DialogFooter,
10+
DialogHeader,
11+
DialogTitle,
12+
} from '@/components/ui/dialog';
13+
import { Button } from '@/components/ui/button';
414
import {
515
Popover,
616
PopoverContent,
@@ -21,6 +31,7 @@ function ConnectWalletButton() {
2131
const [showAddressPopover, setShowAddressPopover] = useState(false);
2232
const [copied, setCopied] = useState(false);
2333
const connectedAtRef = useRef<number | null>(null);
34+
const [showDisconnectDialog, setShowDisconnectDialog] = useState(false);
2435
const { address, isConnected } = useAccount();
2536
const { connect, connectors, error, isPending } = useConnect();
2637
const { disconnect } = useDisconnect();
@@ -74,41 +85,45 @@ function ConnectWalletButton() {
7485
{shortenAddress(address)}
7586
</button>
7687
</PopoverTrigger>
77-
<PopoverContent className="w-80">
78-
<div className="space-y-3">
79-
<div className="space-y-1">
80-
<p className="text-xs font-medium text-muted-foreground">
81-
Wallet address
88+
<PopoverContent align="end" className="w-80">
89+
<div className="flex flex-col gap-3">
90+
<div className="flex items-center justify-between">
91+
<span className="text-sm font-medium text-gray-900">
92+
Connected Wallet
93+
</span>
94+
<button
95+
type="button"
96+
onClick={() => setShowAddressPopover(false)}
97+
className="text-gray-400 hover:text-gray-600"
98+
>
99+
×
100+
</button>
101+
</div>
102+
<div className="rounded-md bg-gray-100 p-3">
103+
<p className="font-mono text-xs break-all text-gray-700">
104+
{address}
82105
</p>
83-
<p className="break-all font-mono text-sm">{address}</p>
84106
</div>
85-
<div className="flex items-center gap-2">
107+
<div className="flex gap-2">
86108
<button
87109
type="button"
88110
onClick={handleCopyAddress}
89-
className="inline-flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-700"
111+
className="flex flex-1 items-center justify-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50"
90112
>
91113
{copied ? (
92-
<Check className="size-3.5" aria-hidden="true" />
114+
<Check className="size-4 text-emerald-500" />
93115
) : (
94-
<Copy className="size-3.5" aria-hidden="true" />
116+
<Copy className="size-4" />
95117
)}
96-
{copied ? 'Copied' : 'Copy address'}
118+
{copied ? 'Copied!' : 'Copy Address'}
97119
</button>
98120
<button
99121
type="button"
100122
onClick={() => {
101-
if (connectedAtRef.current != null) {
102-
logWalletDisconnectSession(
103-
address,
104-
connectedAtRef.current
105-
);
106-
}
107-
disconnect();
108-
connectedAtRef.current = null;
109123
setShowAddressPopover(false);
124+
setShowDisconnectDialog(true);
110125
}}
111-
className="rounded-md px-3 py-1.5 text-xs font-medium text-red-600 transition-colors hover:bg-red-50"
126+
className="flex-1 rounded-md border border-red-200 bg-white px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50"
112127
>
113128
Disconnect
114129
</button>
@@ -117,6 +132,42 @@ function ConnectWalletButton() {
117132
</PopoverContent>
118133
</Popover>
119134
</div>
135+
<Dialog
136+
open={showDisconnectDialog}
137+
onOpenChange={setShowDisconnectDialog}
138+
>
139+
<DialogContent>
140+
<DialogHeader>
141+
<DialogTitle>Disconnect wallet?</DialogTitle>
142+
<DialogDescription>
143+
Disconnecting clears your current wallet session and any
144+
pending wallet state. You will need to reconnect to
145+
continue.
146+
</DialogDescription>
147+
</DialogHeader>
148+
<DialogFooter>
149+
<DialogClose asChild>
150+
<Button variant="outline">Cancel</Button>
151+
</DialogClose>
152+
<Button
153+
type="button"
154+
variant="destructive"
155+
onClick={() => {
156+
if (connectedAtRef.current != null) {
157+
logWalletDisconnectSession(
158+
address,
159+
connectedAtRef.current
160+
);
161+
}
162+
disconnect();
163+
setShowDisconnectDialog(false);
164+
}}
165+
>
166+
Disconnect
167+
</Button>
168+
</DialogFooter>
169+
</DialogContent>
170+
</Dialog>
120171
<CopySuccessAnnouncement message={announcement} />
121172
</>
122173
);

0 commit comments

Comments
 (0)