Skip to content

Commit 188d44e

Browse files
Merge pull request #2285 from trilitech/wc_verify
feat: WalletConnect integration, part 8, verify
2 parents 9085d74 + 6127b2d commit 188d44e

17 files changed

+181
-61
lines changed

apps/web/src/components/SendFlow/Beacon/useSignWithBeacon.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
1111
export const useSignWithBeacon = ({
1212
operation,
1313
headerProps,
14-
requestId,
1514
}: SdkSignPageProps): CalculatedSignProps => {
1615
const { isLoading: isSigning, handleAsyncAction } = useAsyncActionHandler();
1716
const { openWith } = useDynamicModalContext();
@@ -28,7 +27,7 @@ export const useSignWithBeacon = ({
2827

2928
const response: OperationResponseInput = {
3029
type: BeaconMessageType.OperationResponse,
31-
id: requestId.id.toString(),
30+
id: headerProps.requestId.id.toString(),
3231
transactionHash: opHash,
3332
};
3433
await WalletClient.respond(response);

apps/web/src/components/SendFlow/WalletConnect/useSignWithWalletConnect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { type CalculatedSignProps, type SdkSignPageProps } from "../utils";
1111
export const useSignWithWalletConnect = ({
1212
operation,
1313
headerProps,
14-
requestId,
1514
}: SdkSignPageProps): CalculatedSignProps => {
1615
const { isLoading: isSigning, handleAsyncAction } = useAsyncActionHandler();
1716
const { openWith } = useDynamicModalContext();
1817

1918
const form = useForm({ defaultValues: { executeParams: operation.estimates } });
19+
const requestId = headerProps.requestId;
2020

2121
if (requestId.sdkType !== "walletconnect") {
2222
return {

apps/web/src/components/SendFlow/common/BatchSignPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export const BatchSignPage = (
3434
const beaconCalculatedProps = useSignWithBeacon({ ...signProps });
3535
const walletConnectCalculatedProps = useSignWithWalletConnect({ ...signProps });
3636
const calculatedProps =
37-
signProps.requestId.sdkType === "beacon" ? beaconCalculatedProps : walletConnectCalculatedProps;
37+
signProps.headerProps.requestId.sdkType === "beacon"
38+
? beaconCalculatedProps
39+
: walletConnectCalculatedProps;
3840

3941
const { isSigning, onSign, network, fee } = calculatedProps;
4042
const { signer, operations } = signProps.operation;

apps/web/src/components/SendFlow/common/Header.tsx

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,49 @@ import { capitalize } from "lodash";
33

44
import { CodeSandboxIcon } from "../../../assets/icons";
55
import { useColor } from "../../../styles/useColor";
6+
import { VerifyInfobox } from "../../WalletConnect/VerifyInfobox";
67
import { SignPageHeader } from "../SignPageHeader";
78
import { type SignHeaderProps } from "../utils";
89

910
export const Header = ({ headerProps }: { headerProps: SignHeaderProps }) => {
1011
const color = useColor();
1112

1213
return (
13-
<SignPageHeader>
14-
<Flex alignItems="center" justifyContent="center" marginTop="10px">
15-
<Heading marginRight="4px" color={color("700")} size="sm">
16-
Network:
17-
</Heading>
18-
<Text color={color("700")} fontWeight="400" size="sm">
19-
{capitalize(headerProps.network.name)}
20-
</Text>
21-
</Flex>
14+
<>
15+
<SignPageHeader>
16+
<Flex alignItems="center" justifyContent="center" marginTop="10px">
17+
<Heading marginRight="4px" color={color("700")} size="sm">
18+
Network:
19+
</Heading>
20+
<Text color={color("700")} fontWeight="400" size="sm">
21+
{capitalize(headerProps.network.name)}
22+
</Text>
23+
</Flex>
2224

23-
<Flex
24-
alignItems="center"
25-
marginTop="16px"
26-
padding="15px"
27-
borderRadius="4px"
28-
backgroundColor={color("100")}
29-
>
30-
<AspectRatio width="30px" marginRight="12px" ratio={1}>
31-
<Image
32-
borderRadius="4px"
33-
objectFit="cover"
34-
fallback={<CodeSandboxIcon width="36px" height="36px" />}
35-
src={headerProps.appIcon}
36-
/>
37-
</AspectRatio>
38-
<Heading size="sm">{headerProps.appName}</Heading>
39-
</Flex>
40-
</SignPageHeader>
25+
<Flex
26+
alignItems="center"
27+
marginTop="16px"
28+
padding="15px"
29+
borderRadius="4px"
30+
backgroundColor={color("100")}
31+
>
32+
<AspectRatio width="30px" marginRight="12px" ratio={1}>
33+
<Image
34+
borderRadius="4px"
35+
objectFit="cover"
36+
fallback={<CodeSandboxIcon width="36px" height="36px" />}
37+
src={headerProps.appIcon}
38+
/>
39+
</AspectRatio>
40+
<Heading size="sm">{headerProps.appName}</Heading>
41+
</Flex>
42+
</SignPageHeader>
43+
{headerProps.requestId.sdkType === "walletconnect" ? (
44+
<VerifyInfobox
45+
isScam={headerProps.isScam ?? false}
46+
validationStatus={headerProps.validationStatus ?? "UNKNOWN"}
47+
/>
48+
) : null}
49+
</>
4150
);
4251
};

apps/web/src/components/SendFlow/common/OriginationOperationSignPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ const headerProps: SignHeaderProps = {
3535
network: GHOSTNET,
3636
appName: message.appMetadata.name,
3737
appIcon: message.appMetadata.icon,
38+
requestId: { sdkType: "beacon", id: message.id },
3839
};
3940
const signProps: SdkSignPageProps = {
4041
headerProps: headerProps,
4142
operation: operation,
42-
requestId: { sdkType: "beacon", id: message.id },
4343
};
4444

4545
jest.mock("@umami/core", () => ({

apps/web/src/components/SendFlow/common/SingleSignPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ describe("<SingleSignPage />", () => {
8181
network: GHOSTNET,
8282
appName: message.appMetadata.name,
8383
appIcon: message.appMetadata.icon,
84+
requestId: { sdkType: "beacon", id: message.id },
8485
};
8586
store.dispatch(networksActions.setCurrent(GHOSTNET));
8687

@@ -89,7 +90,6 @@ describe("<SingleSignPage />", () => {
8990
const signProps: SdkSignPageProps = {
9091
headerProps: headerProps,
9192
operation: operation,
92-
requestId: { sdkType: "beacon", id: message.id },
9393
};
9494

9595
jest.mocked(useGetSecretKey).mockImplementation(() => () => Promise.resolve("secretKey"));

apps/web/src/components/SendFlow/common/SingleSignPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export const SingleSignPage = (signProps: SdkSignPageProps) => {
1818
const beaconCalculatedProps = useSignWithBeacon({ ...signProps });
1919
const walletConnectCalculatedProps = useSignWithWalletConnect({ ...signProps });
2020
const calculatedProps =
21-
signProps.requestId.sdkType === "beacon" ? beaconCalculatedProps : walletConnectCalculatedProps;
21+
signProps.headerProps.requestId.sdkType === "beacon"
22+
? beaconCalculatedProps
23+
: walletConnectCalculatedProps;
2224

2325
switch (operationType) {
2426
case "tez": {

apps/web/src/components/SendFlow/common/TezSignPage.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ describe("<TezSignPage />", () => {
5555
network: GHOSTNET,
5656
appName: message.appMetadata.name,
5757
appIcon: message.appMetadata.icon,
58+
requestId: { sdkType: "beacon", id: message.id },
5859
};
5960
const signProps: SdkSignPageProps = {
6061
headerProps: headerProps,
6162
operation: operation,
62-
requestId: { sdkType: "beacon", id: message.id },
6363
};
6464

6565
store.dispatch(networksActions.setCurrent(GHOSTNET));
@@ -73,6 +73,8 @@ describe("<TezSignPage />", () => {
7373
expect(screen.getByText("Ghostnet")).toBeInTheDocument();
7474
expect(screen.queryByText("Mainnet")).not.toBeInTheDocument();
7575

76+
expect(screen.queryByText("verifyinfobox")).not.toBeInTheDocument();
77+
7678
const signButton = screen.getByRole("button", {
7779
name: "Confirm Transaction",
7880
});

apps/web/src/components/SendFlow/utils.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ export type SignHeaderProps = {
7676
network: Network;
7777
appName: string;
7878
appIcon?: string;
79+
isScam?: boolean;
80+
validationStatus?: "VALID" | "INVALID" | "UNKNOWN";
81+
requestId: SignRequestId;
7982
};
8083

8184
export type SdkSignPageProps = {
82-
requestId: SignRequestId;
8385
operation: EstimatedAccountOperations;
8486
headerProps: SignHeaderProps;
8587
};
@@ -89,6 +91,8 @@ export type SignPayloadProps = {
8991
appName: string;
9092
appIcon?: string;
9193
payload: string;
94+
isScam?: boolean;
95+
validationStatus?: "VALID" | "INVALID" | "UNKNOWN";
9296
signer: ImplicitAccount;
9397
signingType: SigningType;
9498
};

apps/web/src/components/WalletConnect/ProjectInfoCard.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { Avatar, Box, Card, Flex, Icon, Link, Text } from "@chakra-ui/react";
1+
import { Avatar, Box, Card, Link, Text } from "@chakra-ui/react";
22
import { type SignClientTypes } from "@walletconnect/types";
33

4-
import { PencilIcon } from "../../assets/icons";
5-
64
type Props = {
75
metadata: SignClientTypes.Metadata;
86
intention?: string;
@@ -38,10 +36,6 @@ export const ProjectInfoCard = ({ metadata, intention }: Props) => {
3836
{url}
3937
</Link>
4038
</Box>
41-
<Flex alignItems="center" justifyContent="center" marginTop="16px">
42-
<Icon as={PencilIcon} verticalAlign="bottom" />
43-
<Card marginLeft="8px">Cannot Verify: to be implemented</Card>
44-
</Flex>
4539
</Box>
4640
);
4741
};

0 commit comments

Comments
 (0)