-
Sign using Cosmos key
-
Cosmos account: {cosmosAddress}
-
-
{message}
+
+
+
+
+
+
+
+ {displayAttestation}{" "}
+
+
+
+
+
+
+
- {result && (
-
} severity="success">
- Signed message ({result}) will be broadcasted to the chain
-
- )}
-
+
);
};
diff --git a/src/pages/SignWithEthereum.tsx b/src/pages/SignWithEthereum.tsx
index ec5c5c0..91bae74 100644
--- a/src/pages/SignWithEthereum.tsx
+++ b/src/pages/SignWithEthereum.tsx
@@ -1,148 +1,185 @@
-import React, { useState, useMemo } from "react";
-import assert from "assert";
+import React, { useState, useMemo, useEffect, useCallback } from "react";
import { useNavigate } from "react-router-dom";
import { SnackbarProvider, enqueueSnackbar } from "notistack";
+import canonicalStringify from "canonical-json";
import {
- Modal,
Button,
- Typography,
- Box,
Select,
MenuItem,
+ Dialog,
+ DialogTitle,
+ DialogContent,
+ DialogActions,
+ Box,
+ Typography,
} from "@mui/material";
import { utf8ToHex } from "@walletconnect/encoding";
import { useWalletConnectContext } from "../context/WalletConnectContext";
-const style = {
- position: "absolute" as const,
- top: "50%",
- left: "50%",
- transform: "translate(-50%, -50%)",
- overflow: "scroll",
- bgcolor: "background.paper",
- border: "2px solid #000",
- boxShadow: 24,
- p: 4,
-};
-
const SignWithEthereum = () => {
- window.Buffer = Buffer;
+ const { session, signClient, checkPersistedState } =
+ useWalletConnectContext();
+
+ useEffect(() => {
+ if (signClient && !session) {
+ checkPersistedState(signClient);
+ }
+ }, [session, signClient, checkPersistedState]);
- const { session, signClient } = useWalletConnectContext();
const navigate = useNavigate();
const [ethAddress, setEthAddress] = useState("");
+ const [ethSignature, setEthSignature] = useState("");
+
const [cosmosAddress, setCosmosAddress] = useState("");
const [openModal, setOpenModal] = useState(false);
const message = useMemo(() => {
return {
- cosmosAddress,
- text: "Onboarding azimuth ID onto urbit chain",
+ msg: "Onboarding my cosmos validator onto UrbitChain",
+ address: cosmosAddress,
};
}, [cosmosAddress]);
const signEth = async () => {
- try {
- const jsonMessage = JSON.stringify(message, null, 2);
- const hexMsg = utf8ToHex(jsonMessage, true);
- const ethSignature: string = await signClient!.request({
- topic: session!.topic,
- chainId: "eip155:1",
- request: {
- method: "personal_sign",
- params: [hexMsg, ethAddress],
- },
- });
- navigate(
- `/sign-with-cosmos/${ethAddress}/${cosmosAddress}/${ethSignature}`
- );
- } catch (error) {
- console.log("err in signing ", error);
- setOpenModal(false);
- enqueueSnackbar("Error signing message", { variant: "error" })
+ if (session && signClient) {
+ try {
+ const jsonMessage = canonicalStringify(message);
+ const hexMsg = utf8ToHex(jsonMessage, true);
+ const ethSignature: string = await signClient!.request({
+ topic: session!.topic,
+ chainId: "eip155:1",
+ request: {
+ method: "personal_sign",
+ params: [hexMsg, ethAddress],
+ },
+ });
+ setEthSignature(ethSignature);
+ setOpenModal(true);
+ } catch (error) {
+ console.log("err in signing ", error);
+ setOpenModal(false);
+ enqueueSnackbar("Error signing message", { variant: "error" });
+ }
}
};
- assert(session, "Session not found");
+ const submitHandler = useCallback(() => {
+ navigate(
+ `/sign-with-cosmos/${ethAddress}/${cosmosAddress}/${ethSignature}`
+ );
+ setOpenModal(false);
+ }, [ethAddress, cosmosAddress, ethSignature, navigate]);
return (