Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions kleros-sdk/src/dataMappings/utils/lambdas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const lambdas = {
// Converts a value to hex representation
hex: function () {
return function (text: string, render: Function) {
const originalValueStr = render(text);
const num = parseInt(originalValueStr, 10);
if (!isNaN(num)) {
return "0x" + num.toString(16).toLowerCase();
}
return originalValueStr;
};
},
};
3 changes: 2 additions & 1 deletion kleros-sdk/src/dataMappings/utils/populateTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import mustache from "mustache";
import { DisputeDetails } from "./disputeDetailsTypes";
import DisputeDetailsSchema, { RefuseToArbitrateAnswer } from "./disputeDetailsSchema";
import { lambdas } from "./lambdas";

export const populateTemplate = (mustacheTemplate: string, data: any): DisputeDetails => {
const render = mustache.render(mustacheTemplate, data);
const render = mustache.render(mustacheTemplate, { ...data, ...lambdas });
const dispute = JSON.parse(render);

const validation = DisputeDetailsSchema.safeParse(dispute);
Expand Down
Loading