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 authored Jan 16, 2024
1 parent 4360d73 commit abb1231
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion website/src/components/CreatePortal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { type FunctionComponent, useState } from "react";
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { useAccount } from "wagmi";
import { Address } from "@wagmi/core";

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

const CreatePortal: FunctionComponent<SDKDemoProps> = ({ veraxSdk, getTxHash }) => {
Expand Down
7 changes: 4 additions & 3 deletions website/src/components/CreateSchema.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { type FunctionComponent, useEffect, useState } from "react";
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { useAccount } from "wagmi";
import { Address } from "@wagmi/core";

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

const SCHEMA = "(bool hasCompletedTutorial)";
Expand All @@ -20,7 +21,7 @@ const CreateSchema: FunctionComponent<SDKDemoProps> = ({ veraxSdk, getTxHash, ge

useEffect(() => {
const fetchSchema = async () => {
const schemaId = (await veraxSdk.schema.getIdFromSchemaString(SCHEMA)) as `0x${string}`;
const schemaId = (await veraxSdk.schema.getIdFromSchemaString(SCHEMA)) as Address;
const alreadyExists = (await veraxSdk.schema.getSchema(schemaId)) as boolean;
setSchemaId(schemaId);
setSchemaExists(alreadyExists);
Expand Down
7 changes: 4 additions & 3 deletions website/src/components/IssueAttestation.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { type FunctionComponent, useState } from "react";
import { VeraxSdk } from "@verax-attestation-registry/verax-sdk";
import { useAccount } from "wagmi";
import { Address } from "@wagmi/core";

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

const IssueAttestation: FunctionComponent<SDKDemoProps> = ({ veraxSdk, getTxHash, schemaId, portalId }) => {
Expand Down
12 changes: 6 additions & 6 deletions website/src/pages/Tutorials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ConnectWallet from "../components/ConnectWallet.tsx";
import IssueAttestation from "../components/IssueAttestation.tsx";
import AttestationPreview from "../components/AttestationPreview.tsx";
import { waitForTransactionReceipt } from "viem/actions";
import { getPublicClient } from "@wagmi/core";
import { Address, getPublicClient } from "@wagmi/core";
import CreateSchema from "../components/CreateSchema.tsx";
import CreatePortal from "../components/CreatePortal.tsx";
import { decodeEventLog, parseAbi } from "viem";
Expand All @@ -16,8 +16,8 @@ export type SDKDemoProps = {

const Tutorials: FunctionComponent<SDKDemoProps> = ({ title }) => {
const [veraxSdk, setVeraxSdk] = useState<VeraxSdk>();
const [schemaId, setSchemaId] = useState<`0x${string}`>();
const [portalId, setPortalId] = useState<`0x${string}`>();
const [schemaId, setSchemaId] = useState<Address>();
const [portalId, setPortalId] = useState<Address>();
const [attestationId, setAttestationId] = useState<string>();

const { address, isConnected } = useAccount();
Expand All @@ -36,14 +36,14 @@ const Tutorials: FunctionComponent<SDKDemoProps> = ({ title }) => {
}
}, [chain, address]);

const handleSchemaTx = async (hash: `0x${string}`) => {
const handleSchemaTx = async (hash: Address) => {
const receipt = await waitForTransactionReceipt(getPublicClient(), {
hash,
});
setSchemaId(receipt.logs[0].topics[1]);
};

const handlePortalTx = async (hash: `0x${string}`) => {
const handlePortalTx = async (hash: Address) => {
const receipt = await waitForTransactionReceipt(getPublicClient(), {
hash,
});
Expand All @@ -55,7 +55,7 @@ const Tutorials: FunctionComponent<SDKDemoProps> = ({ title }) => {
setPortalId(decodedLogs.args.portalAddress);
};

const handleAttestationTx = async (hash: `0x${string}`) => {
const handleAttestationTx = async (hash: Address) => {
const receipt = await waitForTransactionReceipt(getPublicClient(), {
hash,
});
Expand Down

0 comments on commit abb1231

Please sign in to comment.