Skip to content

Commit

Permalink
Merge pull request #1759 from kleros/refactor/UI-UX-improvements
Browse files Browse the repository at this point in the history
Refactor/UI ux improvements
  • Loading branch information
alcercu authored Nov 27, 2024
2 parents d0cfb91 + dd18317 commit 71ac556
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion web/src/components/ClaimPnkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ClaimPnkButton: React.FC = () => {
const { request } = await simulatePnkFaucet(wagmiConfig, {
functionName: "request",
});
if (walletClient) {
if (walletClient && publicClient) {
wrapWithToast(async () => await walletClient.writeContract(request), publicClient)
.finally(() => {
setIsSending(false);
Expand Down
12 changes: 8 additions & 4 deletions web/src/components/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,14 @@ const Popup: React.FC<PopupProps & IPopup> = ({
break;
}

const closePopup = () => {
setIsOpen(false);
resetValue();
};

return (
<Overlay>
<Container ref={containerRef}>
<Overlay onClick={closePopup}>
<Container ref={containerRef} onClick={(e) => e.stopPropagation()}>
{popupType === PopupType.SWAP_SUCCESS && (
<SVGContainer>
<CloseIcon onClick={() => setIsOpen(false)} />
Expand All @@ -259,8 +264,7 @@ const Popup: React.FC<PopupProps & IPopup> = ({
variant="secondary"
text={popupType === PopupType.DISPUTE_CREATED ? "Check the case" : "Close"}
onClick={() => {
setIsOpen(false);
resetValue();
closePopup();
if (popupType === PopupType.DISPUTE_CREATED) {
const { disputeId } = props as IDisputeCreated;
navigate(`/cases/${disputeId}`);
Expand Down
4 changes: 1 addition & 3 deletions web/src/pages/Cases/CaseDetails/Appeal/Classic/Fund.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ const Fund: React.FC<IFund> = ({ amount, setAmount, setIsOpen }) => {
if (fundAppeal && fundAppealConfig && publicClient) {
setIsSending(true);
wrapWithToast(async () => await fundAppeal(fundAppealConfig.request), publicClient)
.then((res) => {
res.status && setIsOpen(true);
})
.then((res) => setIsOpen(res.status))
.finally(() => {
setIsSending(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const SubmitEvidenceModal: React.FC<{
}, [publicClient, wagmiConfig, walletClient, close, evidenceGroup, file, message, setIsSending, uploadFile]);

return (
<StyledModal {...{ isOpen }}>
<StyledModal {...{ isOpen }} shouldCloseOnEsc shouldCloseOnOverlayClick onRequestClose={close}>
<h1>Submit New Evidence</h1>
<StyledTextArea value={message} onChange={(e) => setMessage(e.target.value)} placeholder="Your Arguments" />
<StyledFileUploader callback={(file: File) => setFile(file)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
},
args: [address ?? "0x", BigInt(id ?? "0")],
});
const parsedStake = formatPNK(jurorBalance?.[2] || 0n, 0, true);
const parsedStake = formatPNK(jurorBalance?.[2] ?? 0n, 0, true);
const isStaking = useMemo(() => action === ActionType.stake, [action]);

useEffect(() => {
Expand Down Expand Up @@ -153,6 +153,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
isSending,
setIsSending,
setIsPopupOpen,
setErrorMsg,
}}
/>
</EnsureChainContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from "react";
import React, { useCallback, useEffect, useMemo } from "react";

import { useParams } from "react-router-dom";
import { useAccount, usePublicClient } from "wagmi";
Expand Down Expand Up @@ -36,17 +36,14 @@ const Container = styled.div`
flex-direction: column;
`;

const ErrorLabel = styled.label`
color: ${({ theme }) => theme.error};
`;

interface IActionButton {
isSending: boolean;
parsedAmount: bigint;
action: ActionType;
setIsSending: (arg0: boolean) => void;
setAmount: (arg0: string) => void;
setIsPopupOpen: (arg0: boolean) => void;
setErrorMsg: (msg: string) => void;
}

const StakeWithdrawButton: React.FC<IActionButton> = ({
Expand All @@ -55,6 +52,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
isSending,
setIsSending,
setIsPopupOpen,
setErrorMsg,
}) => {
const { id } = useParams();
const { address } = useAccount();
Expand Down Expand Up @@ -104,9 +102,11 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
},
args: [klerosCoreAddress[DEFAULT_CHAIN], BigInt(targetStake ?? 0) - BigInt(allowance ?? 0)],
});

const { writeContractAsync: increaseAllowance } = useWritePnkIncreaseAllowance();

const handleAllowance = useCallback(() => {
if (increaseAllowanceConfig) {
if (increaseAllowanceConfig && publicClient) {
setIsSending(true);
wrapWithToast(async () => await increaseAllowance(increaseAllowanceConfig.request), publicClient).finally(() => {
setIsSending(false);
Expand All @@ -116,16 +116,18 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({

const { data: setStakeConfig, error: setStakeError } = useSimulateKlerosCoreSetStake({
query: {
enabled: !isUndefined(targetStake) && !isUndefined(id) && !isAllowance && parsedAmount !== 0n,
enabled:
!isUndefined(targetStake) && !isUndefined(id) && !isAllowance && parsedAmount !== 0n && targetStake >= 0n,
},
args: [BigInt(id ?? 0), targetStake],
});
const { writeContractAsync: setStake } = useWriteKlerosCoreSetStake();

const handleStake = useCallback(() => {
if (setStakeConfig) {
if (setStakeConfig && publicClient) {
setIsSending(true);
wrapWithToast(async () => await setStake(setStakeConfig.request), publicClient)
.then((res) => res.status && setIsPopupOpen(true))
.then((res) => setIsPopupOpen(res.status))
.finally(() => {
setIsSending(false);
});
Expand All @@ -135,7 +137,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
const buttonProps = {
[ActionType.allowance]: {
text: "Allow PNK",
checkDisabled: () => !balance || targetStake! > balance,
checkDisabled: () => !balance || targetStake > balance,
onClick: handleAllowance,
},
[ActionType.stake]: {
Expand All @@ -150,6 +152,12 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
},
};

useEffect(() => {
if (setStakeError) {
setErrorMsg(setStakeError?.shortMessage ?? setStakeError.message);
}
}, [setStakeError]);

const { text, checkDisabled, onClick } = buttonProps[isAllowance ? ActionType.allowance : action];
return (
<EnsureChain>
Expand All @@ -168,7 +176,6 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
}
onClick={onClick}
/>
{setStakeError && <ErrorLabel> {setStakeError.message}</ErrorLabel>}
</Container>
</EnsureChain>
);
Expand Down
14 changes: 11 additions & 3 deletions web/src/pages/Resolver/NavigationButtons/SubmitDisputeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const SubmitDisputeButton: React.FC = () => {
}, [userBalance, disputeData]);

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

const errorMsg = useMemo(() => {
if (insufficientBalance) return "Insufficient balance";
else if (error) {
return error?.shortMessage ?? error.message;
}
return null;
}, [error, insufficientBalance]);

return (
<>
{" "}
Expand Down Expand Up @@ -91,9 +99,9 @@ const SubmitDisputeButton: React.FC = () => {
}
}}
/>
{insufficientBalance && (
{errorMsg && (
<ErrorButtonMessage>
<ClosedCircleIcon /> Insufficient balance
<ClosedCircleIcon /> {errorMsg}
</ErrorButtonMessage>
)}
</div>
Expand Down

0 comments on commit 71ac556

Please sign in to comment.