+
Connected to: {session.peer.metadata.name}{" "}
@@ -65,7 +71,12 @@ const SignPageLayout = () => {
variant="square"
alt="Peer logo"
src={session.peer.metadata.icons[0]}
- sx={{ width: 20, height: 20, marginLeft: 1, paddingBottom: 0.5 }}
+ sx={{
+ width: 20,
+ height: 20,
+ marginLeft: 1,
+ paddingBottom: 0.5,
+ }}
/>
diff --git a/src/pages/ConnectWallet.tsx b/src/pages/ConnectWallet.tsx
index 4a5b23e..c54a46a 100644
--- a/src/pages/ConnectWallet.tsx
+++ b/src/pages/ConnectWallet.tsx
@@ -1,38 +1,56 @@
-import React, { useEffect } from 'react';
-import { useNavigate } from 'react-router-dom'
+import React, { useEffect } from "react";
+import { useNavigate } from "react-router-dom";
-import { Typography, Button, Box, Container, Avatar } from '@mui/material';
+import { Typography, Button, Box, Container, Avatar } from "@mui/material";
import { useWalletConnectContext } from "../context/WalletConnectContext";
const ConnectWallet = () => {
const { connect, session } = useWalletConnectContext();
- const navigate = useNavigate()
+ const navigate = useNavigate();
useEffect(() => {
if (session) {
- navigate("/sign-with-ethereum")
+ navigate("/sign-with-ethereum");
}
- }, [session, navigate])
+ }, [session, navigate]);
const handler = async () => {
await connect();
- }
+ };
return (
-
+
-
-
- Urbit Onboarding
+
+
+ Testnet Onboarding
-
+
Connect wallet
-
diff --git a/src/pages/SignWithCosmos.tsx b/src/pages/SignWithCosmos.tsx
index 4c05006..16aad73 100644
--- a/src/pages/SignWithCosmos.tsx
+++ b/src/pages/SignWithCosmos.tsx
@@ -1,141 +1,87 @@
import React, { useMemo, useState } from "react";
import { useParams, useLocation } from "react-router-dom";
import { SnackbarProvider, enqueueSnackbar } from "notistack";
-import canonicalStringify from "canonical-json";
-import {
- Button,
- Dialog,
- DialogContent,
- DialogActions,
- Box,
- Typography,
-} from "@mui/material";
+import { Box, Typography } from "@mui/material";
import LoadingButton from "@mui/lab/LoadingButton/LoadingButton";
-
-// TODO: Import types exported from registry-sdk
import {
- MsgCreateBondEncodeObject,
-} from "@cerc-io/registry-sdk/dist/types/cerc/bond/message";
+ MsgOnboardParticipantEncodeObject,
+ typeUrlMsgOnboardParticipant,
+} from "@cerc-io/registry-sdk";
import { useWalletConnectContext } from "../context/WalletConnectContext";
const SignWithCosmos = () => {
const { session, signClient } = useWalletConnectContext();
- const { ethAddress, ethSignature } = useParams();
+ const { cosmosAddress, ethSignature } = useParams();
- const [openModal, setOpenModal] = useState(false);
const [isLoading, setIsLoading] = useState(false);
- const [cosmosSignature, setCosmosSignature] = useState("");
const location = useLocation();
const innerMessage = location.state;
- const cosmosAddress = innerMessage.address;
+ const ethAddress = innerMessage.address;
- const displayAttestation = useMemo(() => {
- return canonicalStringify(
- {
- payload: {
- msg: "Onboarding my Azimuth ID onto UrbitChain",
- address: ethAddress,
- payload: innerMessage,
+ const onboardParticipantMsg: MsgOnboardParticipantEncodeObject =
+ useMemo(() => {
+ return {
+ typeUrl: typeUrlMsgOnboardParticipant,
+ value: {
+ participant: cosmosAddress,
+ ethPayload: innerMessage,
+ ethSignature,
},
- signatures: [cosmosSignature, ethSignature],
- },
- null,
- 2
- );
- }, [ethAddress, cosmosSignature, ethSignature, innerMessage]);
+ };
+ }, [cosmosAddress, innerMessage, ethSignature]);
- const message = useMemo(() => {
- return {
- msg: "Onboarding my Azimuth ID onto UrbitChain",
- address: ethAddress,
- payload: innerMessage,
- };
- }, [ethAddress, innerMessage]);
-
- const signCosmos = async () => {
+ const sendTransaction = async (
+ transactionMessage: MsgOnboardParticipantEncodeObject
+ ) => {
if (!ethAddress) {
+ enqueueSnackbar("Set ethereum address");
return;
}
+
try {
setIsLoading(true);
- const signDoc = {
- msgs: [],
- fee: { amount: [], gas: "23" },
- chain_id: "cosmos:cosmoshub-4",
- memo: canonicalStringify(message),
- account_number: "7",
- sequence: "54",
- };
- const params = { signerAddress: cosmosAddress, signDoc };
-
- const signedMessage = await signClient!.request<{ signature: string }>({
+ const params = { transactionMessage, signer: cosmosAddress };
+ const responseFromWallet = await signClient!.request<{
+ code: number;
+ }>({
topic: session!.topic,
- chainId: "cosmos:cosmoshub-4",
+ chainId: "cosmos:laconic_9000-1", // TODO: Get chain ID from .env
request: {
- method: "cosmos_signAmino",
+ method: "cosmos_sendTransaction",
params,
},
});
- setIsLoading(false);
- setOpenModal(true);
- setCosmosSignature(signedMessage.signature);
- } catch (error) {
- setIsLoading(false);
- setOpenModal(false);
- enqueueSnackbar("Error signing message", { variant: "error" });
- }
- };
-
- const sendTransaction = async (
- transactionMessage: MsgCreateBondEncodeObject
- ) => {
- try {
- if (ethAddress) {
- setIsLoading(true);
-
- const params = { transactionMessage };
- const responseFromWallet = await signClient!.request<{
- code: number
- }>({
- topic: session!.topic,
- chainId: "cosmos:laconic_9000-1", // TODO: Get chain from WalletConnect
- request: {
- method: "cosmos_sendTransaction",
- params,
- },
- });
- if (responseFromWallet.code !== 0) {
- enqueueSnackbar("Error creating bond", { variant: "error" });
- } else {
- enqueueSnackbar("Created bond", { variant: "success" });
- }
+ if (responseFromWallet.code !== 0) {
+ enqueueSnackbar("Transaction not sent", { variant: "error" });
+ } else {
+ enqueueSnackbar("Transaction successful", { variant: "success" });
}
} catch (error) {
+ console.error(error);
enqueueSnackbar("Error in sending transaction", { variant: "error" });
+ } finally {
+ setIsLoading(false);
}
- setIsLoading(false);
};
- // TODO: Add method to create attestation
-
return (
- Sign with cosmos key
+ Send transaction to chain
Cosmos account: {cosmosAddress}
- Message:
+ Onboarding message:
{
}}
>
- {canonicalStringify(message, null, 2)}{" "}
+ {JSON.stringify(onboardParticipantMsg, null, 2)}{" "}
{
- signCosmos();
+ onClick={async () => {
+ await sendTransaction(onboardParticipantMsg);
}}
loading={isLoading}
>
Send transaction
-
-
);
diff --git a/src/pages/SignWithEthereum.tsx b/src/pages/SignWithEthereum.tsx
index 1187d44..5a3b5f2 100644
--- a/src/pages/SignWithEthereum.tsx
+++ b/src/pages/SignWithEthereum.tsx
@@ -1,16 +1,11 @@
-import React, { useState, useMemo, useEffect, useCallback } from "react";
+import React, { useState, useMemo, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { SnackbarProvider, enqueueSnackbar } from "notistack";
import canonicalStringify from "canonical-json";
import {
- Button,
Select,
MenuItem,
- Dialog,
- DialogTitle,
- DialogContent,
- DialogActions,
Box,
Typography,
} from "@mui/material";
@@ -35,15 +30,14 @@ const SignWithEthereum = () => {
const [cosmosAddress, setCosmosAddress] = useState("");
- const [openModal, setOpenModal] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const message = useMemo(() => {
return {
- msg: "Onboarding my cosmos validator onto UrbitChain",
- address: cosmosAddress,
+ msg: "Register my account as a validator on the Laconic network",
+ address: ethAddress,
};
- }, [cosmosAddress]);
+ }, [ethAddress]);
const signEth = async () => {
if (session && signClient) {
@@ -51,7 +45,7 @@ const SignWithEthereum = () => {
setIsLoading(true)
const jsonMessage = canonicalStringify(message);
const hexMsg = utf8ToHex(jsonMessage, true);
- const ethSignature: string = await signClient!.request({
+ const receivedEthSig: string = await signClient!.request({
topic: session!.topic,
chainId: "eip155:1",
request: {
@@ -61,22 +55,17 @@ const SignWithEthereum = () => {
});
setIsLoading(false)
setEthSignature(ethSignature);
- setOpenModal(true);
+ navigate(`/sign-with-cosmos/${cosmosAddress}/${receivedEthSig}`, {
+ state: message,
+ });
} catch (error) {
console.log("err in signing ", error);
setIsLoading(false)
- setOpenModal(false);
enqueueSnackbar("Error signing message", { variant: "error" });
}
}
};
- const submitHandler = useCallback(() => {
- navigate(`/sign-with-cosmos/${ethAddress}/${ethSignature}`, {
- state: message,
- });
- setOpenModal(false);
- }, [ethAddress, ethSignature, navigate, message]);
return (
@@ -143,42 +132,6 @@ const SignWithEthereum = () => {
Sign using Ethereum key
-
) : (