Skip to content

Commit 71ac556

Browse files
authored
Merge pull request #1759 from kleros/refactor/UI-UX-improvements
Refactor/UI ux improvements
2 parents d0cfb91 + dd18317 commit 71ac556

File tree

7 files changed

+42
-24
lines changed

7 files changed

+42
-24
lines changed

web/src/components/ClaimPnkButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const ClaimPnkButton: React.FC = () => {
5151
const { request } = await simulatePnkFaucet(wagmiConfig, {
5252
functionName: "request",
5353
});
54-
if (walletClient) {
54+
if (walletClient && publicClient) {
5555
wrapWithToast(async () => await walletClient.writeContract(request), publicClient)
5656
.finally(() => {
5757
setIsSending(false);

web/src/components/Popup/index.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,14 @@ const Popup: React.FC<PopupProps & IPopup> = ({
236236
break;
237237
}
238238

239+
const closePopup = () => {
240+
setIsOpen(false);
241+
resetValue();
242+
};
243+
239244
return (
240-
<Overlay>
241-
<Container ref={containerRef}>
245+
<Overlay onClick={closePopup}>
246+
<Container ref={containerRef} onClick={(e) => e.stopPropagation()}>
242247
{popupType === PopupType.SWAP_SUCCESS && (
243248
<SVGContainer>
244249
<CloseIcon onClick={() => setIsOpen(false)} />
@@ -259,8 +264,7 @@ const Popup: React.FC<PopupProps & IPopup> = ({
259264
variant="secondary"
260265
text={popupType === PopupType.DISPUTE_CREATED ? "Check the case" : "Close"}
261266
onClick={() => {
262-
setIsOpen(false);
263-
resetValue();
267+
closePopup();
264268
if (popupType === PopupType.DISPUTE_CREATED) {
265269
const { disputeId } = props as IDisputeCreated;
266270
navigate(`/cases/${disputeId}`);

web/src/pages/Cases/CaseDetails/Appeal/Classic/Fund.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ const Fund: React.FC<IFund> = ({ amount, setAmount, setIsOpen }) => {
137137
if (fundAppeal && fundAppealConfig && publicClient) {
138138
setIsSending(true);
139139
wrapWithToast(async () => await fundAppeal(fundAppealConfig.request), publicClient)
140-
.then((res) => {
141-
res.status && setIsOpen(true);
142-
})
140+
.then((res) => setIsOpen(res.status))
143141
.finally(() => {
144142
setIsSending(false);
145143
});

web/src/pages/Cases/CaseDetails/Evidence/SubmitEvidenceModal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const SubmitEvidenceModal: React.FC<{
9191
}, [publicClient, wagmiConfig, walletClient, close, evidenceGroup, file, message, setIsSending, uploadFile]);
9292

9393
return (
94-
<StyledModal {...{ isOpen }}>
94+
<StyledModal {...{ isOpen }} shouldCloseOnEsc shouldCloseOnOverlayClick onRequestClose={close}>
9595
<h1>Submit New Evidence</h1>
9696
<StyledTextArea value={message} onChange={(e) => setMessage(e.target.value)} placeholder="Your Arguments" />
9797
<StyledFileUploader callback={(file: File) => setFile(file)} />

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
104104
},
105105
args: [address ?? "0x", BigInt(id ?? "0")],
106106
});
107-
const parsedStake = formatPNK(jurorBalance?.[2] || 0n, 0, true);
107+
const parsedStake = formatPNK(jurorBalance?.[2] ?? 0n, 0, true);
108108
const isStaking = useMemo(() => action === ActionType.stake, [action]);
109109

110110
useEffect(() => {
@@ -153,6 +153,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
153153
isSending,
154154
setIsSending,
155155
setIsPopupOpen,
156+
setErrorMsg,
156157
}}
157158
/>
158159
</EnsureChainContainer>

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

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useMemo } from "react";
1+
import React, { useCallback, useEffect, useMemo } from "react";
22

33
import { useParams } from "react-router-dom";
44
import { useAccount, usePublicClient } from "wagmi";
@@ -36,17 +36,14 @@ const Container = styled.div`
3636
flex-direction: column;
3737
`;
3838

39-
const ErrorLabel = styled.label`
40-
color: ${({ theme }) => theme.error};
41-
`;
42-
4339
interface IActionButton {
4440
isSending: boolean;
4541
parsedAmount: bigint;
4642
action: ActionType;
4743
setIsSending: (arg0: boolean) => void;
4844
setAmount: (arg0: string) => void;
4945
setIsPopupOpen: (arg0: boolean) => void;
46+
setErrorMsg: (msg: string) => void;
5047
}
5148

5249
const StakeWithdrawButton: React.FC<IActionButton> = ({
@@ -55,6 +52,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
5552
isSending,
5653
setIsSending,
5754
setIsPopupOpen,
55+
setErrorMsg,
5856
}) => {
5957
const { id } = useParams();
6058
const { address } = useAccount();
@@ -104,9 +102,11 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
104102
},
105103
args: [klerosCoreAddress[DEFAULT_CHAIN], BigInt(targetStake ?? 0) - BigInt(allowance ?? 0)],
106104
});
105+
107106
const { writeContractAsync: increaseAllowance } = useWritePnkIncreaseAllowance();
107+
108108
const handleAllowance = useCallback(() => {
109-
if (increaseAllowanceConfig) {
109+
if (increaseAllowanceConfig && publicClient) {
110110
setIsSending(true);
111111
wrapWithToast(async () => await increaseAllowance(increaseAllowanceConfig.request), publicClient).finally(() => {
112112
setIsSending(false);
@@ -116,16 +116,18 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
116116

117117
const { data: setStakeConfig, error: setStakeError } = useSimulateKlerosCoreSetStake({
118118
query: {
119-
enabled: !isUndefined(targetStake) && !isUndefined(id) && !isAllowance && parsedAmount !== 0n,
119+
enabled:
120+
!isUndefined(targetStake) && !isUndefined(id) && !isAllowance && parsedAmount !== 0n && targetStake >= 0n,
120121
},
121122
args: [BigInt(id ?? 0), targetStake],
122123
});
123124
const { writeContractAsync: setStake } = useWriteKlerosCoreSetStake();
125+
124126
const handleStake = useCallback(() => {
125-
if (setStakeConfig) {
127+
if (setStakeConfig && publicClient) {
126128
setIsSending(true);
127129
wrapWithToast(async () => await setStake(setStakeConfig.request), publicClient)
128-
.then((res) => res.status && setIsPopupOpen(true))
130+
.then((res) => setIsPopupOpen(res.status))
129131
.finally(() => {
130132
setIsSending(false);
131133
});
@@ -135,7 +137,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
135137
const buttonProps = {
136138
[ActionType.allowance]: {
137139
text: "Allow PNK",
138-
checkDisabled: () => !balance || targetStake! > balance,
140+
checkDisabled: () => !balance || targetStake > balance,
139141
onClick: handleAllowance,
140142
},
141143
[ActionType.stake]: {
@@ -150,6 +152,12 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
150152
},
151153
};
152154

155+
useEffect(() => {
156+
if (setStakeError) {
157+
setErrorMsg(setStakeError?.shortMessage ?? setStakeError.message);
158+
}
159+
}, [setStakeError]);
160+
153161
const { text, checkDisabled, onClick } = buttonProps[isAllowance ? ActionType.allowance : action];
154162
return (
155163
<EnsureChain>
@@ -168,7 +176,6 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
168176
}
169177
onClick={onClick}
170178
/>
171-
{setStakeError && <ErrorLabel> {setStakeError.message}</ErrorLabel>}
172179
</Container>
173180
</EnsureChain>
174181
);

web/src/pages/Resolver/NavigationButtons/SubmitDisputeButton.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const SubmitDisputeButton: React.FC = () => {
4343
}, [userBalance, disputeData]);
4444

4545
// TODO: decide which dispute kit to use
46-
const { data: submitCaseConfig } = useSimulateDisputeResolverCreateDisputeForTemplate({
46+
const { data: submitCaseConfig, error } = useSimulateDisputeResolverCreateDisputeForTemplate({
4747
query: {
4848
enabled: !insufficientBalance && isTemplateValid(disputeTemplate),
4949
},
@@ -63,6 +63,14 @@ const SubmitDisputeButton: React.FC = () => {
6363
[isSubmittingCase, insufficientBalance, isBalanceLoading, disputeTemplate]
6464
);
6565

66+
const errorMsg = useMemo(() => {
67+
if (insufficientBalance) return "Insufficient balance";
68+
else if (error) {
69+
return error?.shortMessage ?? error.message;
70+
}
71+
return null;
72+
}, [error, insufficientBalance]);
73+
6674
return (
6775
<>
6876
{" "}
@@ -91,9 +99,9 @@ const SubmitDisputeButton: React.FC = () => {
9199
}
92100
}}
93101
/>
94-
{insufficientBalance && (
102+
{errorMsg && (
95103
<ErrorButtonMessage>
96-
<ClosedCircleIcon /> Insufficient balance
104+
<ClosedCircleIcon /> {errorMsg}
97105
</ErrorButtonMessage>
98106
)}
99107
</div>

0 commit comments

Comments
 (0)