From a6787b53f436c55995e26470f55a6e04300ee520 Mon Sep 17 00:00:00 2001
From: John Guilding <54913924+JohnGuilding@users.noreply.github.com>
Date: Wed, 28 Aug 2024 22:32:38 +0100
Subject: [PATCH] submit application & use useSmartAccount hook (#17)
* submit application & use useSmartAccount hook
* Use Hex & Address types
---
packages/interface/package.json | 1 +
.../src/components/EligibilityDialog.tsx | 14 +---
.../interface/src/components/JoinButton.tsx | 4 +-
packages/interface/src/config.ts | 3 +-
packages/interface/src/contexts/Ballot.tsx | 9 ---
packages/interface/src/contexts/Maci.tsx | 6 +-
.../components/ApplicationButtons.tsx | 4 +-
.../components/ApplicationForm.tsx | 14 ++--
.../hooks/useApproveApplication.ts | 8 ++-
.../hooks/useCreateApplication.ts | 6 +-
.../features/voters/hooks/useApproveVoters.ts | 8 ++-
packages/interface/src/hooks/useEAS.ts | 60 +++++++++++++---
.../interface/src/hooks/useEthersSigner.ts | 2 +-
packages/interface/src/hooks/useIsAdmin.ts | 6 +-
.../src/hooks/useIsCorrectNetwork.ts | 5 +-
.../interface/src/hooks/useSmartAccount.ts | 13 +++-
packages/interface/src/layouts/BaseLayout.tsx | 8 +--
.../interface/src/layouts/DefaultLayout.tsx | 6 +-
packages/interface/src/pages/ballot/index.tsx | 8 +--
packages/interface/src/pages/signup/index.tsx | 4 +-
.../src/pages/signup/registerEmail.tsx | 5 +-
packages/interface/src/pages/stats/index.tsx | 19 +----
.../interface/src/pages/voters/status.tsx | 5 +-
packages/interface/src/utils/types.ts | 2 +-
pnpm-lock.yaml | 70 ++++++++++++++++++-
25 files changed, 190 insertions(+), 100 deletions(-)
diff --git a/packages/interface/package.json b/packages/interface/package.json
index 8403456..5dd1bfa 100644
--- a/packages/interface/package.json
+++ b/packages/interface/package.json
@@ -16,6 +16,7 @@
"test:e2e": "playwright test --project=chromium"
},
"dependencies": {
+ "@ethereum-attestation-service/eas-contracts": "^1.7.1",
"@ethereum-attestation-service/eas-sdk": "^1.5.0",
"@hatsprotocol/sdk-v1-core": "^0.10.0",
"@hookform/resolvers": "^3.3.4",
diff --git a/packages/interface/src/components/EligibilityDialog.tsx b/packages/interface/src/components/EligibilityDialog.tsx
index 57f952e..2f566d7 100644
--- a/packages/interface/src/components/EligibilityDialog.tsx
+++ b/packages/interface/src/components/EligibilityDialog.tsx
@@ -1,17 +1,16 @@
import { useRouter } from "next/router";
import { useState, useCallback, useEffect } from "react";
import { toast } from "sonner";
-import { useAccount, useDisconnect } from "wagmi";
import { useMaci } from "~/contexts/Maci";
import { useAppState } from "~/utils/state";
import { EAppState } from "~/utils/types";
import { Dialog } from "./ui/Dialog";
+import useSmartAccount from "~/hooks/useSmartAccount";
export const EligibilityDialog = (): JSX.Element | null => {
- const { address } = useAccount();
- const { disconnect } = useDisconnect();
+ const { address } = useSmartAccount();
const [openDialog, setOpenDialog] = useState(!!address);
const { onSignup, isEligibleToVote, isRegistered } = useMaci();
@@ -34,10 +33,6 @@ export const EligibilityDialog = (): JSX.Element | null => {
setOpenDialog(false);
}, [setOpenDialog]);
- const handleDisconnect = useCallback(() => {
- disconnect();
- }, [disconnect]);
-
const handleGoToProjects = useCallback(() => {
router.push("/projects");
}, [router]);
@@ -46,7 +41,7 @@ export const EligibilityDialog = (): JSX.Element | null => {
router.push("/applications/new");
}, [router]);
- if (appState === EAppState.APPLICATION) {
+ if (appState === EAppState.APPLICATION && isEligibleToVote) {
return (
- {address && isRegistered && appState === EAppState.APPLICATION && (
+ {address && isEligibleToVote && appState === EAppState.APPLICATION && (
Start Application
diff --git a/packages/interface/src/pages/signup/registerEmail.tsx b/packages/interface/src/pages/signup/registerEmail.tsx
index 196c4de..25c9d81 100644
--- a/packages/interface/src/pages/signup/registerEmail.tsx
+++ b/packages/interface/src/pages/signup/registerEmail.tsx
@@ -27,9 +27,10 @@ import { useEthersSigner } from "~/hooks/useEthersSigner";
const RegisterEmail = (): JSX.Element => {
const { address, smartAccount, smartAccountClient } = useSmartAccount();
- const router = useRouter();
- const { updateEligibility } = useMaci();
const signer = useEthersSigner({ client: smartAccountClient });
+ const { updateEligibility } = useMaci();
+ const router = useRouter();
+
const [emailField, setEmail] = useState();
const registerEmail = async (emailField: EmailField) => {
diff --git a/packages/interface/src/pages/stats/index.tsx b/packages/interface/src/pages/stats/index.tsx
index f28e927..2bd7653 100644
--- a/packages/interface/src/pages/stats/index.tsx
+++ b/packages/interface/src/pages/stats/index.tsx
@@ -1,14 +1,13 @@
import { differenceInDays } from "date-fns";
import dynamic from "next/dynamic";
import { useMemo, type PropsWithChildren } from "react";
-import { useAccount } from "wagmi";
-import { ConnectButton } from "~/components/ConnectButton";
import { Alert } from "~/components/ui/Alert";
import { Heading } from "~/components/ui/Heading";
import { config } from "~/config";
import { useMaci } from "~/contexts/Maci";
import { useProjectCount, useProjectsResults, useResults } from "~/hooks/useResults";
+import useSmartAccount from "~/hooks/useSmartAccount";
import { Layout } from "~/layouts/DefaultLayout";
import { formatNumber } from "~/utils/formatNumber";
import { useAppState } from "~/utils/state";
@@ -31,7 +30,7 @@ const Stats = () => {
const results = useResults(pollData);
const count = useProjectCount();
const { data: projectsResults } = useProjectsResults(pollData);
- const { isConnected } = useAccount();
+ const { isConnected } = useSmartAccount();
const { averageVotes, projects = {} } = results.data ?? {};
@@ -46,22 +45,10 @@ const Stats = () => {
return [{ id: "awarded", data }];
}, [projects, projectsResults]);
- if (isLoading) {
+ if (isLoading || !isConnected) {
return Loading...
;
}
- if (!pollData && !isConnected) {
- return (
-
- Connect your wallet to see results
-
-
-
-
-
- );
- }
-
if (!pollData) {
return Something went wrong. Try later.
;
}
diff --git a/packages/interface/src/pages/voters/status.tsx b/packages/interface/src/pages/voters/status.tsx
index 0b24ebc..696f7bd 100644
--- a/packages/interface/src/pages/voters/status.tsx
+++ b/packages/interface/src/pages/voters/status.tsx
@@ -1,12 +1,11 @@
-import { useAccount } from "wagmi";
-
import { Alert } from "~/components/ui/Alert";
import { Spinner } from "~/components/ui/Spinner";
import { useApprovedVoter } from "~/features/voters/hooks/useApprovedVoter";
+import useSmartAccount from "~/hooks/useSmartAccount";
import { Layout } from "~/layouts/DefaultLayout";
const VotersPage = (): JSX.Element => {
- const { address } = useAccount();
+ const { address } = useSmartAccount();
const approved = useApprovedVoter(address!);
if (approved.isLoading) {
diff --git a/packages/interface/src/utils/types.ts b/packages/interface/src/utils/types.ts
index dea81c1..c4594ce 100644
--- a/packages/interface/src/utils/types.ts
+++ b/packages/interface/src/utils/types.ts
@@ -95,7 +95,7 @@ export type Config = {
tokenName: string;
eventName: string;
roundId: string;
- admin: `0x${string}`;
+ admin: Address;
network: Chain;
maciAddress: string | undefined;
maciStartBlock: number;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 05874a9..445e81e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -106,6 +106,9 @@ importers:
packages/interface:
dependencies:
+ '@ethereum-attestation-service/eas-contracts':
+ specifier: ^1.7.1
+ version: 1.7.1(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4))(typescript@5.5.4)(utf-8-validate@5.0.10)
'@ethereum-attestation-service/eas-sdk':
specifier: ^1.5.0
version: 1.6.1(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4))(typescript@5.5.4)(utf-8-validate@5.0.10)
@@ -11948,7 +11951,7 @@ snapshots:
- typescript
- utf-8-validate
- '@ethereum-attestation-service/eas-contracts@1.7.1(ts-node@10.9.2(typescript@5.5.4))(typescript@5.5.4)':
+ '@ethereum-attestation-service/eas-contracts@1.7.1(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4))(typescript@5.5.4)(utf-8-validate@5.0.10)':
dependencies:
hardhat: 2.22.4(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4))(typescript@5.5.4)(utf-8-validate@5.0.10)
transitivePeerDependencies:
@@ -11959,6 +11962,17 @@ snapshots:
- typescript
- utf-8-validate
+ '@ethereum-attestation-service/eas-contracts@1.7.1(ts-node@10.9.2(typescript@5.5.4))(typescript@5.5.4)':
+ dependencies:
+ hardhat: 2.22.4(ts-node@10.9.2(typescript@5.5.4))(typescript@5.5.4)
+ transitivePeerDependencies:
+ - bufferutil
+ - c-kzg
+ - supports-color
+ - ts-node
+ - typescript
+ - utf-8-validate
+
'@ethereum-attestation-service/eas-sdk@1.6.1(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4))(typescript@5.5.4)(utf-8-validate@5.0.10)':
dependencies:
'@ethereum-attestation-service/eas-contracts': 1.4.1(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4))(typescript@5.5.4)(utf-8-validate@5.0.10)
@@ -18639,6 +18653,60 @@ snapshots:
- supports-color
- utf-8-validate
+ hardhat@2.22.4(ts-node@10.9.2(typescript@5.5.4))(typescript@5.5.4):
+ dependencies:
+ '@ethersproject/abi': 5.7.0
+ '@metamask/eth-sig-util': 4.0.1
+ '@nomicfoundation/edr': 0.3.8
+ '@nomicfoundation/ethereumjs-common': 4.0.4
+ '@nomicfoundation/ethereumjs-tx': 5.0.4
+ '@nomicfoundation/ethereumjs-util': 9.0.4
+ '@nomicfoundation/solidity-analyzer': 0.1.2
+ '@sentry/node': 5.30.0
+ '@types/bn.js': 5.1.5
+ '@types/lru-cache': 5.1.1
+ adm-zip: 0.4.16
+ aggregate-error: 3.1.0
+ ansi-escapes: 4.3.2
+ boxen: 5.1.2
+ chalk: 2.4.2
+ chokidar: 3.6.0
+ ci-info: 2.0.0
+ debug: 4.3.6(supports-color@8.1.1)
+ enquirer: 2.4.1
+ env-paths: 2.2.1
+ ethereum-cryptography: 1.2.0
+ ethereumjs-abi: 0.6.8
+ find-up: 2.1.0
+ fp-ts: 1.19.3
+ fs-extra: 7.0.1
+ glob: 7.2.0
+ immutable: 4.3.7
+ io-ts: 1.10.4
+ keccak: 3.0.4
+ lodash: 4.17.21
+ mnemonist: 0.38.5
+ mocha: 10.7.0
+ p-map: 4.0.0
+ raw-body: 2.5.2
+ resolve: 1.17.0
+ semver: 6.3.1
+ solc: 0.7.3(debug@4.3.6)
+ source-map-support: 0.5.21
+ stacktrace-parser: 0.1.10
+ tsort: 0.0.1
+ undici: 5.28.4
+ uuid: 8.3.2
+ ws: 7.5.10(bufferutil@4.0.8)(utf-8-validate@5.0.10)
+ optionalDependencies:
+ ts-node: 10.9.2(@types/node@22.1.0)(typescript@5.5.4)
+ typescript: 5.5.4
+ transitivePeerDependencies:
+ - bufferutil
+ - c-kzg
+ - supports-color
+ - utf-8-validate
+
hardhat@2.22.8(bufferutil@4.0.8)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4))(typescript@5.5.4)(utf-8-validate@5.0.10):
dependencies:
'@ethersproject/abi': 5.7.0