generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup signing with ethereum and zupass only with proof
- Loading branch information
1 parent
c4d7318
commit 6c89a52
Showing
5 changed files
with
582 additions
and
51 deletions.
There are no files selected for viewing
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,54 @@ | ||
import * as React from "react"; | ||
import { recoverMessageAddress } from "viem"; | ||
import { useSignMessage } from "wagmi"; | ||
import { notification } from "~~/utils/scaffold-eth"; | ||
|
||
export const SignMessageButton = () => { | ||
const { | ||
data: signMessageData, | ||
error, | ||
isLoading, | ||
signMessageAsync, | ||
variables, | ||
} = useSignMessage({ | ||
message: "Welcome to Limonade", | ||
}); | ||
const [recorveredAddress, setRecoveredAddress] = React.useState<string>(""); | ||
|
||
React.useEffect(() => { | ||
(async () => { | ||
if (variables?.message && signMessageData) { | ||
const recoveredAddress = await recoverMessageAddress({ | ||
message: variables?.message, | ||
signature: signMessageData, | ||
}); | ||
setRecoveredAddress(recoveredAddress); | ||
} | ||
})(); | ||
}, [signMessageData, variables?.message]); | ||
|
||
const handleSign = async () => { | ||
try { | ||
await signMessageAsync(); | ||
notification.success("Message signed successfully"); | ||
} catch (e) { | ||
notification.error("An Error happend while signing the message"); | ||
console.log("An Error happend while signing the message", e); | ||
console.log("Error", error?.cause); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<button className={`btn btn-primary ${isLoading ? "loading" : ""}`} onClick={() => handleSign()}> | ||
{isLoading ? "Check Wallet" : "Sign Message"} | ||
</button> | ||
{signMessageData && ( | ||
<div> | ||
<div>Recovered Address: {recorveredAddress}</div> | ||
<div>Signature: {signMessageData}</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; |
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,10 @@ | ||
import { usePopup } from "zuauth"; | ||
|
||
/** | ||
* This popup sends requests and receives PCDs from the passport. | ||
*/ | ||
export default function Popup() { | ||
const error = usePopup(); | ||
|
||
return <div>{error}</div>; | ||
} |
Oops, something went wrong.