Skip to content

Commit b4756cf

Browse files
authored
refactor: account layout and fix error toasts (#60)
* change layout and fix error toasts * auto navigate on connect Signed-off-by: JaeBrian <[email protected]> --------- Signed-off-by: JaeBrian <[email protected]>
1 parent 58495b5 commit b4756cf

File tree

4 files changed

+228
-178
lines changed

4 files changed

+228
-178
lines changed

src/components/WalletConnection.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useWalletStore } from '../stores/walletStore'
2+
import { useNavigate } from 'react-router'
23

34
interface WalletConnectionProps {
45
variant?: 'default' | 'white'
@@ -12,19 +13,26 @@ const WalletConnection = ({
1213
showDescription = false
1314
}: WalletConnectionProps) => {
1415
const { isConnected, connect, disconnect } = useWalletStore()
16+
const navigate = useNavigate()
1517

1618
const handleConnect = async () => {
1719
try {
1820
const walletNames = ['nami', 'eternl', 'flint', 'yoroi', 'gerowallet']
21+
let connected = false
22+
1923
for (const walletName of walletNames) {
20-
try {
21-
await connect(walletName)
24+
const success = await connect(walletName)
25+
if (success) {
2226
console.log(`Connected to ${walletName}`)
27+
connected = true
28+
navigate('/account')
2329
break
24-
} catch (error) {
25-
console.log(`Failed to connect to ${walletName}:`, error)
2630
}
2731
}
32+
33+
if (!connected) {
34+
console.warn('No compatible wallets found. Please install a supported Cardano wallet.')
35+
}
2836
} catch (error) {
2937
console.error('Failed to connect wallet:', error)
3038
}

src/components/WalletModal.tsx

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,92 @@ interface WalletModalProps {
66
}
77

88
const WalletModal = ({ isOpen, onDisconnect }: WalletModalProps) => {
9-
const { balance, enabledWallet, walletAddress } = useWalletStore()
9+
const { balance, enabledWallet, walletAddress, isConnected, connect } = useWalletStore()
1010

1111
if (!isOpen) return null
1212

13+
const handleConnect = async () => {
14+
try {
15+
const walletNames = ['nami', 'eternl', 'flint', 'yoroi', 'gerowallet']
16+
let connected = false
17+
18+
for (const walletName of walletNames) {
19+
const success = await connect(walletName)
20+
if (success) {
21+
connected = true
22+
break
23+
}
24+
}
25+
26+
if (!connected) {
27+
console.warn('No compatible wallets found. Please install a supported Cardano wallet.')
28+
}
29+
} catch (error) {
30+
console.error('Failed to connect wallet:', error)
31+
}
32+
}
33+
1334
return (
1435
<div className="w-full bg-transparent flex justify-end">
1536
<div className="min-w-full sm:min-w-[37.8125rem] px-4 py-8">
1637
<div className="border-1 border-white rounded-md bg-transparent p-6">
17-
<div className="flex justify-between items-start">
18-
{/* Left side */}
19-
<div className="flex flex-col gap-4">
38+
{!isConnected ? (
39+
// Wallet not connected - show connection prompt
40+
<div className="flex flex-col items-start gap-2">
2041
<div className="flex items-center gap-3">
2142
<img
2243
src="/wallet-icon-white.svg"
2344
alt="Wallet"
2445
className="w-8 h-8"
2546
/>
2647
<div className="flex flex-col">
27-
<h3 className="text-white font-medium text-lg">Your Wallet</h3>
28-
<p className="text-white/70 text-sm max-w-[10rem] truncate">{enabledWallet}: {walletAddress}</p>
48+
<h3 className="text-white font-medium text-lg">Connect Wallet</h3>
49+
<p className="text-white/70 text-sm">Connect your wallet to purchase VPN access</p>
2950
</div>
3051
</div>
52+
<div className="text-center">
53+
<p className="text-white text-lg font-bold">0.00 <span className="text-sm font-normal">ADA</span></p>
54+
</div>
3155
<button
32-
onClick={onDisconnect}
33-
className="bg-white text-black px-6 py-2 rounded-lg font-medium w-fit self-start"
56+
onClick={handleConnect}
57+
className="bg-white text-black px-6 py-2 rounded-lg font-medium w-fit"
3458
>
35-
Disconnect
59+
Connect Wallet
3660
</button>
3761
</div>
62+
) : (
63+
// Wallet connected - show wallet info
64+
<div className="flex justify-between items-start">
65+
{/* Left side */}
66+
<div className="flex flex-col gap-4">
67+
<div className="flex items-center gap-3">
68+
<img
69+
src="/wallet-icon-white.svg"
70+
alt="Wallet"
71+
className="w-8 h-8"
72+
/>
73+
<div className="flex flex-col">
74+
<h3 className="text-white font-medium text-lg">Your Wallet</h3>
75+
<p className="text-white/70 text-sm max-w-[10rem] truncate">{enabledWallet}: {walletAddress}</p>
76+
</div>
77+
</div>
78+
<button
79+
onClick={onDisconnect}
80+
className="bg-white text-black px-6 py-2 rounded-lg font-medium w-fit self-start"
81+
>
82+
Disconnect
83+
</button>
84+
</div>
3885

39-
{/* Right side */}
40-
<div className="text-right">
41-
<p className="text-white/70 text-sm mb-2 font-normal">Wallet Balance</p>
42-
<p className="text-white text-2xl font-bold">
43-
{balance || "0.00"} <span className="text-sm font-normal">ADA</span>
44-
</p>
86+
{/* Right side */}
87+
<div className="text-right">
88+
<p className="text-white/70 text-sm mb-2 font-normal">Wallet Balance</p>
89+
<p className="text-white text-2xl font-bold">
90+
{balance || "0.00"} <span className="text-sm font-normal">ADA</span>
91+
</p>
92+
</div>
4593
</div>
46-
</div>
94+
)}
4795
</div>
4896
</div>
4997
</div>

0 commit comments

Comments
 (0)