-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
095b8d5
commit 8def57f
Showing
5 changed files
with
236 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { useState, useEffect } from "react" | ||
import { getPresentations, modifyPresentations} from "../../../utils" | ||
import { DataGrid, GridColDef } from '@mui/x-data-grid'; | ||
import { TextField, Button } from "@mui/material" | ||
|
||
|
||
const columns: GridColDef[] = [ | ||
{ field: 'id', headerName: 'ID', width: 70 }, | ||
{ field: 'status', headerName: 'Status', width: 100 }, | ||
{ field: 'cred_hashes', headerName: 'Credential hashes', width: 140 }, | ||
{ field: 'cred_schemas', headerName: 'Credential schemas', width: 1000 }, | ||
{ field: 'lang', headerName: 'Language', width: 100 }, | ||
{ field: 'script', headerName: 'Script', width: 1000 }, | ||
{ field: 'result', headerName: 'Result', width: 70 }, | ||
]; | ||
|
||
|
||
export function AdminsTab() { | ||
const [presentations, setPresentations] = useState<object[]>([]); | ||
const [toApprove, setToApprove] = useState<string>(""); | ||
const [toDeny, setToDeny] = useState<string>(""); | ||
|
||
const fetchData = async () => { | ||
const res = await getPresentations() | ||
setPresentations(res.map((x, index) => { | ||
x["id"] = index; | ||
x["cred_schemas"] = x["cred_schemas"].map((y: string) => atob(y)); | ||
Check failure on line 27 in src/pages/verifier/tabs/admin.tsx GitHub Actions / build
|
||
return x; | ||
})); | ||
} | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
switch(event.target.id) { | ||
case "todeny": | ||
setToDeny(event.target.value) | ||
break | ||
case "toapprove": | ||
setToApprove(event.target.value) | ||
break | ||
} | ||
} | ||
|
||
const handleApprove = () => { | ||
const idx = toApprove.split(",").filter(x => x != "").map(x => parseInt(x)); | ||
modifyPresentations(idx, []).then(() => { fetchData() }); | ||
} | ||
|
||
const handleDeny = () => { | ||
const idx = toDeny.split(",").filter(x => x != "").map(x => parseInt(x)); | ||
modifyPresentations([], idx).then(() => { fetchData() }); | ||
} | ||
|
||
useEffect(() => { fetchData() }, []) | ||
|
||
return ( | ||
<> | ||
<div style={{ width: '100%' }}> | ||
<DataGrid | ||
rows={presentations} | ||
columns={columns} | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { page: 0, pageSize: 5 }, | ||
}, | ||
}} | ||
pageSizeOptions={[5, 10]} | ||
checkboxSelection | ||
/> | ||
</div> | ||
<br/> | ||
<div><h2><b>Manage presentation status</b></h2></div> | ||
<TextField | ||
id="toapprove" | ||
variant="outlined" | ||
label="IDs to approve" | ||
value={toApprove} | ||
onChange={handleChange} | ||
/> | ||
<Button | ||
variant="contained" | ||
onClick={handleApprove} | ||
> | ||
Approve | ||
</Button> | ||
<br/> | ||
<br/> | ||
<TextField | ||
id="todeny" | ||
variant="outlined" | ||
label="IDs to deny" | ||
value={toDeny} | ||
onChange={handleChange} | ||
/> | ||
<Button | ||
variant="contained" | ||
onClick={handleDeny} | ||
> | ||
Deny | ||
</Button> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { useState } from "react" | ||
import { checkPresentation } from "../../../utils" | ||
import { TextField, Button } from "@mui/material" | ||
|
||
export function HoldersTab() { | ||
const [receipt, setReceipt] = useState(""); | ||
const [issuers, setIssuers] = useState(""); | ||
const [msg, setMsg] = useState(""); | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
switch(event.target.id) { | ||
case "receipt-field": | ||
setReceipt(event.target.value) | ||
break | ||
case "issuers-field": | ||
setIssuers(event.target.value) | ||
break | ||
} | ||
} | ||
|
||
const handleSubmit = () => { | ||
const issuersList = issuers.split(",").filter(x => x != ""); | ||
checkPresentation(issuersList, receipt).then((result) => setMsg(JSON.stringify(result))) | ||
} | ||
|
||
const msgToStatus = (): string => { | ||
if (msg === "") { | ||
return ""; | ||
} | ||
const parsedMsg = JSON.parse(msg); | ||
if (parsedMsg["verdict"] === true) { | ||
return "Success ✅"; | ||
} | ||
else { | ||
return `Error: ${parsedMsg["error"]}` | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<br/> | ||
<TextField | ||
id="receipt-field" | ||
variant="outlined" | ||
label="Proof" | ||
value={receipt} | ||
onChange={handleChange} | ||
/> | ||
<br/> | ||
<br/> | ||
<TextField | ||
id="issuers-field" | ||
variant="outlined" | ||
label="Credential issuers" | ||
value={issuers} | ||
onChange={handleChange} | ||
/> | ||
<br/> | ||
<br/> | ||
<Button | ||
variant="contained" | ||
onClick={handleSubmit} | ||
> | ||
Submit | ||
</Button> | ||
<br/> | ||
<div>{msgToStatus()}</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./admin" | ||
export * from "./holder" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,40 @@ | ||
import { useState } from 'react' | ||
import { HoldersTab, AdminsTab } from './tabs' | ||
import { Tabs, Tab, Box } from '@mui/material' | ||
|
||
|
||
export function Verifier() { | ||
document.title = 'Verifier' | ||
const [activeTab, setActiveTab] = useState<string>("holders") | ||
|
||
const handleChange = (_event: React.SyntheticEvent, newValue: string) => { | ||
setActiveTab(newValue); | ||
}; | ||
|
||
const displayActiveTab = () => { | ||
switch (activeTab) { | ||
case "holders": | ||
return <HoldersTab/> | ||
case "admins": | ||
return <AdminsTab/> | ||
default: | ||
return <></> | ||
} | ||
} | ||
|
||
document.title = 'Verifer' | ||
return( | ||
<>Verifier Page</> | ||
<> | ||
<b>Relying Party Page</b> | ||
<Box sx={{ width: '100%' }}> | ||
<Tabs | ||
value={activeTab} | ||
onChange={handleChange} | ||
> | ||
<Tab value="holders" label="Holders"></Tab> | ||
<Tab value="admins" label="Admins" /> | ||
</Tabs> | ||
</Box> | ||
{displayActiveTab()} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters