diff --git a/apps/web/src/components/SendFlow/Beacon/useSignWithBeacon.tsx b/apps/web/src/components/SendFlow/Beacon/useSignWithBeacon.tsx
index 579724d9ff..7def3c8f69 100644
--- a/apps/web/src/components/SendFlow/Beacon/useSignWithBeacon.tsx
+++ b/apps/web/src/components/SendFlow/Beacon/useSignWithBeacon.tsx
@@ -2,7 +2,7 @@ import { BeaconMessageType, type OperationResponseInput } from "@airgap/beacon-w
import { type TezosToolkit } from "@taquito/taquito";
import { useDynamicModalContext } from "@umami/components";
import { executeOperations, totalFee } from "@umami/core";
-import { WalletClient, useAsyncActionHandler, useFindNetwork } from "@umami/state";
+import { WalletClient, useAsyncActionHandler } from "@umami/state";
import { useForm } from "react-hook-form";
import { SuccessStep } from "../SuccessStep";
@@ -15,7 +15,6 @@ export const useSignWithBeacon = ({
}: SdkSignPageProps): CalculatedSignProps => {
const { isLoading: isSigning, handleAsyncAction } = useAsyncActionHandler();
const { openWith } = useDynamicModalContext();
- const findNetwork = useFindNetwork();
const form = useForm({ defaultValues: { executeParams: operation.estimates } });
@@ -45,7 +44,6 @@ export const useSignWithBeacon = ({
fee: totalFee(form.watch("executeParams")),
isSigning,
onSign,
- network: findNetwork(headerProps.networkName),
- form,
+ network: headerProps.network,
};
};
diff --git a/apps/web/src/components/SendFlow/WalletConnect/useSignWithWc.tsx b/apps/web/src/components/SendFlow/WalletConnect/useSignWithWc.tsx
new file mode 100644
index 0000000000..e3f688526c
--- /dev/null
+++ b/apps/web/src/components/SendFlow/WalletConnect/useSignWithWc.tsx
@@ -0,0 +1,53 @@
+import { type TezosToolkit } from "@taquito/taquito";
+import { useDynamicModalContext } from "@umami/components";
+import { executeOperations, totalFee } from "@umami/core";
+import { useAsyncActionHandler, walletKit } from "@umami/state";
+import { formatJsonRpcResult } from "@walletconnect/jsonrpc-utils";
+import { useForm } from "react-hook-form";
+
+import { SuccessStep } from "../SuccessStep";
+import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
+
+export const useSignWithWalletConnect = ({
+ operation,
+ headerProps,
+ requestId,
+}: SdkSignPageProps): CalculatedSignProps => {
+ const { isLoading: isSigning, handleAsyncAction } = useAsyncActionHandler();
+ const { openWith } = useDynamicModalContext();
+
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
+
+ if (requestId.sdkType !== "walletconnect") {
+ return {
+ fee: 0,
+ isSigning: false,
+ onSign: async () => {},
+ network: null,
+ };
+ }
+
+ const onSign = async (tezosToolkit: TezosToolkit) =>
+ handleAsyncAction(
+ async () => {
+ const { opHash } = await executeOperations(
+ { ...operation, estimates: form.watch("executeParams") },
+ tezosToolkit
+ );
+
+ const response = formatJsonRpcResult(requestId.id, { hash: opHash });
+ await walletKit.respondSessionRequest({ topic: requestId.topic, response });
+ return openWith();
+ },
+ error => ({
+ description: `Failed to confirm Beacon operation: ${error.message}`,
+ })
+ );
+
+ return {
+ fee: totalFee(form.watch("executeParams")),
+ isSigning,
+ onSign,
+ network: headerProps.network,
+ };
+};
diff --git a/apps/web/src/components/SendFlow/sdk/BatchSignPage.tsx b/apps/web/src/components/SendFlow/sdk/BatchSignPage.tsx
index 8616529ef8..5e8858db05 100644
--- a/apps/web/src/components/SendFlow/sdk/BatchSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/BatchSignPage.tsx
@@ -23,6 +23,7 @@ import { useSignWithBeacon } from "../Beacon/useSignWithBeacon";
import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type SdkSignPageProps } from "../utils";
+import { useSignWithWalletConnect } from "../WalletConnect/useSignWithWc";
export const BatchSignPage = (
signProps: SdkSignPageProps,
@@ -30,7 +31,10 @@ export const BatchSignPage = (
) => {
const color = useColor();
- const calculatedProps = useSignWithBeacon({ ...signProps });
+ const beaconCalculatedProps = useSignWithBeacon({ ...signProps });
+ const walletConnectCalculatedProps = useSignWithWalletConnect({ ...signProps });
+ const calculatedProps =
+ signProps.requestId.sdkType === "beacon" ? beaconCalculatedProps : walletConnectCalculatedProps;
const { isSigning, onSign, network, fee, form } = calculatedProps;
const { signer, operations } = signProps.operation;
diff --git a/apps/web/src/components/SendFlow/sdk/ContractCallSignPage.tsx b/apps/web/src/components/SendFlow/sdk/ContractCallSignPage.tsx
index b9b261fbd7..9af9172441 100644
--- a/apps/web/src/components/SendFlow/sdk/ContractCallSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/ContractCallSignPage.tsx
@@ -12,7 +12,7 @@ import {
ModalFooter,
} from "@chakra-ui/react";
import { type ContractCall } from "@umami/core";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { Header } from "./Header";
import { useColor } from "../../../styles/useColor";
@@ -24,10 +24,14 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const ContractCallSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
+export const ContractCallSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
const {
amount: mutezAmount,
contract,
@@ -35,7 +39,7 @@ export const ContractCallSignPage = (
args,
} = operation.operations[0] as ContractCall;
const color = useColor();
- const { isSigning, onSign, network, fee, form } = calculatedSignProps;
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
return (
diff --git a/apps/web/src/components/SendFlow/sdk/DelegationSignPage.tsx b/apps/web/src/components/SendFlow/sdk/DelegationSignPage.tsx
index b41e476ed9..8ab37e4382 100644
--- a/apps/web/src/components/SendFlow/sdk/DelegationSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/DelegationSignPage.tsx
@@ -1,6 +1,6 @@
import { Flex, FormLabel, ModalBody, ModalContent, ModalFooter } from "@chakra-ui/react";
import { type Delegation } from "@umami/core";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { Header } from "./Header";
import { AddressTile } from "../../AddressTile/AddressTile";
@@ -9,13 +9,17 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const DelegationSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
+export const DelegationSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
const { recipient } = operation.operations[0] as Delegation;
- const { isSigning, onSign, network, fee, form } = calculatedSignProps;
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
return (
diff --git a/apps/web/src/components/SendFlow/sdk/FinalizeUnstakeSignPage.tsx b/apps/web/src/components/SendFlow/sdk/FinalizeUnstakeSignPage.tsx
index 76b2969117..cd1e081e86 100644
--- a/apps/web/src/components/SendFlow/sdk/FinalizeUnstakeSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/FinalizeUnstakeSignPage.tsx
@@ -1,6 +1,6 @@
import { Flex, FormLabel, ModalBody, ModalContent, ModalFooter } from "@chakra-ui/react";
import { useAccountTotalFinalizableUnstakeAmount } from "@umami/state";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { Header } from "./Header";
import { AddressTile } from "../../AddressTile/AddressTile";
@@ -9,11 +9,15 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const FinalizeUnstakeSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
- const { isSigning, onSign, network, fee, form } = calculatedSignProps;
+export const FinalizeUnstakeSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
const totalFinalizableAmount = useAccountTotalFinalizableUnstakeAmount(
operation.signer.address.pkh
);
diff --git a/apps/web/src/components/SendFlow/sdk/Header.tsx b/apps/web/src/components/SendFlow/sdk/Header.tsx
index 7256daa035..c032a227d6 100644
--- a/apps/web/src/components/SendFlow/sdk/Header.tsx
+++ b/apps/web/src/components/SendFlow/sdk/Header.tsx
@@ -16,7 +16,7 @@ export const Header = ({ headerProps }: { headerProps: SignHeaderProps }) => {
Network:
- {capitalize(headerProps.networkName)}
+ {capitalize(headerProps.network.name)}
diff --git a/apps/web/src/components/SendFlow/sdk/OriginationOperationSignPage.tsx b/apps/web/src/components/SendFlow/sdk/OriginationOperationSignPage.tsx
index e9d5431bda..ee65587e93 100644
--- a/apps/web/src/components/SendFlow/sdk/OriginationOperationSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/OriginationOperationSignPage.tsx
@@ -17,7 +17,7 @@ import {
} from "@chakra-ui/react";
import { type ContractOrigination } from "@umami/core";
import { capitalize } from "lodash";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { CodeSandboxIcon } from "../../../assets/icons";
import { useColor } from "../../../styles/useColor";
@@ -27,13 +27,17 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const OriginationOperationSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
- const { isSigning, onSign, network, form, fee } = calculatedSignProps;
+export const OriginationOperationSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
const color = useColor();
const { code, storage } = operation.operations[0] as ContractOrigination;
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
return (
@@ -48,7 +52,7 @@ export const OriginationOperationSignPage = (
Network:
- {capitalize(headerProps.networkName)}
+ {capitalize(headerProps.network.name)}
diff --git a/apps/web/src/components/SendFlow/sdk/SingleSignPage.tsx b/apps/web/src/components/SendFlow/sdk/SingleSignPage.tsx
index c51abd0d7a..b1160855aa 100644
--- a/apps/web/src/components/SendFlow/sdk/SingleSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/SingleSignPage.tsx
@@ -8,11 +8,16 @@ import { TezSignPage } from "./TezSignPage";
import { UndelegationSignPage } from "./UndelegationSignPage";
import { UnstakeSignPage } from "./UnstakeSignPage";
import { useSignWithBeacon } from "../Beacon/useSignWithBeacon";
+import { useSignWithWalletConnect } from "../WalletConnect/useSignWithWc";
export const SingleSignPage = (signProps: SdkSignPageProps) => {
const operationType = signProps.operation.operations[0].type;
- const calculatedProps = useSignWithBeacon({ ...signProps });
+ const beaconCalculatedProps = useSignWithBeacon({ ...signProps });
+ const walletConnectCalculatedProps = useSignWithWalletConnect({ ...signProps });
+ const calculatedProps =
+ signProps.requestId.sdkType === "beacon" ? beaconCalculatedProps : walletConnectCalculatedProps;
+ console.log("SingleSignPage, signProps, calculatedProps", signProps, calculatedProps);
switch (operationType) {
case "tez": {
diff --git a/apps/web/src/components/SendFlow/sdk/StakeSignPage.tsx b/apps/web/src/components/SendFlow/sdk/StakeSignPage.tsx
index 025cf195be..237dfe4b84 100644
--- a/apps/web/src/components/SendFlow/sdk/StakeSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/StakeSignPage.tsx
@@ -1,6 +1,6 @@
import { Flex, FormLabel, ModalBody, ModalContent, ModalFooter } from "@chakra-ui/react";
import { type Stake } from "@umami/core";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { Header } from "./Header";
import { AddressTile } from "../../AddressTile/AddressTile";
@@ -9,13 +9,17 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const StakeSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
+export const StakeSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
const { amount: mutezAmount } = operation.operations[0] as Stake;
- const { isSigning, onSign, network, fee, form } = calculatedSignProps;
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
return (
diff --git a/apps/web/src/components/SendFlow/sdk/TezSignPage.tsx b/apps/web/src/components/SendFlow/sdk/TezSignPage.tsx
index f60792f4df..0d033b7730 100644
--- a/apps/web/src/components/SendFlow/sdk/TezSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/TezSignPage.tsx
@@ -1,6 +1,6 @@
import { Flex, FormLabel, ModalBody, ModalContent, ModalFooter } from "@chakra-ui/react";
import { type TezTransfer } from "@umami/core";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { Header } from "./Header";
import { AddressTile } from "../../AddressTile/AddressTile";
@@ -10,13 +10,16 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const TezSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
+export const TezSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
const { amount: mutezAmount, recipient } = operation.operations[0] as TezTransfer;
-
- const { isSigning, onSign, network, fee, form } = calculatedSignProps;
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
return (
diff --git a/apps/web/src/components/SendFlow/sdk/UndelegationSignPage.tsx b/apps/web/src/components/SendFlow/sdk/UndelegationSignPage.tsx
index 977bea20c0..c7094ff075 100644
--- a/apps/web/src/components/SendFlow/sdk/UndelegationSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/UndelegationSignPage.tsx
@@ -1,5 +1,5 @@
import { Flex, FormLabel, ModalBody, ModalContent, ModalFooter } from "@chakra-ui/react";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { Header } from "./Header";
import { AddressTile } from "../../AddressTile/AddressTile";
@@ -8,11 +8,15 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const UndelegationSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
- const { isSigning, onSign, network, form, fee } = calculatedSignProps;
+export const UndelegationSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
return (
diff --git a/apps/web/src/components/SendFlow/sdk/UnstakeSignPage.tsx b/apps/web/src/components/SendFlow/sdk/UnstakeSignPage.tsx
index 41c3088656..3bbb878cfd 100644
--- a/apps/web/src/components/SendFlow/sdk/UnstakeSignPage.tsx
+++ b/apps/web/src/components/SendFlow/sdk/UnstakeSignPage.tsx
@@ -1,6 +1,6 @@
import { Flex, FormLabel, ModalBody, ModalContent, ModalFooter } from "@chakra-ui/react";
import { type Unstake } from "@umami/core";
-import { FormProvider } from "react-hook-form";
+import { FormProvider, useForm } from "react-hook-form";
import { Header } from "./Header";
import { AddressTile } from "../../AddressTile/AddressTile";
@@ -9,13 +9,17 @@ import { SignButton } from "../SignButton";
import { SignPageFee } from "../SignPageFee";
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
-export const UnstakeSignPage = (
- { operation, headerProps }: SdkSignPageProps,
- calculatedSignProps: CalculatedSignProps
-) => {
+export const UnstakeSignPage = ({
+ operation,
+ headerProps,
+ isSigning,
+ onSign,
+ network,
+ fee,
+}: SdkSignPageProps & CalculatedSignProps) => {
const { amount: mutezAmount } = operation.operations[0] as Unstake;
- const { isSigning, onSign, network, fee, form } = calculatedSignProps;
+ const form = useForm({ defaultValues: { executeParams: operation.estimates } });
return (
diff --git a/apps/web/src/components/SendFlow/utils.tsx b/apps/web/src/components/SendFlow/utils.tsx
index 5e3430361c..a2c639c54d 100644
--- a/apps/web/src/components/SendFlow/utils.tsx
+++ b/apps/web/src/components/SendFlow/utils.tsx
@@ -18,7 +18,7 @@ import {
useGetOwnedAccount,
useSelectedNetwork,
} from "@umami/state";
-import { type ExecuteParams, type RawPkh } from "@umami/tezos";
+import { type ExecuteParams, type Network, type RawPkh } from "@umami/tezos";
import { repeat } from "lodash";
import { useState } from "react";
import { useForm, useFormContext } from "react-hook-form";
@@ -55,7 +55,6 @@ export type CalculatedSignProps = {
isSigning: boolean;
onSign: (tezosToolkit: TezosToolkit) => Promise;
network: any;
- form: any;
};
export type sdkType = "beacon" | "walletconnect";
@@ -72,7 +71,7 @@ export type SignRequestId =
};
export type SignHeaderProps = {
- networkName: string;
+ network: Network;
appName: string;
appIcon?: string;
};
diff --git a/apps/web/src/components/WalletConnect/WalletConnectProvider.tsx b/apps/web/src/components/WalletConnect/WalletConnectProvider.tsx
index aea33afec7..15ae92280d 100644
--- a/apps/web/src/components/WalletConnect/WalletConnectProvider.tsx
+++ b/apps/web/src/components/WalletConnect/WalletConnectProvider.tsx
@@ -16,6 +16,7 @@ import { getSdkError } from "@walletconnect/utils";
import { type PropsWithChildren, useEffect } from "react";
import { SessionProposalModal } from "./SessionProposalModal";
+import { useHandleWcRequest } from "./useHandleWcRequest";
export const WalletConnectProvider = ({ children }: PropsWithChildren) => {
const { handleAsyncActionUnsafe } = useAsyncActionHandler();
@@ -25,6 +26,8 @@ export const WalletConnectProvider = ({ children }: PropsWithChildren) => {
const availableNetworks: Network[] = useAvailableNetworks();
+ const handleWcRequest = useHandleWcRequest();
+
const onSessionProposal = (proposal: WalletKitTypes.SessionProposal) =>
handleAsyncActionUnsafe(async () => {
// dApp sends in the session proposal the required networks and the optional networks.
@@ -67,8 +70,8 @@ export const WalletConnectProvider = ({ children }: PropsWithChildren) => {
toggleWcPeerListUpdated();
};
- const onSessionRequest = async (event: WalletKitTypes.SessionRequest) => {
- try {
+ const onSessionRequest = (event: WalletKitTypes.SessionRequest) =>
+ handleAsyncActionUnsafe(async () => {
const activeSessions: Record = walletKit.getActiveSessions();
if (!(event.topic in activeSessions)) {
console.error("WalletConnect session request failed. Session not found", event);
@@ -83,8 +86,8 @@ export const WalletConnectProvider = ({ children }: PropsWithChildren) => {
description: `Session request from dApp ${session.peer.metadata.name}`,
status: "info",
});
- throw new Error("Not implemented");
- } catch (error) {
+ await handleWcRequest(event, session);
+ }).catch(async error => {
const { id, topic } = event;
const activeSessions: Record = walletKit.getActiveSessions();
console.error("WalletConnect session request failed", event, error);
@@ -103,8 +106,7 @@ export const WalletConnectProvider = ({ children }: PropsWithChildren) => {
// dApp is waiting so we need to notify it
const response = formatJsonRpcError(id, getSdkError("INVALID_METHOD").message);
await walletKit.respondSessionRequest({ topic, response });
- }
- };
+ });
useEffect(() => {
const initializeWallet = async () => {
diff --git a/apps/web/src/components/WalletConnect/useHandleWcRequest.tsx b/apps/web/src/components/WalletConnect/useHandleWcRequest.tsx
new file mode 100644
index 0000000000..cb888ebc71
--- /dev/null
+++ b/apps/web/src/components/WalletConnect/useHandleWcRequest.tsx
@@ -0,0 +1,123 @@
+import { useToast } from "@chakra-ui/react";
+import { useDynamicModalContext } from "@umami/components";
+import { type ImplicitAccount, estimate, toAccountOperations } from "@umami/core";
+import {
+ useAsyncActionHandler,
+ useFindNetwork,
+ useGetOwnedAccountSafe,
+ walletKit,
+} from "@umami/state";
+import { formatJsonRpcError } from "@walletconnect/jsonrpc-utils";
+import { type SessionTypes, type SignClientTypes, type Verify } from "@walletconnect/types";
+import { getSdkError } from "@walletconnect/utils";
+
+import { BatchSignPage } from "../SendFlow/sdk/BatchSignPage";
+import { SingleSignPage } from "../SendFlow/sdk/SingleSignPage";
+import { type SdkSignPageProps, type SignHeaderProps } from "../SendFlow/utils";
+
+/**
+ * @returns a function that handles a beacon message and opens a modal with the appropriate content
+ *
+ * For operation requests it will also try to convert the operation(s) to our {@link Operation} format,
+ * estimate the fee and open the BeaconSignPage only if it succeeds
+ */
+export const useHandleWcRequest = () => {
+ const { openWith } = useDynamicModalContext();
+ const { handleAsyncActionUnsafe } = useAsyncActionHandler();
+ const getAccount = useGetOwnedAccountSafe();
+ const findNetwork = useFindNetwork();
+ const toast = useToast();
+
+ return async (
+ event: {
+ verifyContext: Verify.Context;
+ } & SignClientTypes.BaseEventArgs<{
+ request: {
+ method: string;
+ params: any;
+ expiryTimestamp?: number;
+ };
+ chainId: string;
+ }>,
+ session: SessionTypes.Struct
+ ) => {
+ await handleAsyncActionUnsafe(
+ async () => {
+ const { id, topic, params } = event;
+ const { request, chainId } = params;
+
+ let modal;
+ let onClose;
+
+ switch (request.method) {
+ case "tezos_getAccounts": {
+ const response = formatJsonRpcError(id, getSdkError("INVALID_METHOD").message);
+ await walletKit.respondSessionRequest({ topic, response });
+ return;
+ }
+
+ case "tezos_sign": {
+ // onClose = async () => {
+ // const response = formatJsonRpcError(id, getSdkError("USER_REJECTED").message);
+ // await walletKit.respondSessionRequest({ topic, response });
+ // };
+ // return openWith(, { onClose });
+ const response = formatJsonRpcError(id, getSdkError("INVALID_METHOD").message);
+ await walletKit.respondSessionRequest({ topic, response });
+ return;
+ }
+
+ case "tezos_send": {
+ if (!request.params.account) {
+ throw new Error("Missing account in request");
+ }
+ const signer = getAccount(request.params.account);
+ if (!signer) {
+ throw new Error(`Unknown account, no signer: ${request.params.account}`);
+ }
+ const operation = toAccountOperations(
+ request.params.operations,
+ signer as ImplicitAccount
+ );
+ const network = findNetwork(chainId.split(":")[1]);
+ if (!network) {
+ const response = formatJsonRpcError(id, getSdkError("INVALID_EVENT").message);
+ await walletKit.respondSessionRequest({ topic, response });
+ toast({ description: `Unsupported network: ${chainId}`, status: "error" });
+ return;
+ }
+ const estimatedOperations = await estimate(operation, network);
+ console.log("got request", request);
+ const headerProps: SignHeaderProps = {
+ network,
+ appName: session.peer.metadata.name,
+ appIcon: session.peer.metadata.icons[0],
+ };
+ const signProps: SdkSignPageProps = {
+ headerProps: headerProps,
+ operation: estimatedOperations,
+ requestId: { sdkType: "walletconnect", id: id, topic },
+ };
+
+ if (operation.operations.length === 1) {
+ modal = ;
+ } else {
+ modal = ;
+ }
+ onClose = async () => {
+ const response = formatJsonRpcError(id, getSdkError("USER_REJECTED").message);
+ await walletKit.respondSessionRequest({ topic, response });
+ };
+
+ return openWith(modal, { onClose });
+ }
+ default:
+ throw new Error(`Unsupported method ${request.method}`);
+ }
+ }
+ // error => ({
+ // description: `Error while processing WalletConnect request: ${error.message}`,
+ // })
+ );
+ };
+};
diff --git a/apps/web/src/components/beacon/useHandleBeaconMessage.tsx b/apps/web/src/components/beacon/useHandleBeaconMessage.tsx
index 49dc19fac8..2e838abc35 100644
--- a/apps/web/src/components/beacon/useHandleBeaconMessage.tsx
+++ b/apps/web/src/components/beacon/useHandleBeaconMessage.tsx
@@ -19,7 +19,7 @@ import { PermissionRequestModal } from "./PermissionRequestModal";
import { SignPayloadRequestModal } from "./SignPayloadRequestModal";
import { BatchSignPage } from "../../components/SendFlow/sdk/BatchSignPage";
import { SingleSignPage } from "../../components/SendFlow/sdk/SingleSignPage";
-import { type SdkSignPageProps } from "../SendFlow/utils";
+import { type SdkSignPageProps, type SignHeaderProps } from "../SendFlow/utils";
/**
* @returns a function that handles a beacon message and opens a modal with the appropriate content
@@ -103,14 +103,14 @@ export const useHandleBeaconMessage = () => {
});
throw new Error(`Unknown account: ${message.sourceAddress}`);
}
+
const operation = toAccountOperations(
message.operationDetails,
signer as ImplicitAccount
);
const estimatedOperations = await estimate(operation, network);
- const headerProps = {
- requestId: message.id,
- networkName: message.network.type,
+ const headerProps: SignHeaderProps = {
+ network: network,
appName: message.appMetadata.name,
appIcon: message.appMetadata.icon,
};