Skip to content

Commit 7b2ccd3

Browse files
committed
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
2 parents d2cb260 + a932aa6 commit 7b2ccd3

File tree

7 files changed

+24
-14
lines changed

7 files changed

+24
-14
lines changed

web/src/components/CasesDisplay/Search.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useDebounce } from "react-use";
77

88
import { Searchbar, DropdownCascader } from "@kleros/ui-components-library";
99

10-
import { isUndefined } from "utils/index";
10+
import { isEmpty, isUndefined } from "utils/index";
1111
import { decodeURIFilter, encodeURIFilter, useRootPath } from "utils/uri";
1212

1313
import { rootCourtToItems, useCourtTree } from "queries/useCourtTree";
@@ -58,7 +58,7 @@ const Search: React.FC = () => {
5858
const navigate = useNavigate();
5959
useDebounce(
6060
() => {
61-
const newFilters = search === "" ? { ...filterObject } : { ...filterObject, id: search };
61+
const newFilters = isEmpty(search) ? { ...filterObject } : { ...filterObject, id: search };
6262
const encodedFilter = encodeURIFilter(newFilters);
6363
navigate(`${location}/${page}/${order}/${encodedFilter}`);
6464
},

web/src/context/NewDisputeContext.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Address } from "viem";
55
import { DEFAULT_CHAIN } from "consts/chains";
66
import { klerosCoreAddress } from "hooks/contracts/generated";
77
import { useLocalStorage } from "hooks/useLocalStorage";
8-
import { isUndefined } from "utils/index";
8+
import { isEmpty, isUndefined } from "utils/index";
99

1010
export type Answer = {
1111
id: string;
@@ -133,7 +133,7 @@ const constructDisputeTemplate = (disputeData: IDisputeData) => {
133133
for (const answer of baseTemplate.answers) {
134134
answer.id = "0x" + BigInt(answer.id).toString(16);
135135
}
136-
if (!isUndefined(baseTemplate.policyURI) && baseTemplate.policyURI === "") delete baseTemplate.policyURI;
136+
if (!isUndefined(baseTemplate.policyURI) && isEmpty(baseTemplate.policyURI)) delete baseTemplate.policyURI;
137137

138138
baseTemplate.arbitratorAddress = klerosCoreAddress[DEFAULT_CHAIN];
139139
baseTemplate.arbitratorChainID = DEFAULT_CHAIN.toString();

web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/FormContact.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Dispatch, SetStateAction, useMemo, useEffect } from "react";
22
import styled from "styled-components";
33

44
import { Field } from "@kleros/ui-components-library";
5+
import { isEmpty } from "src/utils";
56

67
const StyledLabel = styled.label`
78
display: flex;
@@ -47,7 +48,7 @@ const FormContact: React.FC<IForm> = ({
4748
};
4849

4950
const fieldVariant = useMemo(() => {
50-
if (contactInput === "" || !isEditing) {
51+
if (!isEditing || isEmpty(contactInput)) {
5152
return undefined;
5253
}
5354
return contactIsValid ? "success" : "error";

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { wrapWithToast, OPTIONS as toastOptions } from "utils/wrapWithToast";
1414

1515
import EnsureAuth from "components/EnsureAuth";
1616
import { EnsureChain } from "components/EnsureChain";
17-
import { isUndefined } from "src/utils";
17+
import { isEmpty } from "src/utils";
1818

1919
const StyledModal = styled(Modal)`
2020
position: absolute;
@@ -65,7 +65,7 @@ const SubmitEvidenceModal: React.FC<{
6565
const [file, setFile] = useState<File>();
6666
const { uploadFile } = useAtlasProvider();
6767

68-
const isDisabled = useMemo(() => isSending || message.trim() === "" || isUndefined(message), [isSending, message]);
68+
const isDisabled = useMemo(() => isSending || isEmpty(message), [isSending, message]);
6969

7070
const submitEvidence = useCallback(async () => {
7171
try {
@@ -83,8 +83,10 @@ const SubmitEvidenceModal: React.FC<{
8383
close();
8484
})
8585
.finally(() => setIsSending(false));
86-
} catch {
86+
} catch (error) {
8787
setIsSending(false);
88+
toast.error("Failed to submit evidence.", toastOptions);
89+
console.error("Error in submitEvidence:", error);
8890
}
8991
}, [publicClient, wagmiConfig, walletClient, close, evidenceGroup, file, message, setIsSending, uploadFile]);
9092

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useLocation, useNavigate } from "react-router-dom";
55
import { Button } from "@kleros/ui-components-library";
66

77
import { useNewDisputeContext } from "context/NewDisputeContext";
8+
import { isEmpty } from "src/utils";
89

910
interface INextButton {
1011
nextRoute: string;
@@ -21,17 +22,17 @@ const NextButton: React.FC<INextButton> = ({ nextRoute }) => {
2122
disputeData.answers.every((answer) => answer.title !== "" && answer.description !== "");
2223

2324
//check if any filled address or ens is invalid
24-
const areFilledAddressesValid = disputeData?.aliasesArray?.every((alias) =>
25-
alias.address === "" && alias.name === "" ? true : alias.isValid
26-
);
27-
25+
const areAliasesValidOrEmpty = disputeData?.aliasesArray?.every((alias) => {
26+
const isAliasEmpty = isEmpty(alias.address) && isEmpty(alias.name);
27+
return isAliasEmpty || alias.isValid;
28+
});
2829
const isButtonDisabled =
2930
(location.pathname.includes("/resolver/title") && !disputeData.title) ||
3031
(location.pathname.includes("/resolver/description") && !disputeData.description) ||
3132
(location.pathname.includes("/resolver/court") && !disputeData.courtId) ||
3233
(location.pathname.includes("/resolver/jurors") && !disputeData.arbitrationCost) ||
3334
(location.pathname.includes("/resolver/voting-options") && !areVotingOptionsFilled) ||
34-
(location.pathname.includes("/resolver/notable-persons") && !areFilledAddressesValid) ||
35+
(location.pathname.includes("/resolver/notable-persons") && !areAliasesValidOrEmpty) ||
3536
(location.pathname.includes("/resolver/policy") && (isPolicyUploading || !disputeData.policyURI));
3637

3738
return <Button disabled={isButtonDisabled} onClick={() => navigate(nextRoute)} text="Next" />;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import styled from "styled-components";
44
import { useNavigate } from "react-router-dom";
55

66
import { Button } from "@kleros/ui-components-library";
7+
import { isEmpty } from "src/utils";
78

89
const StyledButton = styled(Button)<{ prevRoute: string }>`
9-
display: ${({ prevRoute }) => (prevRoute === "" ? "none" : "flex")};
10+
display: ${({ prevRoute }) => (isEmpty(prevRoute) ? "none" : "flex")};
1011
`;
1112

1213
interface IReturnButton {

web/src/utils/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
export const isUndefined = (maybeObject: any): maybeObject is undefined | null =>
22
typeof maybeObject === "undefined" || maybeObject === null;
3+
4+
/**
5+
* Checks if a string is empty or contains only whitespace.
6+
*/
7+
export const isEmpty = (str: string): boolean => str.trim() === "";

0 commit comments

Comments
 (0)