-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: As a developer, I want to see an end-to-end hello-world tutorial (
#521)
- Loading branch information
Showing
17 changed files
with
377 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,5 @@ | ||
.attestation-preview { | ||
width: 70%; | ||
text-align: start; | ||
margin: auto; | ||
} |
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,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; |
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,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; |
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,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; |
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
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,53 @@ | ||
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 hash = await veraxSdk.portal.attest( | ||
portalId, | ||
{ | ||
schemaId, | ||
expirationDate: Math.floor(Date.now() / 1000) + 2592000, | ||
subject: address, | ||
attestationData: [{ hasCompletedTutorial: true }], | ||
}, | ||
[], | ||
); | ||
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; |
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
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
Empty file.
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
Empty file.
Oops, something went wrong.