From a4fff5c84eda68acd1addc60ee61bf1e73de1ba4 Mon Sep 17 00:00:00 2001 From: Diana Savatina Date: Thu, 19 Dec 2024 16:13:12 +0000 Subject: [PATCH] feat: WalletConnect integration, part 8, verify --- .../src/components/SendFlow/common/Header.tsx | 63 +++++++++-------- .../SendFlow/common/TezSignPage.test.tsx | 2 + apps/web/src/components/SendFlow/utils.tsx | 4 ++ .../WalletConnect/ProjectInfoCard.tsx | 8 +-- .../WalletConnect/SessionProposalModal.tsx | 10 ++- .../WalletConnect/VerifyInfobox.tsx | 69 ++++++++++++++++--- .../WalletConnect/useHandleWcRequest.tsx | 4 ++ .../common/SignPayloadRequestModal.test.tsx | 47 +++++++++++++ .../common/SignPayloadRequestModal.tsx | 8 +++ 9 files changed, 167 insertions(+), 48 deletions(-) diff --git a/apps/web/src/components/SendFlow/common/Header.tsx b/apps/web/src/components/SendFlow/common/Header.tsx index c032a227d6..c806f31567 100644 --- a/apps/web/src/components/SendFlow/common/Header.tsx +++ b/apps/web/src/components/SendFlow/common/Header.tsx @@ -3,6 +3,7 @@ import { capitalize } from "lodash"; import { CodeSandboxIcon } from "../../../assets/icons"; import { useColor } from "../../../styles/useColor"; +import { VerifyInfobox } from "../../WalletConnect/VerifyInfobox"; import { SignPageHeader } from "../SignPageHeader"; import { type SignHeaderProps } from "../utils"; @@ -10,33 +11,41 @@ export const Header = ({ headerProps }: { headerProps: SignHeaderProps }) => { const color = useColor(); return ( - - - - Network: - - - {capitalize(headerProps.network.name)} - - + <> + + + + Network: + + + {capitalize(headerProps.network.name)} + + - - - } - src={headerProps.appIcon} - /> - - {headerProps.appName} - - + + + } + src={headerProps.appIcon} + /> + + {headerProps.appName} + + + {headerProps.requestId.sdkType === "walletconnect" ? ( + + ) : null} + ); }; diff --git a/apps/web/src/components/SendFlow/common/TezSignPage.test.tsx b/apps/web/src/components/SendFlow/common/TezSignPage.test.tsx index 682c7832d1..407e910d68 100644 --- a/apps/web/src/components/SendFlow/common/TezSignPage.test.tsx +++ b/apps/web/src/components/SendFlow/common/TezSignPage.test.tsx @@ -73,6 +73,8 @@ describe("", () => { expect(screen.getByText("Ghostnet")).toBeInTheDocument(); expect(screen.queryByText("Mainnet")).not.toBeInTheDocument(); + expect(screen.queryByText("verifyinfobox")).not.toBeInTheDocument(); + const signButton = screen.getByRole("button", { name: "Confirm Transaction", }); diff --git a/apps/web/src/components/SendFlow/utils.tsx b/apps/web/src/components/SendFlow/utils.tsx index 45a54f2547..2b77f88f7f 100644 --- a/apps/web/src/components/SendFlow/utils.tsx +++ b/apps/web/src/components/SendFlow/utils.tsx @@ -76,6 +76,8 @@ export type SignHeaderProps = { network: Network; appName: string; appIcon?: string; + isScam?: boolean; + validationStatus?: "VALID" | "INVALID" | "UNKNOWN"; requestId: SignRequestId; }; @@ -89,6 +91,8 @@ export type SignPayloadProps = { appName: string; appIcon?: string; payload: string; + isScam?: boolean; + validationStatus?: "VALID" | "INVALID" | "UNKNOWN"; signer: ImplicitAccount; signingType: SigningType; }; diff --git a/apps/web/src/components/WalletConnect/ProjectInfoCard.tsx b/apps/web/src/components/WalletConnect/ProjectInfoCard.tsx index 78cc0ce66e..04b850952d 100644 --- a/apps/web/src/components/WalletConnect/ProjectInfoCard.tsx +++ b/apps/web/src/components/WalletConnect/ProjectInfoCard.tsx @@ -1,8 +1,6 @@ -import { Avatar, Box, Card, Flex, Icon, Link, Text } from "@chakra-ui/react"; +import { Avatar, Box, Card, Link, Text } from "@chakra-ui/react"; import { type SignClientTypes } from "@walletconnect/types"; -import { PencilIcon } from "../../assets/icons"; - type Props = { metadata: SignClientTypes.Metadata; intention?: string; @@ -38,10 +36,6 @@ export const ProjectInfoCard = ({ metadata, intention }: Props) => { {url} - - - Cannot Verify: to be implemented - ); }; diff --git a/apps/web/src/components/WalletConnect/SessionProposalModal.tsx b/apps/web/src/components/WalletConnect/SessionProposalModal.tsx index 0122248b56..91b7c4c188 100644 --- a/apps/web/src/components/WalletConnect/SessionProposalModal.tsx +++ b/apps/web/src/components/WalletConnect/SessionProposalModal.tsx @@ -22,7 +22,7 @@ import { useToggleWcPeerListUpdated, walletKit, } from "@umami/state"; -import { type SessionTypes } from "@walletconnect/types"; +import { type SessionTypes, type Verify } from "@walletconnect/types"; import { buildApprovedNamespaces, getSdkError } from "@walletconnect/utils"; import { FormProvider, useForm } from "react-hook-form"; @@ -46,6 +46,10 @@ export const SessionProposalModal = ({ const { onClose } = useDynamicModalContext(); const { isLoading, handleAsyncAction } = useAsyncActionHandler(); + const verifyContext: Verify.Context = proposal.verifyContext; + const isScam = verifyContext.verified.isScam ?? false; + const validationStatus = verifyContext.verified.validation; + const form = useForm<{ address: string }>({ mode: "onBlur", }); @@ -97,6 +101,7 @@ export const SessionProposalModal = ({ + Requested permissions @@ -132,7 +137,6 @@ export const SessionProposalModal = ({ {network} - @@ -141,7 +145,7 @@ export const SessionProposalModal = ({