Skip to content

Commit

Permalink
Merge pull request #59 from pshenmic/feat/data_contract_schema
Browse files Browse the repository at this point in the history
Add data contracts page
  • Loading branch information
pshenmic authored Oct 3, 2023
2 parents ead84f7 + 2431af7 commit 8991957
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/frontend/src/components/RootComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function RootComponent() {
<div className="topnav">
<Link to="/">Home</Link>
<Link to="/blocks">Blocks</Link>
<Link to="/dataContracts">Data Contracts</Link>
<input value={searchQuery} type="text" placeholder="Search..." onChange={handleSearchInput}
onKeyPress={handleKeyPress}/>
<ModalWindow open={showModal} text={modalText} setShowModal={setShowModal}/>
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import TransactionRoute, {
loader as transactionLoader,
} from "./routes/transaction/transaction.route";
import DataContractRoute, {loader as dataContractLoader} from "./routes/dataContract/data.contract.route";
import DataContractsRoute from "./routes/dataContracts/data.contracts.route";

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -49,6 +50,10 @@ const router = createBrowserRouter([
element: <DataContractRoute/>,
loader: dataContractLoader,
},
{
path: "dataContracts",
element: <DataContractsRoute/>,
},
]
}
]);
Expand Down
45 changes: 45 additions & 0 deletions packages/frontend/src/routes/dataContracts/data.contracts.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, {useEffect, useState} from 'react';
import './data_contracts.css'
import * as Api from '../../util/Api'
import {Link} from "react-router-dom";

function DataContracts({dataContracts}) {
return <div className={"data_contracts_list"}>
{
dataContracts.map((dataContract) =>
<DataContract
key={dataContract.identifier}
dataContract={dataContract}/>)
}
</div>
}

function DataContract({dataContract}) {
return <div className={"data_contracts_item"}>
<Link to={`/dataContracts/${dataContract.identifier}`}>{dataContract.identifier}</Link>
</div>
}

function DataContractsRoute() {
const [dataContracts, setDataContracts] = useState(null)
const [loading, setLoading] = useState(null)
const [error, setError] = useState(null)


useEffect(() => {
Api.getDataContracts()
.then((dataContracts) => setDataContracts(dataContracts))
.catch((err) => {
setError(err)
})
.finally(() => setLoading(false))
}, [])

return (<div className="container">
{error && <div>Error {error}</div>}
{loading && <div>Loading data contracts from API</div>}
{dataContracts && <DataContracts dataContracts={dataContracts}/>}
</div>);
}

export default DataContractsRoute;
23 changes: 23 additions & 0 deletions packages/frontend/src/routes/dataContracts/data_contracts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.data_contracts_list {
color: white;
text-decoration: none;
background-color: #1a491c;
}

.data_contracts_item {
text-decoration: none;
padding: 5px;
margin-left: 10px;
margin-right: 10px;
background-color: #1a491c;
}

.data_contracts_item a {
text-decoration: none;
color: white;
}

.data_contracts_item a:hover {
text-decoration: underline;
color: #76b2d2;
}
6 changes: 5 additions & 1 deletion packages/frontend/src/util/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const getDataContractByIdentifier = (identifier) => {
return call(`dataContract/${identifier}`, 'GET')
}

const getDataContracts = () => {
return call(`dataContracts`, 'GET')
}

const getStatus = () => {
return call(`status`, 'GET')
}
Expand All @@ -78,4 +82,4 @@ const decodeTx = (base64) => {
return call(`transaction/decode`, 'POST', {base64})
}

export {getStatus, getBlocks, getBlockByHash, getTransactions, getTransaction, search, decodeTx, getDataContractByIdentifier}
export {getStatus, getBlocks, getBlockByHash, getTransactions, getTransaction, search, decodeTx, getDataContractByIdentifier, getDataContracts}

0 comments on commit 8991957

Please sign in to comment.