Skip to content

Commit 6f5522f

Browse files
committed
updated
1 parent 7200ac1 commit 6f5522f

File tree

7 files changed

+1152
-2144
lines changed

7 files changed

+1152
-2144
lines changed

client/app/layout.tsx

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
1-
import type { Metadata } from "next";
2-
import "./globals.css";
3-
import ErrorReporter from "@/components/ErrorReporter";
4-
import Script from "next/script";
5-
import { Toaster } from "@/components/ui/sonner";
1+
import type { Metadata } from 'next'
2+
import './globals.css'
3+
import { Toaster } from 'sonner'
64

75
export const metadata: Metadata = {
8-
title: "Tavarn.AI - The Smartest Trader on Somnia",
9-
description: "AI-powered gaming marketplace where prices evolve with demand",
10-
};
6+
title: 'Tavarn.AI',
7+
description: 'AI Trading Platform',
8+
}
119

1210
export default function RootLayout({
1311
children,
14-
}: Readonly<{
15-
children: React.ReactNode;
16-
}>) {
12+
}: {
13+
children: React.ReactNode
14+
}) {
1715
return (
1816
<html lang="en">
19-
<body className="antialiased">
20-
<ErrorReporter />
21-
<Script
22-
src="https://slelguoygbfzlpylpxfs.supabase.co/storage/v1/object/public/scripts//route-messenger.js"
23-
strategy="afterInteractive"
24-
data-target-origin="*"
25-
data-message-type="ROUTE_CHANGE"
26-
data-include-search-params="true"
27-
data-only-in-iframe="true"
28-
data-debug="true"
29-
data-custom-data='{"appName": "YourApp", "version": "1.0.0", "greeting": "hi"}'
30-
/>
17+
<body>
3118
{children}
32-
<Toaster position="top-right" theme="dark" />
19+
<Toaster
20+
position="top-right"
21+
richColors
22+
closeButton
23+
theme="dark"
24+
/>
3325
</body>
3426
</html>
35-
);
36-
}
27+
)
28+
}

