Skip to content

feat(eas-form): auto generate form from eas schema #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: draft
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Meta, StoryObj } from "@storybook/react";
import { encodeBytes32String } from "ethers";
import { Chain, Hex, zeroHash } from "viem";
import { mainnet, optimism, optimismSepolia, sepolia } from "viem/chains";
import { withQueryClientProvider } from "#stories/decorators/wagmi.tsx";
import { withToaster } from "../decorators/toaster";
import { withWalletControl } from "../decorators/wallet-control";

Expand Down Expand Up @@ -59,17 +60,17 @@ const AttestationFormEasSdk = ({
schemaId={schemaId}
schemaIndex={schemaIndex}
isOffchain={isOffchain}
signAttestation={async (): Promise<any> => {
signAttestation={async (values: any): Promise<any> => {
// TODO fix encode data structure
const now = BigInt(Date.now());

const { recipient, revocable, expirationTime, refUID, data, salt } =
const { recipient, revocable, expirationTime, refUID, salt } =
requestTemplate;

return signAttestation({
...requestTemplate,
recipient,
data,
data: values,
time: now,
});
}}
Expand All @@ -83,7 +84,7 @@ const meta = {
parameters: {
layout: "centered",
},
decorators: [withToaster(), withWalletControl()],
decorators: [withToaster(), withWalletControl(), withQueryClientProvider()],
args: {},
} satisfies Meta<typeof AttestationFormEasSdk>;

Expand All @@ -94,6 +95,7 @@ const createArgs = (schema: any, chain: Chain, fixture: any) => {
const { schemaString, byChain } = schema;
const { uid, index } = byChain[chain.id];
const { data, attestData } = fixture;

return {
chainId: chain.id,
privateKey: BY_USER.user.privateKey,
Expand All @@ -114,7 +116,6 @@ export const OnchainSepolia: Story = {
SCHEMA_BY_NAME.IS_A_FRIEND.byFixture.isFriend,
),
},
decorators: [],
};

export const OnchainOptimismSepolia: Story = {
Expand All @@ -126,7 +127,6 @@ export const OnchainOptimismSepolia: Story = {
SCHEMA_BY_NAME.IS_A_FRIEND.byFixture.isFriend,
),
},
decorators: [],
};

export const OffchainSepolia: Story = {
Expand All @@ -142,11 +142,13 @@ export const OffchainSepolia: Story = {
};

// Until dynamic form
// export const OffchainVote: Story = {
// args: {
// isOffchain: true,
// ...createArgs(SCHEMA_BY_NAME.VOTE, sepolia.id),
// ...SCHEMA_BY_NAME.VOTE.byFixture.vote,
// },
// decorators: [],
// };
export const OffchainVote: Story = {
args: {
isOffchain: true,
...createArgs(
SCHEMA_BY_NAME.IS_A_FRIEND,
sepolia,
SCHEMA_BY_NAME.IS_A_FRIEND.byFixture.isFriend,
),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import type { Meta, StoryObj } from "@storybook/react";
import { Account, Address, Chain, Hex, stringToHex, zeroHash } from "viem";
import { sepolia } from "viem/chains";
import { withToaster } from "../decorators/toaster";
import { withMockAccount, withWagmiProvider } from "../decorators/wagmi";
import {
withMockAccount,
withQueryClientProvider,
withWagmiProvider,
} from "../decorators/wagmi";
import { withWalletControlWagmi } from "../decorators/wallet-control";

const AttestationFormWagmi = ({
schemaId,
schemaIndex,

account,
isOffchain,
schemaString,
chain,
data,
attestData,
}: {
schemaId: string;
Expand All @@ -29,7 +31,6 @@ const AttestationFormWagmi = ({
isOffchain: boolean;
schemaString: string;
chain: Chain;
data: any;
attestData: Omit<AttestationRequestData, "recipient">;
}) => {
if (!account) {
Expand All @@ -54,10 +55,10 @@ const AttestationFormWagmi = ({
schemaId={schemaId}
schemaIndex={schemaIndex}
isOffchain={isOffchain}
signAttestation={async () =>
signAttestation={async (values: any) =>
signAttestation({
...attestData,
data,
data: values,
recipient,
// attester: account.address,
})
Expand All @@ -77,6 +78,7 @@ const meta = {
withWalletControlWagmi(),
withMockAccount(),
withWagmiProvider(),
withQueryClientProvider(),
],
args: {},
} satisfies Meta<typeof AttestationFormWagmi>;
Expand Down Expand Up @@ -110,6 +112,7 @@ const createArgs = (schema: any, chain: Chain, fixture: any) => {
// TODO chain control at withWalletControlWagmi

export const AttestationWagmiOffchain: Story = {
// @ts-expect-error withMockAccount() decorator should inject an account.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(lets create extra stories and keep as is)

args: {
isOffchain: true,
...createArgs(
Expand All @@ -121,6 +124,7 @@ export const AttestationWagmiOffchain: Story = {
};

export const AttestationWagmiOnchain: Story = {
// @ts-expect-error withMockAccount() decorator should inject an account.
args: {
isOffchain: false,
...createArgs(
Expand Down
2 changes: 1 addition & 1 deletion packages/domain/src/user.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const vitalik = {
// 0x4E123166e7DfDE7AbA29162Fb3a5c6Af562443D4
const user = {
privateKey: config.test.user.privateKey as Hex,
address: "",
address: "0x4E123166e7DfDE7AbA29162Fb3a5c6Af562443D4",
};

const eas = {
Expand Down
6 changes: 6 additions & 0 deletions packages/gql/src/graphql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import * as types from "./graphql";
const documents = {
"\n query allAttestationsBy(\n $where: AttestationWhereInput\n ) {\n attestations(where: $where) {\n id\n txid\n recipient\n schema {\n index\n schemaNames {\n name\n }\n }\n time\n isOffchain\n schemaId\n attester\n }\n }\n":
types.AllAttestationsByDocument,
"\n\tquery schemaBy($where: SchemaWhereUniqueInput!) {\n\t\tschema(where: $where) {\n\t\t\tschemaString: schema\n\t\t\tindex\n\t\t\trevocable\n\t\t\tcreator\n\t\t}\n\t}\n":
types.SchemaByDocument,
};

/**
Expand All @@ -23,6 +25,10 @@ export function gql(
source: "\n query allAttestationsBy(\n $where: AttestationWhereInput\n ) {\n attestations(where: $where) {\n id\n txid\n recipient\n schema {\n index\n schemaNames {\n name\n }\n }\n time\n isOffchain\n schemaId\n attester\n }\n }\n",
): typeof import("./graphql").AllAttestationsByDocument;

export function gql(
source: "\n\tquery schemaBy($where: SchemaWhereUniqueInput!) {\n\t\tschema(where: $where) {\n\t\t\tschemaString: schema\n\t\t\tindex\n\t\t\trevocable\n\t\t\tcreator\n\t\t}\n\t}\n",
): typeof import("./graphql").SchemaByDocument;

export function gql(source: string) {
return (documents as any)[source] ?? {};
}
26 changes: 26 additions & 0 deletions packages/gql/src/graphql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2842,3 +2842,29 @@ export const AllAttestationsByDocument = new TypedDocumentString(`
AllAttestationsByQuery,
AllAttestationsByQueryVariables
>;

export type SchemaByQueryVariables = Exact<{
where?: InputMaybe<SchemaWhereUniqueInput>;
}>;

export type SchemaByQuery = {
__typename?: "Query";
schema: {
__typename?: "Schema";
index: string;
schemaString: string;
revocable: boolean;
creator: string;
};
};

export const SchemaByDocument = new TypedDocumentString(`
query schemaBy($where: SchemaWhereUniqueInput!) {
schema(where: $where) {
schemaString: schema
index
revocable
creator
}
}
`) as unknown as TypedDocumentString<SchemaByQuery, SchemaByQueryVariables>;
Loading