|
3 | 3 | import Image from 'next/image' |
4 | 4 | import React, { useState, useEffect } from 'react' |
5 | 5 | import avatar from '../../public/Images/avatar.png' |
6 | | -import { Copy, LogOut, X } from 'lucide-react' |
7 | | -import { useAccount } from '@starknet-react/core' |
| 6 | +import { Copy, LogOut, X, Power } from 'lucide-react' |
| 7 | +import { useAccount, useDisconnect, useNetwork } from '@starknet-react/core' |
8 | 8 | import { useRouter } from 'next/navigation' |
9 | | -import { useTheme } from '@/app/context/theme-context-provider' |
10 | 9 | import { useWalletAuth } from '@/app/context/wallet-auth-context' |
11 | 10 |
|
12 | 11 | const WalletConnected = ({ address }: { address: string }) => { |
13 | | - const { actualTheme } = useTheme() |
14 | 12 | const [panelOpen, setPanelOpen] = useState(false) |
15 | 13 | const [copied, setCopied] = useState(false) |
16 | 14 | const { address: walletAddress } = useAccount() |
| 15 | + const { disconnect } = useDisconnect() |
| 16 | + const { chain } = useNetwork() |
17 | 17 | const router = useRouter() |
18 | | - const { logout } = useWalletAuth() |
19 | | - // Dummy balance for now |
20 | | - const balance = '0.00' |
| 18 | + const { logout, isAuthenticated, setIsAuthModalOpen } = useWalletAuth() |
21 | 19 |
|
22 | 20 | // Close panel on outside click or ESC |
23 | 21 | useEffect(() => { |
@@ -61,10 +59,14 @@ const WalletConnected = ({ address }: { address: string }) => { |
61 | 59 | } |
62 | 60 |
|
63 | 61 | const handleDisconnect = async () => { |
64 | | - // Use the auth context logout to clear all auth state |
| 62 | + disconnect() |
| 63 | + setPanelOpen(false) |
| 64 | + router.push('/') |
| 65 | + } |
| 66 | + |
| 67 | + const handleLogout = () => { |
65 | 68 | logout() |
66 | 69 | setPanelOpen(false) |
67 | | - router.push('/') // Route to connect wallet page (home) |
68 | 70 | } |
69 | 71 |
|
70 | 72 | return ( |
@@ -102,62 +104,69 @@ const WalletConnected = ({ address }: { address: string }) => { |
102 | 104 | </button> |
103 | 105 | <div className="flex items-center gap-3 mb-4"> |
104 | 106 | <Image src={avatar} alt="avatar" width={40} height={40} /> |
105 | | - <span className="text-lg font-semibold text-theme transition-colors duration-300"> |
106 | | - {(walletAddress || address).slice(0, 6)}... |
107 | | - {(walletAddress || address).slice(-4)} |
108 | | - </span> |
| 107 | + <div className="flex flex-col"> |
| 108 | + <span className="text-lg font-semibold text-theme transition-colors duration-300"> |
| 109 | + {(walletAddress || address).slice(0, 6)}... |
| 110 | + {(walletAddress || address).slice(-4)} |
| 111 | + </span> |
| 112 | + <div className="flex items-center gap-2"> |
| 113 | + <span className="text-xs text-theme-secondary">Network:</span> |
| 114 | + <span className="text-xs text-theme"> |
| 115 | + {chain?.name ?? 'Unknown'} |
| 116 | + </span> |
| 117 | + </div> |
| 118 | + </div> |
109 | 119 | </div> |
110 | | - <div className="flex gap-2 mb-6"> |
111 | | - <button |
112 | | - onClick={handleCopy} |
113 | | - className="p-2 rounded hover:bg-theme-bg-tertiary transition-colors duration-200" |
114 | | - aria-label="Copy address" |
115 | | - > |
116 | | - <Copy className="w-5 h-5 text-primary" /> |
117 | | - </button> |
| 120 | + |
| 121 | + {isAuthenticated ? ( |
| 122 | + <div className="mb-4"> |
| 123 | + <div className="flex gap-2"> |
| 124 | + <button |
| 125 | + onClick={handleCopy} |
| 126 | + className="p-2 rounded hover:bg-theme-bg-tertiary transition-colors duration-200" |
| 127 | + aria-label="Copy address" |
| 128 | + > |
| 129 | + <Copy className="w-5 h-5 text-primary" /> |
| 130 | + </button> |
| 131 | + <button |
| 132 | + onClick={handleLogout} |
| 133 | + className="flex-1 p-2 rounded bg-theme-bg-tertiary border border-theme-border text-theme-secondary hover:bg-theme-bg-secondary hover:text-theme flex items-center justify-center gap-2 transition-colors duration-200" |
| 134 | + > |
| 135 | + <LogOut className="w-5 h-5" /> |
| 136 | + Logout |
| 137 | + </button> |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + ) : ( |
| 141 | + <div className="mb-4"> |
| 142 | + <div className="flex gap-2"> |
| 143 | + <button |
| 144 | + onClick={handleCopy} |
| 145 | + className="p-2 rounded hover:bg-theme-bg-tertiary transition-colors duration-200" |
| 146 | + aria-label="Copy address" |
| 147 | + > |
| 148 | + <Copy className="w-5 h-5 text-primary" /> |
| 149 | + </button> |
| 150 | + <button |
| 151 | + onClick={() => setIsAuthModalOpen(true)} |
| 152 | + className="flex-1 p-2 rounded bg-primary text-white hover:opacity-90 transition-all duration-200" |
| 153 | + > |
| 154 | + Sign In |
| 155 | + </button> |
| 156 | + </div> |
| 157 | + </div> |
| 158 | + )} |
| 159 | + |
| 160 | + <div className="mt-auto flex justify-between gap-2"> |
118 | 161 | <button |
119 | 162 | onClick={handleDisconnect} |
120 | | - className="p-2 rounded bg-theme-bg-tertiary border border-theme-border text-theme-secondary hover:bg-theme-bg-secondary hover:text-theme flex items-center gap-1 transition-colors duration-200" |
121 | | - aria-label="Logout" |
| 163 | + className="flex-1 p-2 rounded border border-theme-border text-theme-secondary hover:bg-theme-bg-tertiary transition-colors duration-200 flex items-center justify-center gap-2" |
122 | 164 | > |
123 | | - <LogOut className="w-5 h-5" /> Logout |
| 165 | + <Power className="w-5 h-5" /> |
| 166 | + Disconnect Wallet |
124 | 167 | </button> |
125 | 168 | </div> |
126 | | - <div className="text-4xl font-bold text-theme mb-2 transition-colors duration-300"> |
127 | | - ${balance} |
128 | | - </div> |
129 | | - <div className="mb-4"> |
130 | | - <span className="text-theme font-semibold transition-colors duration-300"> |
131 | | - Activity |
132 | | - </span> |
133 | | - <span className="ml-2 px-2 py-0.5 rounded-full bg-primary text-xs text-white"> |
134 | | - 0 |
135 | | - </span> |
136 | | - </div> |
137 | | - <div className="flex flex-col items-center justify-center h-40"> |
138 | | - <svg width="48" height="48" fill="none" viewBox="0 0 24 24"> |
139 | | - <rect |
140 | | - width="24" |
141 | | - height="24" |
142 | | - rx="12" |
143 | | - fill={actualTheme === 'dark' ? '#292929' : '#e2e8f0'} |
144 | | - /> |
145 | | - <path |
146 | | - d="M8 17V15.5C8 14.1193 9.11929 13 10.5 13H13.5C14.8807 13 16 14.1193 16 15.5V17" |
147 | | - stroke="#A78BFA" |
148 | | - strokeWidth="1.5" |
149 | | - strokeLinecap="round" |
150 | | - strokeLinejoin="round" |
151 | | - /> |
152 | | - <circle cx="12" cy="9" r="2" stroke="#A78BFA" strokeWidth="1.5" /> |
153 | | - </svg> |
154 | | - <p className="text-theme-secondary text-center mt-2 transition-colors duration-300"> |
155 | | - Transactions you send from the app will appear here. |
156 | | - </p> |
157 | | - </div> |
158 | | - <button className="w-full mt-4 bg-primary text-white py-2 rounded-lg font-semibold hover:opacity-90 transition-all duration-200"> |
159 | | - Create a position |
160 | | - </button> |
| 169 | + |
161 | 170 | {copied && ( |
162 | 171 | <div className="absolute top-2 right-16 bg-primary text-white px-2 py-1 rounded shadow-lg"> |
163 | 172 | Copied! |
|
0 commit comments