Skip to content

Commit

Permalink
feat: WalletConnect integration, part 8, verify
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Dec 19, 2024
1 parent 689bd4c commit b7ee948
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 26 deletions.
5 changes: 5 additions & 0 deletions apps/web/src/components/SendFlow/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -37,6 +38,10 @@ export const Header = ({ headerProps }: { headerProps: SignHeaderProps }) => {
</AspectRatio>
<Heading size="sm">{headerProps.appName}</Heading>
</Flex>
<VerifyInfobox
isScam={headerProps.isScam ?? false}
validationStatus={headerProps.validationStatus ?? "UNKNOWN"}
/>
</SignPageHeader>
);
};
2 changes: 2 additions & 0 deletions apps/web/src/components/SendFlow/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export type SignHeaderProps = {
network: Network;
appName: string;
appIcon?: string;
isScam?: boolean;
validationStatus?: "VALID" | "INVALID" | "UNKNOWN";
};

export type SdkSignPageProps = {
Expand Down
8 changes: 1 addition & 7 deletions apps/web/src/components/WalletConnect/ProjectInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -38,10 +36,6 @@ export const ProjectInfoCard = ({ metadata, intention }: Props) => {
{url}
</Link>
</Box>
<Flex alignItems="center" justifyContent="center" marginTop="16px">
<Icon as={PencilIcon} verticalAlign="bottom" />
<Card marginLeft="8px">Cannot Verify: to be implemented</Card>
</Flex>
</Box>
);
};
10 changes: 7 additions & 3 deletions apps/web/src/components/WalletConnect/SessionProposalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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",
});
Expand Down Expand Up @@ -97,6 +101,7 @@ export const SessionProposalModal = ({
<ModalBody>
<Card>
<ProjectInfoCard metadata={proposal.params.proposer.metadata} />
<VerifyInfobox isScam={isScam} validationStatus={validationStatus} />
<Divider />
<Box marginBottom="16px" fontSize="xl" fontWeight="semibold">
Requested permissions
Expand Down Expand Up @@ -132,7 +137,6 @@ export const SessionProposalModal = ({
<Text marginLeft="8px">{network}</Text>
</Box>
<Divider />
<VerifyInfobox />
</Card>
</ModalBody>
<ModalFooter>
Expand All @@ -141,7 +145,7 @@ export const SessionProposalModal = ({
</Button>
<Button
width="100%"
isDisabled={!isValid}
isDisabled={!isValid || isScam}
isLoading={isLoading}
loadingText="Approving..."
onClick={onApprove}
Expand Down
67 changes: 56 additions & 11 deletions apps/web/src/components/WalletConnect/VerifyInfobox.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,62 @@
import { Box, Card, HStack, Icon, VStack } from "@chakra-ui/react";

import { AlertCircleIcon } from "../../assets/icons";
import { AlertCircleIcon, AlertTriangleIcon, VerifiedIcon } from "../../assets/icons";

export const VerifyInfobox = () => (
<Box textAlign="center">
<VStack spacing="16px">
<HStack margin="auto">
<Icon as={AlertCircleIcon} verticalAlign="bottom" />
<Card marginLeft="8px">Unknown domain</Card>
</HStack>
<Box margin="auto">
<Card>This domain was not verified. To be implemented.</Card>
</Box>
export const VerifyInfobox = ({
isScam,
validationStatus,
}: {
isScam: boolean;
validationStatus: "UNKNOWN" | "INVALID" | "VALID";
}) => (
<Box textAlign="left">
<VStack margin="auto" marginTop="16px" spacing="16px">
{isScam ? (
<HStack
margin="auto"
padding="8px"
border="1px solid"
borderColor="red.500"
borderRadius="md"
>
<Icon as={AlertTriangleIcon} verticalAlign="bottom" />
<Card marginLeft="8px">This domain is a suspected as a SCAM. Potential threat. </Card>
</HStack>
) : validationStatus === "UNKNOWN" ? (
<HStack
margin="auto"
padding="8px"
border="1px solid"
borderColor="yellow.500"
borderRadius="md"
>
<Icon as={AlertCircleIcon} verticalAlign="bottom" />
<Card marginLeft="8px">This domain is unknown. Cannot verify it.</Card>
</HStack>
) : validationStatus === "INVALID" ? (
<HStack
margin="auto"
padding="8px"
border="1px solid"
borderColor="yellow.500"
borderRadius="md"
>
<Icon as={AlertTriangleIcon} verticalAlign="bottom" />
<Card marginLeft="8px">This domain is invalid. </Card>
</HStack>
) : (
// VALID
<HStack
margin="auto"
padding="8px"
border="1px solid"
borderColor="green.500"
borderRadius="md"
>
<Icon as={VerifiedIcon} verticalAlign="bottom" />
<Card marginLeft="8px">This domain is verified. </Card>
</HStack>
)}
</VStack>
</Box>
);
6 changes: 1 addition & 5 deletions apps/web/src/components/WalletConnect/useHandleWcRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ export const useHandleWcRequest = () => {
case "tezos_getAccounts": {
const wcPeers = walletKit.getActiveSessions();
if (!(topic in wcPeers)) {
throw new WalletConnectError(
`Unknown session ${topic}`,
"UNAUTHORIZED_EVENT",
null
);
throw new WalletConnectError(`Unknown session ${topic}`, "UNAUTHORIZED_EVENT", null);
}
const session = wcPeers[topic];
const accountPkh = session.namespaces.tezos.accounts[0].split(":")[2];
Expand Down

1 comment on commit b7ee948

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.81% (1786/2131) 79.58% (850/1068) 78.27% (454/580)
apps/web Coverage: 83%
83.81% (1786/2131) 79.58% (850/1068) 78.27% (454/580)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.47% (207/251) 72.72% (88/121) 81.35% (48/59)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.79% (820/967) 81.03% (188/232) 78.59% (301/383)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.