diff --git a/src/pages/SignWithCosmos.tsx b/src/pages/SignWithCosmos.tsx index b369d5d..03b0210 100644 --- a/src/pages/SignWithCosmos.tsx +++ b/src/pages/SignWithCosmos.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react"; import { useLocation, useNavigate } from "react-router-dom"; import { enqueueSnackbar } from "notistack"; -import { Box, Card, CardContent, Grid, Typography } from "@mui/material"; +import { Box, Divider, Typography } from "@mui/material"; import LoadingButton from "@mui/lab/LoadingButton/LoadingButton"; import { MsgOnboardParticipantEncodeObject, @@ -11,22 +11,27 @@ import { import { StargateClient } from "@cosmjs/stargate"; import { useWalletConnectContext } from "../context/WalletConnectContext"; -import SelectRoleCard, {Role} from "../components/SelectRoleCard"; +import SelectRoleCard, { Role } from "../components/SelectRoleCard"; import { HASHED_SUBSCRIBER_ID_KEY } from "../constants"; +import { Layout } from "../layout/Layout"; const SignWithCosmos = () => { const { session, signClient } = useWalletConnectContext(); const location = useLocation(); const [isLoading, setIsLoading] = useState(false); - const [balance, setBalance] = useState(''); + const [balance, setBalance] = useState(""); const [isRequesting, setIsRequesting] = useState(false); const [isTncAccepted, setIsTncAccepted] = useState(false); const [role, setRole] = useState(Role.Participant); const navigate = useNavigate(); - const {message: innerMessage, cosmosAddress, receivedEthSig: ethSignature} = location.state as { + const { + message: innerMessage, + cosmosAddress, + receivedEthSig: ethSignature, + } = location.state as { message?: { msg: string; address: string; @@ -51,7 +56,7 @@ const SignWithCosmos = () => { ethPayload: innerMessage, ethSignature: ethSignature!, kycId: subscriberIdHash!, - role + role, }, }; }, [cosmosAddress, innerMessage, ethSignature, subscriberIdHash, role]); @@ -59,22 +64,27 @@ const SignWithCosmos = () => { const handleTokenRequest = async () => { try { setIsRequesting(true); - const response = await fetch(`${process.env.REACT_APP_FAUCET_ENDPOINT!}/faucet`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', + const response = await fetch( + `${process.env.REACT_APP_FAUCET_ENDPOINT!}/faucet`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + address: cosmosAddress, + }), }, - body: JSON.stringify({ - address: cosmosAddress, - }), - }); + ); if (response.ok) { - enqueueSnackbar('Tokens sent successfully', { variant: "success" }); + enqueueSnackbar("Tokens sent successfully", { variant: "success" }); } else { const errorResponse = await response.json(); if (response.status === 429) { - enqueueSnackbar(`${response.statusText} : ${errorResponse.error}`, { variant: "error" }); + enqueueSnackbar(`${response.statusText} : ${errorResponse.error}`, { + variant: "error", + }); } else { throw new Error(errorResponse.error); } @@ -90,7 +100,7 @@ const SignWithCosmos = () => { }; const sendTransaction = async ( - transactionMessage: MsgOnboardParticipantEncodeObject + transactionMessage: MsgOnboardParticipantEncodeObject, ) => { if (!ethAddress) { enqueueSnackbar("Set nitro address"); @@ -100,7 +110,9 @@ const SignWithCosmos = () => { try { setIsLoading(true); - enqueueSnackbar("View and sign the message from your Laconic Wallet", { variant: "info" }); + enqueueSnackbar("View and sign the message from your Laconic Wallet", { + variant: "info", + }); const params = { transactionMessage, signer: cosmosAddress }; const responseFromWallet = await signClient!.request<{ @@ -118,8 +130,8 @@ const SignWithCosmos = () => { } else { navigate("/onboarding-success", { state: { - cosmosAddress - } + cosmosAddress, + }, }); } } catch (error) { @@ -132,11 +144,16 @@ const SignWithCosmos = () => { const getBalances = useCallback(async () => { try { - const cosmosClient = await createCosmosClient(process.env.REACT_APP_LACONICD_RPC_ENDPOINT!); - const balance = await cosmosClient.getBalance(cosmosAddress!, process.env.REACT_APP_LACONICD_DENOM!); + const cosmosClient = await createCosmosClient( + process.env.REACT_APP_LACONICD_RPC_ENDPOINT!, + ); + const balance = await cosmosClient.getBalance( + cosmosAddress!, + process.env.REACT_APP_LACONICD_DENOM!, + ); setBalance(balance.amount); } catch (error) { - console.error('Error fetching balance:', error); + console.error("Error fetching balance:", error); throw error; } }, [cosmosAddress, createCosmosClient]); @@ -146,69 +163,77 @@ const SignWithCosmos = () => { }, [getBalances]); return ( - - Please accept terms and conditions to continue - setIsTncAccepted(true)} handleRoleChange={setRole}/> - Send transaction to chain - Laconic Account: - - - - - Address: {cosmosAddress} - Balance: {balance} {process.env.REACT_APP_LACONICD_DENOM} - - - - Request tokens from Faucet - - - - - - - Onboarding message:
-
- -
-          {JSON.stringify(onboardParticipantMsg, null, 2)}{" "}
-        
-
- - + <> + {!isTncAccepted && ( + + setIsTncAccepted(true)} + handleRoleChange={setRole} + /> + + )} + + Laconic Account: + + Address: {cosmosAddress} + + Balance: {balance} {process.env.REACT_APP_LACONICD_DENOM} + + { - await sendTransaction(onboardParticipantMsg); - }} - loading={isLoading} - disabled={isTncAccepted ? (balance === '0') : !isTncAccepted} + onClick={handleTokenRequest} + disabled={isTncAccepted ? isRequesting : !isTncAccepted} + loading={isRequesting} > - Send transaction + Request tokens from Faucet - -
+ + Onboarding message: + + +
+            {JSON.stringify(onboardParticipantMsg, null, 2)}{" "}
+          
+
+ + + { + await sendTransaction(onboardParticipantMsg); + }} + loading={isLoading} + disabled={isTncAccepted ? balance === "0" : !isTncAccepted} + > + Send transaction + + + + ); };