Skip to content

Commit

Permalink
feat: WalletConnect integration, request
Browse files Browse the repository at this point in the history
requests are supported. Tested:
 - send tez
 - delegate / UndelegationSignPage
 - originate / call contract
 - stake / unstake / finalize unstake
  • Loading branch information
dianasavvatina committed Nov 11, 2024
1 parent 244090c commit cb4af5c
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 297 deletions.
11 changes: 2 additions & 9 deletions apps/desktop/src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/* istanbul ignore file */
import { DynamicModalContext, useDynamicModal } from "@umami/components";
import { useDataPolling } from "@umami/data-polling";
import {
WalletClient,
useImplicitAccounts,
useResetBeaconConnections,
useResetWcConnections,
} from "@umami/state";
import { WalletClient, useImplicitAccounts, useResetBeaconConnections } from "@umami/state";
import { noop } from "lodash";
import { useEffect } from "react";
import { HashRouter, Navigate, Route, Routes } from "react-router-dom";
Expand Down Expand Up @@ -65,12 +60,10 @@ const LoggedInRouterWithPolling = () => {

const LoggedOutRouter = () => {
const resetBeaconConnections = useResetBeaconConnections();
const resetWcConnections = useResetWcConnections();

useEffect(() => {
WalletClient.destroy().then(resetBeaconConnections).catch(noop);
resetWcConnections();
}, [resetBeaconConnections, resetWcConnections]);
}, [resetBeaconConnections]);

return (
<HashRouter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ export const useSignWithBeacon = ({
isSigning,
onSign,
network: headerProps.network,
form,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const useSignWithWalletConnect = ({
isSigning: false,
onSign: async () => {},
network: null,
form,
};
}

Expand All @@ -50,6 +49,5 @@ export const useSignWithWalletConnect = ({
isSigning,
onSign,
network: headerProps.network,
form,
};
};
16 changes: 10 additions & 6 deletions apps/web/src/components/SendFlow/sdk/ContractCallSignPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -24,18 +24,22 @@ 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,
entrypoint,
args,
} = operation.operations[0] as ContractCall;
const color = useColor();
const { isSigning, onSign, network, fee, form } = calculatedSignProps;
const form = useForm({ defaultValues: { executeParams: operation.estimates } });

return (
<FormProvider {...form}>
Expand Down
16 changes: 10 additions & 6 deletions apps/web/src/components/SendFlow/sdk/DelegationSignPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
<FormProvider {...form}>
Expand Down
16 changes: 10 additions & 6 deletions apps/web/src/components/SendFlow/sdk/FinalizeUnstakeSignPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 (
<FormProvider {...form}>
Expand All @@ -48,7 +52,7 @@ export const OriginationOperationSignPage = (
Network:
</Heading>
<Text color={color("700")} fontWeight="400" size="sm">
{capitalize(headerProps.networkName)}
{capitalize(headerProps.network.name)}
</Text>
</Flex>
</ModalHeader>
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/SendFlow/sdk/SingleSignPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const SingleSignPage = (signProps: SdkSignPageProps) => {
const walletConnectCalculatedProps = useSignWithWalletConnect({ ...signProps });
const calculatedProps =
signProps.requestId.sdkType === "beacon" ? beaconCalculatedProps : walletConnectCalculatedProps;
console.log("SingleSignPage, signProps, calculatedProps", signProps, calculatedProps);

switch (operationType) {
case "tez": {
Expand Down
16 changes: 10 additions & 6 deletions apps/web/src/components/SendFlow/sdk/StakeSignPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
<FormProvider {...form}>
Expand Down
17 changes: 10 additions & 7 deletions apps/web/src/components/SendFlow/sdk/TezSignPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
<FormProvider {...form}>
Expand Down
16 changes: 10 additions & 6 deletions apps/web/src/components/SendFlow/sdk/UndelegationSignPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
<FormProvider {...form}>
Expand Down
16 changes: 10 additions & 6 deletions apps/web/src/components/SendFlow/sdk/UnstakeSignPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
<FormProvider {...form}>
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/components/SendFlow/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export type CalculatedSignProps = {
isSigning: boolean;
onSign: (tezosToolkit: TezosToolkit) => Promise<void>;
network: any;
form: any;
};

export type sdkType = "beacon" | "walletconnect";
Expand Down
12 changes: 5 additions & 7 deletions apps/web/src/components/WalletConnect/SessionProposalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import {
import { type WalletKitTypes } from "@reown/walletkit";
import { useDynamicModalContext } from "@umami/components";
import {
useAddWcConnection,
useAsyncActionHandler,
useGetImplicitAccount,
useWcPeers,
useToggleWcPeerListUpdated,
walletKit,
} from "@umami/state";
import { type NetworkName } from "@umami/tezos";
import { type SessionTypes } from "@walletconnect/types";
import { buildApprovedNamespaces, getSdkError } from "@walletconnect/utils";
import { FormProvider, useForm } from "react-hook-form";
Expand All @@ -40,9 +38,9 @@ export const SessionProposalModal = ({
proposal: WalletKitTypes.SessionProposal;
network: NetworkType;
}) => {
const addConnectionToWcSlice = useAddWcConnection();
// const addWcTopicToAcc = useAddWcTopicToAcc();
const getAccount = useGetImplicitAccount();
const { refresh } = useWcPeers();
const toggleWcPeerListUpdated = useToggleWcPeerListUpdated();

const { onClose } = useDynamicModalContext();
const { isLoading, handleAsyncAction } = useAsyncActionHandler();
Expand Down Expand Up @@ -77,8 +75,8 @@ export const SessionProposalModal = ({
namespaces,
sessionProperties: {},
});
await addConnectionToWcSlice(session, account.address.pkh, network.split(":")[1] as NetworkName);
await refresh();
console.log("Approved session", session);
toggleWcPeerListUpdated();
onClose();
});

Expand Down
Loading

0 comments on commit cb4af5c

Please sign in to comment.