forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRightPanel.tsx
More file actions
158 lines (144 loc) · 5.1 KB
/
Copy pathRightPanel.tsx
File metadata and controls
158 lines (144 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import React, { useRef, useEffect, useState } from 'react';
import { Wallet, Box, X, BrainCircuit, MessageSquare } from 'lucide-react';
import { Network, ActivityLog, Comment } from '../../types';
import { getOwnedObjects } from '../../services/suiService';
import { useWallet } from '@/wallet';
import {
WalletTab,
ObjectsTab,
AnalysisTab,
DiscussTab,
} from './Tabs';
interface RightPanelProps {
network: Network;
activityLogs: ActivityLog[];
comments: Comment[];
activeRequestId: string;
onPostComment: (content: string) => void;
onClose: () => void;
}
export const RightPanel: React.FC<RightPanelProps> = ({
network,
activityLogs,
comments,
onPostComment,
onClose
}) => {
const [activeTab, setActiveTab] = useState<'wallet' | 'objects' | 'analysis' | 'discuss'>('wallet');
const [objects, setObjects] = useState<any[]>([]);
const [loadingObjects, setLoadingObjects] = useState(false);
const [commentInput, setCommentInput] = useState('');
const { currentWallet } = useWallet();
const connectedAddress = currentWallet?.family === 'sui' ? currentWallet.address : null;
const formatAddress = (address: string) => {
return `${address.slice(0, 6)}...${address.slice(-4)}`;
};
const fetchObjects = async () => {
if (!connectedAddress) return;
setLoadingObjects(true);
try {
const res = await getOwnedObjects(network, connectedAddress);
if (res.result && res.result.data) {
setObjects(res.result.data);
} else {
setObjects([]);
}
} catch (e) {
setObjects([]);
} finally {
setLoadingObjects(false);
}
};
useEffect(() => {
if (activeTab === 'objects' && connectedAddress) {
fetchObjects();
}
}, [activeTab, connectedAddress, network]);
const submitComment = (e: React.FormEvent) => {
e.preventDefault();
if (commentInput.trim()) {
onPostComment(commentInput);
setCommentInput('');
}
};
const TabButton = ({ id, icon: Icon, label }: { id: typeof activeTab, icon: any, label: string }) => (
<button
onClick={() => setActiveTab(id)}
className={`flex-1 flex flex-col items-center justify-center py-2 gap-1 transition-colors relative ${
activeTab === id
? 'text-electric-violet'
: 'text-slate-500 hover:text-slate-300 hover:bg-white/[0.03]'
}`}
title={label}
>
<Icon size={15} strokeWidth={activeTab === id ? 2.25 : 1.75} />
<span className="text-[10px] font-medium">{label}</span>
{activeTab === id && (
<span className="absolute bottom-0 left-0 right-0 h-px bg-electric-violet"></span>
)}
</button>
);
return (
<div className="w-80 bg-near-black border-l border-white/[0.06] flex flex-col h-full font-sans relative z-30">
{/* Header */}
<div className="shrink-0 flex items-center justify-between px-3 py-2 border-b border-white/[0.06] bg-dark-indigo-glow">
<div className="flex items-center gap-2">
<span className="text-[11px] font-semibold text-slate-300 tracking-tight">Inspector</span>
<div className={`px-1.5 py-0.5 rounded-full text-[10px] font-medium ${
network === 'mainnet' ? 'bg-emerald-500/[0.12] text-emerald-400' :
network === 'testnet' ? 'bg-amber-500/[0.12] text-amber-400' :
'bg-blue-500/[0.12] text-blue-400'
}`}>
{network}
</div>
</div>
<button
onClick={onClose}
className="p-1 text-slate-500 hover:text-slate-200 rounded hover:bg-white/[0.05] transition-colors"
aria-label="Close inspector"
>
<X size={13} />
</button>
</div>
{/* Navigation */}
<div className="shrink-0 flex border-b border-white/[0.06] bg-near-black">
<TabButton id="wallet" icon={Wallet} label="Wallet" />
<TabButton id="objects" icon={Box} label="Objects" />
<TabButton id="analysis" icon={BrainCircuit} label="Analysis" />
<TabButton id="discuss" icon={MessageSquare} label="Discuss" />
</div>
<div className="flex-1 flex flex-col min-h-0 relative">
{/* --- WALLET TAB --- */}
{activeTab === 'wallet' && (
<WalletTab
formatAddress={formatAddress}
/>
)}
{/* --- OBJECTS TAB --- */}
{activeTab === 'objects' && (
<div className="flex-1 flex flex-col min-h-0 bg-near-black">
<ObjectsTab
connectedAddress={connectedAddress}
walletFamily={currentWallet?.family || null}
network={network}
objects={objects}
loadingObjects={loadingObjects}
onRefreshObjects={fetchObjects}
/>
</div>
)}
{/* --- ANALYSIS TAB --- */}
{activeTab === 'analysis' && <AnalysisTab />}
{/* --- DISCUSS TAB --- */}
{activeTab === 'discuss' && (
<DiscussTab
comments={comments}
commentInput={commentInput}
onCommentInputChange={setCommentInput}
onSubmitComment={submitComment}
/>
)}
</div>
</div>
);
};