Skip to content

Commit bd0a4db

Browse files
committed
add table component to solana
Signed-off-by: nidhi-singh02 <[email protected]>
1 parent b862a21 commit bd0a4db

File tree

2 files changed

+455
-64
lines changed

2 files changed

+455
-64
lines changed

components/SponsoredFeedsTable.tsx

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@ interface SponsoredFeed {
55
name: string;
66
priceFeedId: string;
77
updateParameters: string;
8+
accountAddress?: string; // Optional field for Solana
89
}
910

1011
interface SponsoredFeedsTableProps {
1112
feeds: SponsoredFeed[];
1213
networkName: string;
14+
showAccountAddress?: boolean; // Optional prop to show account address column
1315
}
1416

1517
export const SponsoredFeedsTable = ({
1618
feeds,
1719
networkName,
20+
showAccountAddress = false,
1821
}: SponsoredFeedsTableProps) => {
1922
const [copiedId, setCopiedId] = useState<string | null>(null);
2023

21-
const copyToClipboard = (text: string) => {
24+
const copyToClipboard = (
25+
text: string,
26+
type: "priceFeedId" | "accountAddress" = "priceFeedId"
27+
) => {
2228
navigator.clipboard.writeText(text).then(() => {
23-
setCopiedId(text);
29+
setCopiedId(`${type}-${text}`);
2430
setTimeout(() => setCopiedId(null), 2000);
2531
});
2632
};
@@ -41,11 +47,18 @@ export const SponsoredFeedsTable = ({
4147
// Show 7 rows by default, then scroll - but maintain consistent minimum height
4248
const maxVisibleRows = 7;
4349
const shouldScroll = feeds.length > maxVisibleRows;
44-
const rowHeight = 56; // Increased row height to account for actual content height
50+
const rowHeight = showAccountAddress ? 78 : 62; // Match actualRowHeight for consistency
4551
const headerHeight = 48; // Header height in pixels
4652
const exactTableHeight = `${headerHeight + maxVisibleRows * rowHeight}px`; // Exact height for 7 rows
4753
const tableHeight = shouldScroll ? exactTableHeight : "auto"; // Use exact height for scrollable tables
4854

55+
// Calculate actual visible rows based on table height
56+
// Different layouts have different row heights due to content wrapping
57+
const actualRowHeight = showAccountAddress ? 78 : 62; // Solana (4 cols) vs EVM (3 cols)
58+
const actualVisibleRows = shouldScroll
59+
? Math.floor((parseInt(exactTableHeight) - headerHeight) / actualRowHeight)
60+
: Math.min(feeds.length, maxVisibleRows);
61+
4962
return (
5063
<div className="my-6">
5164
<p className="mb-3">
@@ -87,21 +100,38 @@ export const SponsoredFeedsTable = ({
87100
</div>
88101

89102
{/* Table */}
90-
<div className="overflow-x-auto">
103+
<div>
91104
<div
92105
className={`${shouldScroll ? "overflow-y-auto" : ""}`}
93106
style={{ height: tableHeight }}
94107
>
95-
<table className="w-full text-sm min-w-full">
108+
<table className="w-full text-sm table-fixed">
96109
<thead className="sticky top-0 bg-gray-50 dark:bg-gray-800 z-30">
97110
<tr>
98-
<th className="text-left px-3 py-2 font-semibold text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-600 min-w-[100px]">
111+
<th className="text-left px-3 py-2 font-semibold text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-600 w-[15%] min-w-[120px]">
99112
Name
100113
</th>
101-
<th className="text-left px-3 py-2 font-semibold text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-600 min-w-[400px]">
114+
{showAccountAddress && (
115+
<th className="text-left px-3 py-2 font-semibold text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-600 w-[30%] min-w-[280px]">
116+
Account Address
117+
</th>
118+
)}
119+
<th
120+
className={`text-left px-3 py-2 font-semibold text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-600 ${
121+
showAccountAddress
122+
? "w-[35%] min-w-[320px]"
123+
: "w-[60%] min-w-[400px]"
124+
}`}
125+
>
102126
Price Feed Id
103127
</th>
104-
<th className="text-left px-3 py-2 font-semibold text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-600 min-w-[200px]">
128+
<th
129+
className={`text-left px-3 py-2 font-semibold text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-600 ${
130+
showAccountAddress
131+
? "w-[20%] min-w-[180px]"
132+
: "w-[25%] min-w-[200px]"
133+
}`}
134+
>
105135
Update Parameters
106136
</th>
107137
</tr>
@@ -128,6 +158,36 @@ export const SponsoredFeedsTable = ({
128158
{feed.name}
129159
</span>
130160
</td>
161+
{showAccountAddress && (
162+
<td className="px-3 py-2 align-top">
163+
<div className="flex items-start gap-2">
164+
<code className="text-xs font-mono text-gray-600 dark:text-gray-400 flex-1 break-all leading-relaxed">
165+
{feed.accountAddress || "N/A"}
166+
</code>
167+
{feed.accountAddress && (
168+
<button
169+
onClick={() =>
170+
copyToClipboard(
171+
feed.accountAddress!,
172+
"accountAddress"
173+
)
174+
}
175+
className="p-1 hover:bg-gray-200 dark:hover:bg-gray-600 rounded flex-shrink-0 mt-0.5"
176+
title="Copy Account Address"
177+
>
178+
{copiedId ===
179+
`accountAddress-${feed.accountAddress}` ? (
180+
<span className="text-green-500 text-xs font-bold">
181+
182+
</span>
183+
) : (
184+
<CopyIcon className="w-3 h-3 text-gray-400" />
185+
)}
186+
</button>
187+
)}
188+
</div>
189+
</td>
190+
)}
131191
<td className="px-3 py-2 align-top">
132192
<div className="flex items-start gap-2">
133193
<code className="text-xs font-mono text-gray-600 dark:text-gray-400 flex-1 break-all leading-relaxed">
@@ -138,7 +198,7 @@ export const SponsoredFeedsTable = ({
138198
className="p-1 hover:bg-gray-200 dark:hover:bg-gray-600 rounded flex-shrink-0 mt-0.5"
139199
title="Copy Price Feed ID"
140200
>
141-
{copiedId === feed.priceFeedId ? (
201+
{copiedId === `priceFeedId-${feed.priceFeedId}` ? (
142202
<span className="text-green-500 text-xs font-bold">
143203
144204
</span>
@@ -185,7 +245,7 @@ export const SponsoredFeedsTable = ({
185245
{/* Show count indicator when scrolling is needed */}
186246
{shouldScroll && (
187247
<div className="px-3 py-1 bg-gray-50 dark:bg-gray-800 border-t border-gray-200 dark:border-gray-600 text-xs text-gray-500 text-center">
188-
Showing {maxVisibleRows} of {feeds.length} feeds • Scroll to see
248+
Showing {actualVisibleRows} of {feeds.length} feeds • Scroll to see
189249
more
190250
</div>
191251
)}

0 commit comments

Comments
 (0)