From 0043053c101a5c9e97b2bd8f8cc848674592b6f5 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 16 Oct 2024 19:13:04 -0300 Subject: [PATCH] fix: UI feedback Two toasts when vouches are invalid New toast warns off chain vouches are not removable --- .../[pohid]/[chain]/[request]/ActionBar.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/app/[pohid]/[chain]/[request]/ActionBar.tsx b/src/app/[pohid]/[chain]/[request]/ActionBar.tsx index 0627552..9f823c2 100644 --- a/src/app/[pohid]/[chain]/[request]/ActionBar.tsx +++ b/src/app/[pohid]/[chain]/[request]/ActionBar.tsx @@ -5,7 +5,7 @@ import { useEffectOnce } from "@legendapp/state/react"; import { colorForStatus } from "config/misc"; import usePoHWrite from "contracts/hooks/usePoHWrite"; import { ContractData } from "data/contract"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { toast } from "react-toastify"; import { Address, Hash, formatEther, hexToSignature } from "viem"; import { useAccount, useChainId } from "wagmi"; @@ -94,8 +94,9 @@ export default withClientConnected(function ActionBar({ // ) // ); + const errorRef = useRef(false); + const offChainRef = useRef(false); const [action, setAction] = useState(ActionType.NONE); - const [didIVouchFor, setDidIVouchFor] = useState(false); const [isVouchOnchain, setIsVouchOnchain] = useState(false); @@ -111,7 +112,16 @@ export default withClientConnected(function ActionBar({ return false; }) || offChainVouches.some( - (voucher) => voucher.voucher.toLocaleLowerCase() === address?.toLocaleLowerCase() + (voucher) => { + if (voucher.voucher.toLocaleLowerCase() === address?.toLocaleLowerCase()) { + if (!offChainRef.current && userChainId === chain.id) { + toast.error("Off chain vouches cannot be removed"); + offChainRef.current = true; + } + return true; + } + return false; + } )) ); }; @@ -185,7 +195,8 @@ export default withClientConnected(function ActionBar({ toast.success("Request advanced to resolving state"); }, onFail() { - toast.error("No vouch is valid. Advance is not possible"); + !errorRef.current && toast.error("No vouch is valid. Advance is not possible"); + errorRef.current = true; setAction(ActionType.VOUCH); }, }),