Skip to content

Commit

Permalink
feat: As a developer, I want to see an end-to-end hello-world tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
alainncls committed Jan 11, 2024
1 parent 3f022ce commit b9667aa
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 23 deletions.
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@lens-protocol/widgets-react": "^2.1.0",
"@verax-attestation-registry/verax-sdk": "1.1.0",
"@wagmi/core": "^1.4.7",
"@web3modal/wagmi": "^3.5.0",
"axios": "^1.6.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-json-view": "^1.21.3",
"react-router-dom": "^6.19.0",
"viem": "^1.18.9",
"wagmi": "^1.4.6"
Expand Down
10 changes: 10 additions & 0 deletions website/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
text-align: center;
}

.global-container {
display: flex;
flex-direction: column;
min-height: 100vh;
}

.global-body {
flex: 1;
}

.logo {
height: 6em;
padding: 1.5em;
Expand Down
32 changes: 19 additions & 13 deletions website/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ import Poh from "./pages/Poh.tsx";
import SDKDemo from "./pages/SDKDemo.tsx";
import Navbar from "./components/Navbar.tsx";
import Footer from "./components/Footer.tsx";
import Tutorials from "./pages/Tutorials.tsx";

function App() {
return (
<HashRouter>
<header>
<Navbar />
</header>
<Routes>
<Route path="*" element={<Home title={"Verax Attestation Registry"} />} />
<Route path="/sdk-demo" element={<SDKDemo title={"Verax | SDK Demo"} />} />
<Route path="/linea-poh" element={<Poh />} />
</Routes>
<footer>
<Footer />
</footer>
</HashRouter>
<div className={"global-container"}>
<HashRouter>
<header>
<Navbar />
</header>
<div className={"global-body"}>
<Routes>
<Route path="*" element={<Home title={"Verax Attestation Registry"} />} />
<Route path="/sdk-demo" element={<SDKDemo title={"Verax | SDK Demo"} />} />
<Route path="/tutorials" element={<Tutorials title={"Verax | Tutorials"} />} />
<Route path="/linea-poh" element={<Poh />} />
</Routes>
</div>
<footer>
<Footer />
</footer>
</HashRouter>
</div>
);
}

Expand Down
5 changes: 5 additions & 0 deletions website/src/components/AttestationPreview.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.attestation-preview {
width: 70%;
text-align: start;
margin: auto;
}
46 changes: 46 additions & 0 deletions website/src/components/AttestationPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { type FunctionComponent, useEffect, useState } from "react";
import "./AttestationPreview.css";
import { Attestation, VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import ReactJson from "react-json-view";

export type SDKDemoProps = {
veraxSdk: VeraxSdk;
attestationId: string;
};

const AttestationPreview: FunctionComponent<SDKDemoProps> = ({ veraxSdk, attestationId }) => {
const [attestation, setAttestation] = useState<Attestation>();

useEffect(() => {
const fetchAttestation = async () => {
const attestation = (await veraxSdk.attestation.getAttestation(attestationId)) as Attestation;
setAttestation(attestation);
};

fetchAttestation();
}, [attestationId, veraxSdk.attestation]);

return (
<div className={"attestation-preview"}>
<ReactJson
src={
attestation
? JSON.parse(
JSON.stringify(attestation, (_key, value) => (typeof value === "bigint" ? value.toString() : value)),
)
: {}
}
name={false}
displayDataTypes={false}
collapsed={false}
enableClipboard={false}
quotesOnKeys={false}
sortKeys={false}
theme={"hopscotch"}
style={{ backgroundColor: "#12172C", padding: "1rem", borderRadius: "0.5rem" }}
/>
</div>
);
};

export default AttestationPreview;
46 changes: 46 additions & 0 deletions website/src/components/CreatePortal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { type FunctionComponent, useState } from "react";
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { useAccount } from "wagmi";

export type SDKDemoProps = {
veraxSdk: VeraxSdk;
getTxHash: (hash: `0x${string}`) => void;
};

const CreatePortal: FunctionComponent<SDKDemoProps> = ({ veraxSdk, getTxHash }) => {
const [txHash, setTxHash] = useState<string>("");
const [error, setError] = useState<string>("");

const { isConnected } = useAccount();

const createPortal = async () => {
try {
const hash = await veraxSdk.portal.deployDefaultPortal(
[],
"Tutorial Portal",
"This Portal is used for the tutorial",
true,
"Verax Tutorial",
);
setTxHash(hash);
getTxHash(hash);
} catch (e) {
console.log(e);
if (e instanceof Error) {
setError(`Oops, something went wrong: ${e.message}`);
}
}
};

return (
<>
<button onClick={createPortal} disabled={!isConnected && txHash !== ""}>
Send transaction
</button>
{txHash !== "" && <p>{`Transaction with hash ${txHash} sent!`}</p>}
{error !== "" && <p style={{ color: "red" }}>{error}</p>}
</>
);
};

export default CreatePortal;
65 changes: 65 additions & 0 deletions website/src/components/CreateSchema.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { type FunctionComponent, useEffect, useState } from "react";
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { useAccount } from "wagmi";

export type SDKDemoProps = {
veraxSdk: VeraxSdk;
getTxHash: (hash: `0x${string}`) => void;
getSchemaId: (schemaId: `0x${string}`) => void;
};

const SCHEMA = "(bool hasCompletedTutorial)";

const CreateSchema: FunctionComponent<SDKDemoProps> = ({ veraxSdk, getTxHash, getSchemaId }) => {
const [txHash, setTxHash] = useState<string>("");
const [error, setError] = useState<string>("");
const [schemaId, setSchemaId] = useState<string>("");
const [schemaExists, setSchemaExists] = useState<boolean>(false);

const { isConnected } = useAccount();

useEffect(() => {
const fetchSchema = async () => {
const schemaId = (await veraxSdk.schema.getIdFromSchemaString(SCHEMA)) as `0x${string}`;
const alreadyExists = (await veraxSdk.schema.getSchema(schemaId)) as boolean;
setSchemaId(schemaId);
setSchemaExists(alreadyExists);
getSchemaId(schemaId);
};

fetchSchema();
}, [getSchemaId, veraxSdk.schema]);

useEffect(() => {}, [veraxSdk.schema]);

const createSchema = async () => {
try {
const hash = await veraxSdk.schema.create(
"Tutorial Schema",
"This Schema is used for the tutorial",
"https://ver.ax/#/tutorials",
SCHEMA,
);
setTxHash(hash);
getTxHash(hash);
} catch (e) {
console.log(e);
if (e instanceof Error) {
setError(`Oops, something went wrong: ${e.message}`);
}
}
};

return (
<>
<button onClick={createSchema} disabled={!isConnected || schemaExists}>
Send transaction
</button>
{schemaExists && <p>{`Schema already exists, with ID ${schemaId} !`}</p>}
{txHash !== "" && <p>{`Transaction with hash ${txHash} sent!`}</p>}
{error !== "" && <p style={{ color: "red" }}>{error}</p>}
</>
);
};

export default CreateSchema;
6 changes: 0 additions & 6 deletions website/src/components/Footer.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 10vh;
min-height: 60px;
margin: 20px 0;
display: flex;
justify-content: center;
Expand Down
50 changes: 50 additions & 0 deletions website/src/components/IssueAttestation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { type FunctionComponent, useState } from "react";
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { useAccount } from "wagmi";

export type SDKDemoProps = {
veraxSdk: VeraxSdk;
getTxHash: (hash: `0x${string}`) => void;
schemaId: `0x${string}`;
portalId: `0x${string}`;
};

const IssueAttestation: FunctionComponent<SDKDemoProps> = ({ veraxSdk, getTxHash, schemaId, portalId }) => {
const [txHash, setTxHash] = useState<string>("");
const [error, setError] = useState<string>("");

const { address, isConnected } = useAccount();

const issueAttestation = async () => {
if (address) {
try {
const attestationPayload = {
schemaId: schemaId,
expirationDate: Math.floor(Date.now() / 1000) + 2592000,
subject: address,
attestationData: [{ hasCompletedTutorial: true }],
};
const hash = await veraxSdk.portal.attest(portalId, attestationPayload, []);
setTxHash(hash);
getTxHash(hash);
} catch (e) {
console.log(e);
if (e instanceof Error) {
setError(`Oops, something went wrong: ${e.message}`);
}
}
}
};

return (
<>
<button onClick={issueAttestation} disabled={!isConnected}>
Send transaction
</button>
{txHash !== "" && <p>{`Transaction with hash ${txHash} sent!`}</p>}
{error !== "" && <p style={{ color: "red" }}>{error}</p>}
</>
);
};

export default IssueAttestation;
5 changes: 5 additions & 0 deletions website/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const Navbar: React.FC = () => {
SDK Demo
</NavLink>
</li>
<li className="nav-item">
<NavLink className="navbar-brand" to="/tutorials" end>
Tutorials
</NavLink>
</li>
</ul>
</div>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions website/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const metadata = {
url: "https://ver.ax",
};

const chains = [linea, lineaTestnet, arbitrum, arbitrumGoerli, mainnet];
const chains = [lineaTestnet, linea, arbitrum, arbitrumGoerli, mainnet];
const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata });

createWeb3Modal({
wagmiConfig,
projectId,
chains,
defaultChain: linea,
defaultChain: lineaTestnet,
chainImages: {
59144: LineaMainnetIcon,
59140: LineaTestnetIcon,
Expand Down
Empty file removed website/src/pages/Home.css
Empty file.
1 change: 0 additions & 1 deletion website/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import veraxLogo from "../assets/verax-logo-circle.svg";
import "./Home.css";
import { type FunctionComponent, useEffect } from "react";

export type HomeProps = {
Expand Down
Empty file removed website/src/pages/SDKDemo.css
Empty file.
1 change: 0 additions & 1 deletion website/src/pages/SDKDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type FunctionComponent, useEffect, useState } from "react";
import "./SDKDemo.css";
import { Attestation, VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { useAccount, useNetwork } from "wagmi";
import ConnectWallet from "../components/ConnectWallet.tsx";
Expand Down
Loading

0 comments on commit b9667aa

Please sign in to comment.