From 2b723847794ee12a62b55b075bd863c8de4f8886 Mon Sep 17 00:00:00 2001 From: Harman-singh-waraich Date: Tue, 17 Dec 2024 13:58:21 +0530 Subject: [PATCH] fix(web): stake-input-error-display --- .../CourtDetails/StakePanel/InputDisplay.tsx | 11 ++++++----- .../StakePanel/StakeWithdrawButton.tsx | 17 ++++++++++++++--- .../StakePanel/StakeWithdrawPopup/index.tsx | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx b/web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx index 1ea779a74..d93511fec 100644 --- a/web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx +++ b/web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx @@ -1,5 +1,5 @@ import React, { useState, useMemo, useEffect } from "react"; -import styled, { css } from "styled-components"; +import styled from "styled-components"; import { useParams } from "react-router-dom"; import { useDebounce } from "react-use"; @@ -10,8 +10,6 @@ import { commify, uncommify } from "utils/commify"; import { formatPNK, roundNumberDown } from "utils/format"; import { isUndefined } from "utils/index"; -import { landscapeStyle } from "styles/landscapeStyle"; - import { NumberInputField } from "components/NumberInputField"; import StakeWithdrawButton, { ActionType } from "./StakeWithdrawButton"; @@ -64,6 +62,7 @@ interface IInputDisplay { const InputDisplay: React.FC = ({ action, amount, setAmount }) => { const [debouncedAmount, setDebouncedAmount] = useState(""); const [errorMsg, setErrorMsg] = useState(); + const [isPopupOpen, setIsPopupOpen] = useState(false); useDebounce(() => setDebouncedAmount(amount), 500, [amount]); const parsedAmount = useParsedAmount(uncommify(debouncedAmount) as `${number}`); @@ -108,8 +107,8 @@ const InputDisplay: React.FC = ({ action, amount, setAmount }) => setAmount(e); }} placeholder={isStaking ? "Amount to stake" : "Amount to withdraw"} - message={errorMsg ?? undefined} - variant={!isUndefined(errorMsg) ? "error" : "info"} + message={isPopupOpen ? undefined : (errorMsg ?? undefined)} + variant={!isUndefined(errorMsg) && !isPopupOpen ? "error" : "info"} formatter={(number: string) => (number !== "" ? commify(roundNumberDown(Number(number))) : "")} /> @@ -120,6 +119,8 @@ const InputDisplay: React.FC = ({ action, amount, setAmount }) => action, setAmount, setErrorMsg, + isPopupOpen, + setIsPopupOpen, }} /> diff --git a/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx b/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx index d8269fa4f..5d0717a72 100644 --- a/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx +++ b/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx @@ -46,13 +46,22 @@ interface IActionButton { parsedAmount: bigint; action: ActionType; setAmount: (arg0: string) => void; - setErrorMsg: (msg: string) => void; + setErrorMsg: (msg?: string) => void; + isPopupOpen: boolean; + setIsPopupOpen: (arg0: boolean) => void; } -const StakeWithdrawButton: React.FC = ({ amount, parsedAmount, action, setErrorMsg, setAmount }) => { +const StakeWithdrawButton: React.FC = ({ + amount, + parsedAmount, + action, + setErrorMsg, + setAmount, + isPopupOpen, + setIsPopupOpen, +}) => { const { id } = useParams(); const theme = useTheme(); - const [isPopupOpen, setIsPopupOpen] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const [popupStepsState, setPopupStepsState] = useState(); const controllerRef = useRef(null); @@ -234,6 +243,7 @@ const StakeWithdrawButton: React.FC = ({ amount, parsedAmount, ac amount, refetchAllowance, refetchSetStake, + setIsPopupOpen, ]); useEffect(() => { @@ -268,6 +278,7 @@ const StakeWithdrawButton: React.FC = ({ amount, parsedAmount, ac ]); const closePopup = () => { + setErrorMsg(undefined); setIsPopupOpen(false); setIsSuccess(false); setAmount(""); diff --git a/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx b/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx index e226edf30..e68ace128 100644 --- a/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx +++ b/web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx @@ -111,7 +111,7 @@ interface IStakeWithdrawPopup { } const StakeWithdrawPopup: React.FC = ({ amount, closePopup, steps, isSuccess, action }) => { - const { data: phase } = useSortitionModulePhase(); + const { data: phase, isLoading } = useSortitionModulePhase(); return ( @@ -121,7 +121,7 @@ const StakeWithdrawPopup: React.FC = ({ amount, closePopup,
{steps && } - {phase !== Phases.staking ? ( + {phase !== Phases.staking && !isLoading ? (