From 898e83c4cd444c63bb149b49b4e8f7bc9fc56078 Mon Sep 17 00:00:00 2001 From: Piyal Basu Date: Tue, 7 Jan 2025 13:51:14 -0500 Subject: [PATCH 1/3] adding blockaid byline and feedback form --- @shared/api/types.ts | 4 +- .../components/WarningMessages/index.tsx | 506 ++++++++++++------ .../components/WarningMessages/styles.scss | 93 +++- .../manageAssets/ManageAssetRows/index.tsx | 28 +- .../sendPayment/SendAmount/index.tsx | 29 +- .../SendConfirm/TransactionDetails/index.tsx | 4 +- extension/src/popup/helpers/blockaid.ts | 78 +++ .../src/popup/views/SignTransaction/index.tsx | 44 +- .../popup/views/SignTransaction/styles.scss | 9 + .../views/__tests__/SendPayment.test.tsx | 2 + 10 files changed, 557 insertions(+), 240 deletions(-) diff --git a/@shared/api/types.ts b/@shared/api/types.ts index f560816d08..03ddbe1dd6 100644 --- a/@shared/api/types.ts +++ b/@shared/api/types.ts @@ -244,7 +244,9 @@ export interface Balance { export type BlockAidScanAssetResult = Blockaid.TokenScanResponse; export type BlockAidScanSiteResult = Blockaid.SiteScanResponse; -export type BlockAidScanTxResult = Blockaid.StellarTransactionScanResponse; +export type BlockAidScanTxResult = Blockaid.StellarTransactionScanResponse & { + request_id: string; +}; export type BlockAidBulkScanAssetResult = Blockaid.TokenBulkScanResponse; export interface AssetBalance extends Balance { diff --git a/extension/src/popup/components/WarningMessages/index.tsx b/extension/src/popup/components/WarningMessages/index.tsx index 418b4e6cdd..9056dc72ed 100644 --- a/extension/src/popup/components/WarningMessages/index.tsx +++ b/extension/src/popup/components/WarningMessages/index.tsx @@ -1,8 +1,21 @@ import React, { useState, useRef, useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; import { createPortal } from "react-dom"; -import { Button, Icon, Loader, Notification } from "@stellar/design-system"; +import { + Alert, + Button, + Card, + Icon, + Loader, + Notification, + Select, + Textarea, + Text, +} from "@stellar/design-system"; import { useTranslation, Trans } from "react-i18next"; +import { Field, FieldProps, Formik, Form } from "formik"; +import { object as YupObject, string as YupString } from "yup"; + import { POPUP_HEIGHT } from "constants/dimensions"; import { Account, @@ -61,7 +74,12 @@ import IconShieldBlockaid from "popup/assets/icon-shield-blockaid.svg"; import IconWarningBlockaid from "popup/assets/icon-warning-blockaid.svg"; import IconWarningBlockaidYellow from "popup/assets/icon-warning-blockaid-yellow.svg"; import { getVerifiedTokens } from "popup/helpers/searchAsset"; -import { isAssetSuspicious, isBlockaidWarning } from "popup/helpers/blockaid"; +import { + isAssetSuspicious, + isBlockaidWarning, + reportAssetWarning, + reportTransactionWarning, +} from "popup/helpers/blockaid"; import { CopyValue } from "../CopyValue"; import "./styles.scss"; @@ -257,15 +275,204 @@ export const BackupPhraseWarningMessage = () => { ); }; -const BlockaidByLine = () => { +interface BlockaidFeedbackFormValues { + details: string; + transactionIssue?: string; +} + +const BlockaidFeedbackFormSchema = YupObject().shape({ + details: YupString().required(), +}); + +interface BlockaidFeedbackFormProps { + address?: string; + requestId?: string; + setIsFeedbackActive: (isActive: boolean) => void; +} + +const BlockaidFeedbackForm = ({ + address, + requestId, + setIsFeedbackActive, +}: BlockaidFeedbackFormProps) => { + const { t } = useTranslation(); + const feedbackRef = useRef(null); + const networkDetails = useSelector(settingsNetworkDetailsSelector); + + const handleSubmit = async (values: BlockaidFeedbackFormValues) => { + if (requestId && values.transactionIssue) { + await reportTransactionWarning({ + details: values.details, + requestId, + event: values.transactionIssue, + }); + } else if (address) { + await reportAssetWarning({ + address, + details: values.details, + networkDetails, + }); + } + + setIsFeedbackActive(false); + }; + + const initialValues: BlockaidFeedbackFormValues = { + details: "", + transactionIssue: "should_be_benign", + }; + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if ( + feedbackRef.current && + !feedbackRef.current.contains(event.target as Node) + ) { + setIsFeedbackActive(false); + } + }; + + document.addEventListener("click", handleClickOutside, true); + return () => { + document.removeEventListener("click", handleClickOutside, true); + }; + }, [setIsFeedbackActive]); + + return ( + <> +
+ +
+
+
+ + + {({ dirty, isValid, isSubmitting }) => ( +
+
+ + {t("Leave feedback about Blockaid warnings and messages")} + + {requestId ? ( + + {({ field }: FieldProps) => ( + + )} + + ) : null} + + + {({ field }: FieldProps) => ( +