From b7d1d04a07a6a5e7df9a6480662b48a09985c1e1 Mon Sep 17 00:00:00 2001 From: kyrers Date: Sun, 24 Aug 2025 17:55:32 +0100 Subject: [PATCH 01/20] feat: add a smart contract wallet warning to layout --- src/assets/close.svg | 10 +++ .../Warnings/SmartContractWalletWarning.tsx | 63 +++++++++++++++++++ src/layout/Layout.tsx | 2 + 3 files changed, 75 insertions(+) create mode 100644 src/assets/close.svg create mode 100644 src/components/Warnings/SmartContractWalletWarning.tsx diff --git a/src/assets/close.svg b/src/assets/close.svg new file mode 100644 index 0000000..78cbdbb --- /dev/null +++ b/src/assets/close.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/components/Warnings/SmartContractWalletWarning.tsx b/src/components/Warnings/SmartContractWalletWarning.tsx new file mode 100644 index 0000000..947556a --- /dev/null +++ b/src/components/Warnings/SmartContractWalletWarning.tsx @@ -0,0 +1,63 @@ +import { AlertMessage } from "@kleros/ui-components-library"; +import { IconButton } from "components/Common/Buttons/IconButton"; +import { useLocalStorage } from "hooks/useLocalStorage"; +import { useEffect, useState } from "react"; +import styled from "styled-components"; +import { getCode } from "viem/actions"; +import { useAccount, useClient } from "wagmi"; +import CloseIcon from "assets/close.svg?react"; + +const Container = styled.div` + display: flex; +`; + +const StyledAlertMessage = styled(AlertMessage)` + flex: 1; +`; + +const StyledIconButton = styled(IconButton)` + position: absolute; + right: 0; +`; + +export default function SmartContractWalletWarning() { + const client = useClient(); + const { address } = useAccount(); + const [isSmartContractWallet, setIsSmartContractWallet] = + useState(false); + const [showWarning, setShowWarning] = useLocalStorage( + "@kleros/escrow-v1/alert/smart-contract-wallet-warning", + true + ); + + useEffect(() => { + if (address && client) { + getCode(client, { + address: address, + }).then((code) => { + setIsSmartContractWallet(!!code); + }); + } + }, [address, client]); + + if (!showWarning || !isSmartContractWallet) { + return null; + } + + return ( + + + + } + text="" + onClick={() => setShowWarning(false)} + /> + + ); +} diff --git a/src/layout/Layout.tsx b/src/layout/Layout.tsx index c695910..ae978dc 100644 --- a/src/layout/Layout.tsx +++ b/src/layout/Layout.tsx @@ -1,6 +1,7 @@ import styled from "styled-components"; import Header from "components/Header/Header"; import Footer from "components/Footer/Footer"; +import SmartContractWalletWarning from "components/Warnings/SmartContractWalletWarning"; import { Outlet } from "react-router"; const Container = styled.div` @@ -13,6 +14,7 @@ const Container = styled.div` export default function Layout() { return ( +