Skip to content

Commit

Permalink
fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgo0018 committed May 16, 2024
1 parent d602883 commit 35adcdf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/nextjs/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { createContext, useContext, useEffect, useState } from "react";
import { createContext, useCallback, useContext, useEffect, useState } from "react";
import { Keypair, PrivKey } from "maci-domainobjs";
import { useAccount, useSignMessage } from "wagmi";
import deployedContracts from "~~/contracts/deployedContracts";
Expand All @@ -11,7 +11,7 @@ interface IAuthContext {
isRegistered: boolean;
keypair: Keypair | null;
stateIndex: bigint | null;
generateKeypair: () => Promise<void>;
generateKeypair: () => void;
}

export const AuthContext = createContext<IAuthContext>({} as IAuthContext);
Expand All @@ -28,13 +28,15 @@ export default function AuthContextProvider({ children }: { children: React.Reac
setSignatureMessage(`Login to ${window.location.origin}`);
}, []);

async function generateKeypair() {
const generateKeypair = useCallback(() => {
if (!address) return;

const signature = await signMessageAsync();
const userKeyPair = new Keypair(new PrivKey(signature));
setKeyPair(userKeyPair);
}
(async () => {
const signature = await signMessageAsync();
const userKeyPair = new Keypair(new PrivKey(signature));
setKeyPair(userKeyPair);
})();
}, [address, signMessageAsync]);

useEffect(() => {
setKeyPair(null);
Expand Down

0 comments on commit 35adcdf

Please sign in to comment.