Skip to content

Commit 899d607

Browse files
author
Bingle Kruger
committed
feat(pools): database linked to DRTs
1 parent 99f56b0 commit 899d607

File tree

2 files changed

+85
-27
lines changed

2 files changed

+85
-27
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { NextResponse } from 'next/server';
2+
import { prisma } from "@/lib/prisma";
3+
4+
export async function GET() {
5+
try {
6+
const digitalRights = await prisma.digitalRightToken.findMany({
7+
where: {
8+
isActive: true
9+
},
10+
select: {
11+
id: true,
12+
name: true,
13+
description: true,
14+
githubUrl: true,
15+
hash: true
16+
}
17+
});
18+
19+
return NextResponse.json(digitalRights);
20+
} catch (error) {
21+
console.error("❌ Error fetching digital rights:", error);
22+
return NextResponse.json(
23+
{ error: "Failed to fetch digital rights" },
24+
{ status: 500 }
25+
);
26+
} finally {
27+
await prisma.$disconnect();
28+
}
29+
}

ntc-web/app/pools/page.tsx

+56-27
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ interface StepProps {
4040
onPrev?: () => void;
4141
}
4242

43+
interface DigitalRight {
44+
id: string;
45+
name: string;
46+
description: string;
47+
githubUrl: string | null;
48+
hash: string | null;
49+
}
50+
4351
// Step 1: File Selection Component
4452
function FileSelectionStep({ isActive, onNext }: StepProps) {
4553
const [schemaFile, setSchemaFile] = useState<File | null>(null)
@@ -139,32 +147,49 @@ function FileSelectionStep({ isActive, onNext }: StepProps) {
139147
// Step 2: Digital Rights Assignment
140148
function DigitalRightsStep({ isActive, onNext, onPrev }: StepProps) {
141149
const [selectedRights, setSelectedRights] = useState<string[]>([])
150+
const [digitalRights, setDigitalRights] = useState<DigitalRight[]>([])
151+
const [isLoading, setIsLoading] = useState(true)
152+
const [error, setError] = useState<string | null>(null)
142153

143-
if (!isActive) return null
154+
useEffect(() => {
155+
const fetchDigitalRights = async () => {
156+
try {
157+
const response = await fetch('/api/digital-rights')
158+
if (!response.ok) {
159+
throw new Error('Failed to fetch digital rights')
160+
}
161+
const data = await response.json()
162+
setDigitalRights(data)
163+
} catch (err) {
164+
setError('Failed to load digital rights. Please try again.')
165+
console.error('Error fetching digital rights:', err)
166+
} finally {
167+
setIsLoading(false)
168+
}
169+
}
144170

145-
const dummyRights = [
146-
{
147-
id: '1',
148-
name: 'Append Data Pool',
149-
description: 'Permits adding new data entries to existing pools while maintaining schema requirements',
150-
github: 'https://github.com/ntls-io/trusted-compute-MVP/blob/main/sgx-mvp/json-append/src/lib.rs',
151-
hash: null
152-
},
153-
{
154-
id: '2',
155-
name: 'Execute Median WASM',
156-
description: 'Enables running Rust WebAssembly-based median calculations on data pools',
157-
github: 'https://github.com/ntls-io/WASM-Binaries-MVP/blob/master/bin/get_median_wasm.wasm',
158-
hash: '728445d425153350b3e353cc96d29c16d5d81978ea3d7bad21f3d2b2dd76d813'
159-
},
160-
{
161-
id: '3',
162-
name: 'Execute Median Python',
163-
description: 'Allows execution of Python-based median computations on data pools',
164-
github: 'https://github.com/ntls-io/Python-Scripts-MVP/blob/main/calculate_median.py',
165-
hash: 'bcda34f2af83a2dac745a5d86f18f4c4cd6cb4e61c76e0dec005a5fc9bc124f5'
171+
if (isActive) {
172+
fetchDigitalRights()
166173
}
167-
]
174+
}, [isActive])
175+
176+
if (!isActive) return null
177+
178+
if (isLoading) {
179+
return (
180+
<div className="flex justify-center items-center h-64">
181+
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" />
182+
</div>
183+
)
184+
}
185+
186+
if (error) {
187+
return (
188+
<Alert variant="destructive">
189+
<AlertDescription>{error}</AlertDescription>
190+
</Alert>
191+
)
192+
}
168193

169194
return (
170195
<div className="space-y-6">
@@ -182,14 +207,14 @@ function DigitalRightsStep({ isActive, onNext, onPrev }: StepProps) {
182207
</TableRow>
183208
</TableHeader>
184209
<TableBody>
185-
{dummyRights.map((right) => (
210+
{digitalRights.map((right) => (
186211
<TableRow key={right.id}>
187212
<TableCell className="font-medium">{right.name}</TableCell>
188213
<TableCell>{right.description}</TableCell>
189214
<TableCell>
190-
{right.github ? (
215+
{right.githubUrl ? (
191216
<a
192-
href={right.github}
217+
href={right.githubUrl}
193218
target="_blank"
194219
rel="noopener noreferrer"
195220
className="text-blue-600 hover:text-blue-800 underline"
@@ -231,7 +256,11 @@ function DigitalRightsStep({ isActive, onNext, onPrev }: StepProps) {
231256
<Button variant="outline" onClick={onPrev} className={buttonOutlineClass}>
232257
Previous
233258
</Button>
234-
<Button onClick={onNext} className={buttonBaseClass}>
259+
<Button
260+
onClick={onNext}
261+
disabled={selectedRights.length === 0}
262+
className={buttonBaseClass}
263+
>
235264
Next
236265
</Button>
237266
</div>

0 commit comments

Comments
 (0)