Skip to content

Commit 20ac82c

Browse files
authored
Merge pull request #1797 from kleros/fix/stake-input
fix(web): stake-input-error-display
2 parents 4849f30 + 24a9c9c commit 20ac82c

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ interface IInputDisplay {
6969
const InputDisplay: React.FC<IInputDisplay> = ({ action, amount, setAmount }) => {
7070
const [debouncedAmount, setDebouncedAmount] = useState("");
7171
const [errorMsg, setErrorMsg] = useState<string | undefined>();
72+
const [isPopupOpen, setIsPopupOpen] = useState(false);
7273
useDebounce(() => setDebouncedAmount(amount), 500, [amount]);
7374
const parsedAmount = useParsedAmount(uncommify(debouncedAmount) as `${number}`);
7475

@@ -113,8 +114,8 @@ const InputDisplay: React.FC<IInputDisplay> = ({ action, amount, setAmount }) =>
113114
setAmount(e);
114115
}}
115116
placeholder={isStaking ? "Amount to stake" : "Amount to withdraw"}
116-
message={errorMsg ?? undefined}
117-
variant={!isUndefined(errorMsg) ? "error" : "info"}
117+
message={isPopupOpen ? undefined : (errorMsg ?? undefined)}
118+
variant={!isUndefined(errorMsg) && !isPopupOpen ? "error" : "info"}
118119
formatter={(number: string) => (number !== "" ? commify(roundNumberDown(Number(number))) : "")}
119120
/>
120121
<EnsureChainContainer>
@@ -125,6 +126,8 @@ const InputDisplay: React.FC<IInputDisplay> = ({ action, amount, setAmount }) =>
125126
action,
126127
setAmount,
127128
setErrorMsg,
129+
isPopupOpen,
130+
setIsPopupOpen,
128131
}}
129132
/>
130133
</EnsureChainContainer>

web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ interface IActionButton {
4646
parsedAmount: bigint;
4747
action: ActionType;
4848
setAmount: (arg0: string) => void;
49-
setErrorMsg: (msg: string) => void;
49+
setErrorMsg: (msg?: string) => void;
50+
isPopupOpen: boolean;
51+
setIsPopupOpen: (arg0: boolean) => void;
5052
}
5153

52-
const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, action, setErrorMsg, setAmount }) => {
54+
const StakeWithdrawButton: React.FC<IActionButton> = ({
55+
amount,
56+
parsedAmount,
57+
action,
58+
setErrorMsg,
59+
setAmount,
60+
isPopupOpen,
61+
setIsPopupOpen,
62+
}) => {
5363
const { id } = useParams();
5464
const theme = useTheme();
55-
const [isPopupOpen, setIsPopupOpen] = useState(false);
5665
const [isSuccess, setIsSuccess] = useState(false);
5766
const [popupStepsState, setPopupStepsState] = useState<Steps>();
5867
const controllerRef = useRef<AbortController | null>(null);
@@ -234,6 +243,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
234243
amount,
235244
refetchAllowance,
236245
refetchSetStake,
246+
setIsPopupOpen,
237247
]);
238248

239249
useEffect(() => {
@@ -268,6 +278,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
268278
]);
269279

270280
const closePopup = () => {
281+
setErrorMsg(undefined);
271282
setIsPopupOpen(false);
272283
setIsSuccess(false);
273284
setAmount("");

web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ interface IStakeWithdrawPopup {
111111
}
112112

113113
const StakeWithdrawPopup: React.FC<IStakeWithdrawPopup> = ({ amount, closePopup, steps, isSuccess, action }) => {
114-
const { data: phase } = useSortitionModulePhase();
114+
const { data: phase, isLoading } = useSortitionModulePhase();
115115

116116
return (
117117
<Overlay onClick={closePopup}>
@@ -121,7 +121,7 @@ const StakeWithdrawPopup: React.FC<IStakeWithdrawPopup> = ({ amount, closePopup,
121121
<Header {...{ amount, isSuccess, action }} />
122122
<Divider />
123123
{steps && <CustomTimeline items={steps} />}
124-
{phase !== Phases.staking ? (
124+
{phase !== Phases.staking && !isLoading ? (
125125
<InfoContainer>
126126
<Divider />
127127
<StyledInfoCard

0 commit comments

Comments
 (0)