Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kleros-sdk/src/dataMappings/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from "./populateTemplate";
export * from "./retrieveVariables";
export * from "./disputeDetailsTypes";

export const isUndefined = (maybeObject: any): maybeObject is undefined | null =>
typeof maybeObject === "undefined" || maybeObject === null;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mustache from "mustache";
import retrieveVariables from "./retrieveVariables";
import { ActionMapping } from "./actionTypes";
import { InvalidContextError } from "../../errors";
import { isUndefined } from ".";

export function replacePlaceholdersWithValues(
mapping: ActionMapping,
Expand Down Expand Up @@ -35,7 +36,8 @@ const validateContext = (template: string, context: Record<string, unknown>) =>
const variables = retrieveVariables(template);

variables.forEach((variable) => {
if (!context[variable]) throw new InvalidContextError(`Expected key "${variable}" to be provided in context.`);
if (isUndefined(context[variable]))
throw new InvalidContextError(`Expected key "${variable}" to be provided in context.`);
});
return true;
};
6 changes: 5 additions & 1 deletion web-devtools/src/app/(main)/dispute-template/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import ReactMarkdown from "components/ReactMarkdown";
import FetchDisputeRequestInput, { DisputeRequest } from "./FetchDisputeRequestInput";
import FetchFromIDInput from "./FetchFromIdInput";
import CustomContextInputs from "./CustomContextInputs";
import { debounceErrorToast } from "utils/debounceErrorToast";
import { isEmpty } from "utils/isEmpty";

const Container = styled.div`
height: auto;
Expand Down Expand Up @@ -193,12 +195,14 @@ const DisputeTemplateView = () => {
if (customContext) initialContext = { ...initialContext, ...customContext };

const fetchData = async () => {
if (isEmpty(disputeTemplateInput)) return;
try {
const data = dataMappingsInput ? await executeActions(JSON.parse(dataMappingsInput), initialContext) : {};
const finalDisputeDetails = populateTemplate(disputeTemplateInput, data);
setDisputeDetails(finalDisputeDetails);
} catch (e) {
} catch (e: any) {
console.error(e);
debounceErrorToast(e?.message);
setDisputeDetails(undefined);
} finally {
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isUndefined } from "utils/isUndefined";

import { graphql } from "src/graphql-generated";
import { DisputeTemplateQuery } from "src/graphql-generated/graphql";
import { isEmpty } from "utils/isEmpty";

const disputeTemplateQuery = graphql(`
query DisputeTemplate($id: ID!) {
Expand All @@ -18,7 +19,7 @@ const disputeTemplateQuery = graphql(`
`);

export const useDisputeTemplateFromId = (templateId?: string) => {
const isEnabled = !isUndefined(templateId);
const isEnabled = !isUndefined(templateId) && !isEmpty(templateId);
const { graphqlBatcher } = useGraphqlBatcher();

return useQuery<DisputeTemplateQuery>({
Expand Down
1 change: 1 addition & 0 deletions web-devtools/src/utils/isEmpty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isEmpty = (str: string): boolean => str.trim() === "";