@@ -27,6 +27,7 @@ import {
2727} from "@/components/ui/sidebar"
2828import { Popover , PopoverContent , PopoverTrigger } from "@/components/ui/popover"
2929import { cn } from "@/lib/utils"
30+ import { useWallet } from "@/hooks/use-wallet"
3031
3132// This is sample data for the sidebar
3233const data = {
@@ -57,14 +58,11 @@ const data = {
5758 title : "Desktop (Online)" ,
5859 status : "online" ,
5960 } ,
60- user : {
61- address : "0x742d...4e89" ,
62- label : "Connect Wallet" ,
63- } ,
6461}
6562
6663export function DashboardSidebar ( { className, ...props } : React . ComponentProps < typeof Sidebar > ) {
6764 const pathname = usePathname ( )
65+ const { walletAddress, isConnected, connectWallet, disconnectWallet } = useWallet ( )
6866
6967 return (
7068 < Sidebar { ...props } className = { cn ( "py-sides" , className ) } >
@@ -141,34 +139,54 @@ export function DashboardSidebar({ className, ...props }: React.ComponentProps<t
141139 < SidebarGroupContent >
142140 < SidebarMenu >
143141 < SidebarMenuItem >
144- < Popover >
145- < PopoverTrigger className = "flex gap-0.5 w-full group cursor-pointer" >
142+ { isConnected && walletAddress ? (
143+ < Popover >
144+ < PopoverTrigger className = "flex gap-0.5 w-full group cursor-pointer" >
145+ < div className = "shrink-0 flex size-14 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground" >
146+ < CreditCardIcon className = "size-8" />
147+ </ div >
148+ < div className = "group/item pl-3 pr-1.5 pt-2 pb-1.5 flex-1 flex bg-sidebar-accent hover:bg-sidebar-accent-active/75 items-center rounded group-data-[state=open]:bg-sidebar-accent-active group-data-[state=open]:hover:bg-sidebar-accent-active group-data-[state=open]:text-sidebar-accent-foreground" >
149+ < div className = "grid flex-1 text-left text-sm leading-tight" >
150+ < span className = "truncate text-xl font-display" >
151+ { `${ walletAddress . slice ( 0 , 6 ) } ...${ walletAddress . slice ( - 4 ) } ` }
152+ </ span >
153+ < span className = "truncate text-xs uppercase opacity-50 group-hover/item:opacity-100 font-mono" >
154+ Connected
155+ </ span >
156+ </ div >
157+ < DotsVerticalIcon className = "ml-auto size-4" />
158+ </ div >
159+ </ PopoverTrigger >
160+ < PopoverContent className = "w-56 p-0" side = "bottom" align = "end" sideOffset = { 4 } >
161+ < div className = "flex flex-col" >
162+ < button
163+ onClick = { ( ) => disconnectWallet ( ) }
164+ className = "flex items-center px-4 py-2 text-sm hover:bg-accent"
165+ >
166+ < CreditCardIcon className = "mr-2 h-4 w-4" />
167+ Disconnect
168+ </ button >
169+ </ div >
170+ </ PopoverContent >
171+ </ Popover >
172+ ) : (
173+ < button
174+ onClick = { ( ) => connectWallet ( ) }
175+ className = "flex gap-0.5 w-full group cursor-pointer"
176+ >
146177 < div className = "shrink-0 flex size-14 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground" >
147178 < CreditCardIcon className = "size-8" />
148179 </ div >
149- < div className = "group/item pl-3 pr-1.5 pt-2 pb-1.5 flex-1 flex bg-sidebar-accent hover:bg-sidebar-accent-active/75 items-center rounded group-data-[state=open]:bg-sidebar-accent-active group-data-[state=open]:hover:bg-sidebar-accent-active group-data-[state=open]:text-sidebar-accent-foreground " >
180+ < div className = "group/item pl-3 pr-1.5 pt-2 pb-1.5 flex-1 flex bg-sidebar-accent hover:bg-sidebar-accent-active/75 items-center rounded" >
150181 < div className = "grid flex-1 text-left text-sm leading-tight" >
151- < span className = "truncate text-xl font-display" > { data . user . label } </ span >
182+ < span className = "truncate text-xl font-display" > Connect Wallet </ span >
152183 < span className = "truncate text-xs uppercase opacity-50 group-hover/item:opacity-100 font-mono" >
153- { data . user . address }
184+ Not Connected
154185 </ span >
155186 </ div >
156- < DotsVerticalIcon className = "ml-auto size-4" />
157- </ div >
158- </ PopoverTrigger >
159- < PopoverContent className = "w-56 p-0" side = "bottom" align = "end" sideOffset = { 4 } >
160- < div className = "flex flex-col" >
161- < button className = "flex items-center px-4 py-2 text-sm hover:bg-accent" >
162- < CreditCardIcon className = "mr-2 h-4 w-4" />
163- Wallet Settings
164- </ button >
165- < button className = "flex items-center px-4 py-2 text-sm hover:bg-accent" >
166- < GearIcon className = "mr-2 h-4 w-4" />
167- Preferences
168- </ button >
169187 </ div >
170- </ PopoverContent >
171- </ Popover >
188+ </ button >
189+ ) }
172190 </ SidebarMenuItem >
173191 </ SidebarMenu >
174192 </ SidebarGroupContent >
0 commit comments