client/components/Navigation.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function Navigation() {
1515
const [cartDrawerOpen, setCartDrawerOpen] = useState(false)
1616
const [cartCount, setCartCount] = useState(0)
1717
const [walletConnected, setWalletConnected] = useState(false)
18+
const [walletAddress, setWalletAddress] = useState('')
1819

1920
useEffect(() => {
2021
// Check cart count
@@ -24,22 +25,33 @@ export default function Navigation() {
2425
// Check wallet connection
2526
const wallet = localStorage.getItem('wallet_address')
2627
setWalletConnected(!!wallet)
28+
setWalletAddress(wallet || '')
2729

2830
// Listen for storage changes
2931
const handleStorage = () => {
3032
const cart = JSON.parse(localStorage.getItem('cart') || '[]')
3133
setCartCount(cart.length)
3234
const wallet = localStorage.getItem('wallet_address')
3335
setWalletConnected(!!wallet)
36+
setWalletAddress(wallet || '')
37+
}
38+
39+
// Listen for wallet updates
40+
const handleWalletUpdate = () => {
41+
const wallet = localStorage.getItem('wallet_address')
42+
setWalletConnected(!!wallet)
43+
setWalletAddress(wallet || '')
3444
}
3545

3646
window.addEventListener('storage', handleStorage)
3747
// Custom event for same-tab updates
3848
window.addEventListener('cartUpdated', handleStorage)
39-
49+
window.addEventListener('walletUpdated', handleWalletUpdate)
50+
4051
return () => {
4152
window.removeEventListener('storage', handleStorage)
4253
window.removeEventListener('cartUpdated', handleStorage)
54+
window.removeEventListener('walletUpdated', handleWalletUpdate)
4355
}
4456
}, [])
4557

@@ -80,9 +92,17 @@ export default function Navigation() {
8092

8193
{/* Desktop Actions */}
8294
<div className="hidden md:flex items-center space-x-3 lg:space-x-4">
83-
<Button
84-
variant="ghost"
85-
size="icon"
95+
{walletConnected && walletAddress && (
96+
<div className="flex items-center space-x-2 px-3 py-1 glass-effect rounded-lg border border-primary/30">
97+
<Wallet className="h-4 w-4 text-primary" />
98+
<span className="text-sm font-mono text-primary">
99+
{walletAddress.slice(0, 6)}...{walletAddress.slice(-4)}
100+
</span>
101+
</div>
102+
)}
103+
<Button
104+
variant="ghost"
105+
size="icon"
86106
className="relative"
87107
onClick={() => setCartDrawerOpen(true)}
88108
>
@@ -93,16 +113,16 @@ export default function Navigation() {
93113
</span>
94114
)}
95115
</Button>
96-
<Button
97-
variant="outline"
116+
<Button
117+
variant="outline"
98118
className="neon-border text-sm lg:text-base"
99119
onClick={() => setWalletDialogOpen(true)}
100120
>
101121
<Wallet className="h-4 w-4 mr-2" />
102122
{walletConnected ? 'Connected' : 'Connect Wallet'}
103123
</Button>
104-
<Button
105-
variant="ghost"
124+
<Button
125+
variant="ghost"
106126
size="icon"
107127
onClick={() => setProfileDialogOpen(true)}
108128
>

client/components/ProfileDialog.jsx

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export default function ProfileDialog({ open, onOpenChange }) {
6969

7070
if (isLoggedIn) {
7171
const user = JSON.parse(localStorage.getItem('user') || '{}')
72+
const connectedWallets = JSON.parse(localStorage.getItem('connected_wallets') || '[]')
73+
const currentWallet = localStorage.getItem('wallet_address')
74+
7275
return (
7376
<Dialog open={open} onOpenChange={onOpenChange}>
7477
<DialogContent className="sm:max-w-md glass-effect border-primary/20">
@@ -80,7 +83,7 @@ export default function ProfileDialog({ open, onOpenChange }) {
8083
Manage your account and settings
8184
</DialogDescription>
8285
</DialogHeader>
83-
86+
8487
<div className="space-y-4 mt-4">
8588
<div className="p-4 glass-effect rounded-lg">
8689
<div className="flex items-center space-x-3">
@@ -94,15 +97,98 @@ export default function ProfileDialog({ open, onOpenChange }) {
9497
</div>
9598
</div>
9699

100+
{/* Connected Wallets Section */}
101+
<div className="space-y-3">
102+
<h3 className="text-lg font-semibold" style={{ fontFamily: 'Rajdhani, sans-serif' }}>
103+
Connected Wallets
104+
</h3>
105+
{connectedWallets.length > 0 ? (
106+
<div className="space-y-2">
107+
{connectedWallets.map((wallet, index) => (
108+
<div
109+
key={index}
110+
className={`p-3 glass-effect rounded-lg border ${
111+
wallet === currentWallet ? 'border-primary' : 'border-primary/20'
112+
}`}
113+
>
114+
<div className="flex items-center justify-between">
115+
<div className="flex items-center space-x-2">
116+
<div className="w-8 h-8 rounded-full bg-primary/20 flex items-center justify-center">
117+
<User className="h-4 w-4" />
118+
</div>
119+
<div>
120+
<div className="text-sm font-mono">
121+
{wallet.slice(0, 6)}...{wallet.slice(-4)}
122+
</div>
123+
{wallet === currentWallet && (
124+
<div className="text-xs text-primary">Currently Active</div>
125+
)}
126+
</div>
127+
</div>
128+
<div className="flex items-center space-x-2">
129+
<Button
130+
size="sm"
131+
variant="ghost"
132+
onClick={() => {
133+
localStorage.setItem('wallet_address', wallet)
134+
window.dispatchEvent(new Event('walletUpdated'))
135+
toast.success('Switched to wallet: ' + wallet.slice(0, 6) + '...' + wallet.slice(-4))
136+
}}
137+
disabled={wallet === currentWallet}
138+
className="text-xs"
139+
>
140+
{wallet === currentWallet ? 'Active' : 'Switch'}
141+
</Button>
142+
<Button
143+
size="sm"
144+
variant="ghost"
145+
onClick={() => {
146+
const newAddress = prompt('Enter new wallet address:', wallet)
147+
if (newAddress && newAddress !== wallet) {
148+
// Validate new address
149+
if (!/^0x[a-fA-F0-9]{40}$/.test(newAddress)) {
150+
toast.error('Invalid Ethereum address format')
151+
return
152+
}
153+
154+
// Update in connected wallets array
155+
const updatedWallets = connectedWallets.map(w => w === wallet ? newAddress : w)
156+
localStorage.setItem('connected_wallets', JSON.stringify(updatedWallets))
157+
158+
// Update current wallet if it was the one being edited
159+
if (wallet === currentWallet) {
160+
localStorage.setItem('wallet_address', newAddress)
161+
}
162+
163+
window.dispatchEvent(new Event('walletUpdated'))
164+
toast.success('Wallet address updated successfully')
165+
}
166+
}}
167+
className="text-xs text-muted-foreground hover:text-primary"
168+
>
169+
Edit
170+
</Button>
171+
</div>
172+
</div>
173+
</div>
174+
))}
175+
</div>
176+
) : (
177+
<div className="p-4 glass-effect rounded-lg border border-dashed border-primary/30 text-center">
178+
<p className="text-sm text-muted-foreground">No wallets connected yet</p>
179+
</div>
180+
)}
181+
</div>
182+
97183
<Link href="/dashboard">
98184
<Button className="w-full neon-border" onClick={() => onOpenChange(false)}>
99185
Go to Dashboard
100186
</Button>
101187
</Link>
102188

103-
<Button
189+
<Button
104190
onClick={handleLogout}
105-
variant="outline"
191+
variant="outline"
106192
className="w-full neon-border"
107193
>
108194
Logout

client/components/WalletConnectDialog.tsx

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { useState } from 'react'
3+
import { useState, useEffect } from 'react'
44
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
55
import { Button } from '@/components/ui/button'
66
import { Input } from '@/components/ui/input'
@@ -17,22 +17,48 @@ export default function WalletConnectDialog({ open, onOpenChange }: WalletConnec
1717
const [walletAddress, setWalletAddress] = useState('')
1818
const [isConnecting, setIsConnecting] = useState(false)
1919
const [isConnected, setIsConnected] = useState(false)
20+
const [isLoggedIn, setIsLoggedIn] = useState(false)
21+
22+
useEffect(() => {
23+
// Check if user is logged in (client-side only)
24+
setIsLoggedIn(!!localStorage.getItem('user'))
25+
}, [])
26+
27+
const isValidEthereumAddress = (address: string) => {
28+
return /^0x[a-fA-F0-9]{40}$/.test(address)
29+
}
2030

2131
const handleConnect = async () => {
22-
if (!walletAddress || walletAddress.length < 42) {
23-
toast.error('Please enter a valid wallet address')
32+
if (!isLoggedIn) {
33+
toast.error('Please create an account first before connecting a wallet')
34+
return
35+
}
36+
37+
if (!walletAddress || !isValidEthereumAddress(walletAddress)) {
38+
toast.error('Please enter a valid Ethereum wallet address (42 characters, starting with 0x)')
2439
return
2540
}
2641

2742
setIsConnecting(true)
28-
43+
2944
// Simulate connection
3045
setTimeout(() => {
3146
setIsConnecting(false)
3247
setIsConnected(true)
3348
localStorage.setItem('wallet_address', walletAddress)
49+
50+
// Add to connected wallets list
51+
const connectedWallets = JSON.parse(localStorage.getItem('connected_wallets') || '[]')
52+
if (!connectedWallets.includes(walletAddress)) {
53+
connectedWallets.push(walletAddress)
54+
localStorage.setItem('connected_wallets', JSON.stringify(connectedWallets))
55+
}
56+
57+
// Dispatch custom event to update Navigation
58+
window.dispatchEvent(new Event('walletUpdated'))
59+
3460
toast.success('Wallet connected successfully!')
35-
61+
3662
setTimeout(() => {
3763
onOpenChange(false)
3864
setIsConnected(false)
@@ -42,16 +68,32 @@ export default function WalletConnectDialog({ open, onOpenChange }: WalletConnec
4268
}
4369

4470
const handleMetaMaskConnect = async () => {
71+
if (!isLoggedIn) {
72+
toast.error('Please create an account first before connecting a wallet')
73+
return
74+
}
75+
4576
if (typeof window.ethereum !== 'undefined') {
4677
try {
4778
setIsConnecting(true)
4879
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' })
4980
if (accounts[0]) {
5081
setWalletAddress(accounts[0])
5182
localStorage.setItem('wallet_address', accounts[0])
83+
84+
// Add to connected wallets list
85+
const connectedWallets = JSON.parse(localStorage.getItem('connected_wallets') || '[]')
86+
if (!connectedWallets.includes(accounts[0])) {
87+
connectedWallets.push(accounts[0])
88+
localStorage.setItem('connected_wallets', JSON.stringify(connectedWallets))
89+
}
90+
91+
// Dispatch custom event to update Navigation
92+
window.dispatchEvent(new Event('walletUpdated'))
93+
5294
setIsConnected(true)
5395
toast.success('Wallet connected via MetaMask!')
54-
96+
5597
setTimeout(() => {
5698
onOpenChange(false)
5799
setIsConnected(false)

0 commit comments

Comments
 (0)