Skip to content

Commit 14496f2

Browse files
refactor(sdk): rta-update-logic
1 parent b709cb2 commit 14496f2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

kleros-sdk/src/dataMappings/utils/populateTemplate.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ export const populateTemplate = (mustacheTemplate: string, data: any): DisputeDe
1111
throw validation.error;
1212
}
1313

14-
const templateRTAAnswer = (dispute as DisputeDetails).answers.find(
14+
return findAndUpdateRTA(dispute);
15+
};
16+
17+
// Filter out any existing answer with id 0 and add customised Refuse to Arbitrate option
18+
const findAndUpdateRTA = (dispute: DisputeDetails) => {
19+
const templateRTAIndex = (dispute as DisputeDetails).answers.findIndex(
1520
(answer) => answer.id && BigInt(answer.id) === BigInt(0)
1621
);
1722

18-
const CustomRTA: DisputeDetails["answers"][number] = {
19-
...RefuseToArbitrateAnswer,
20-
description: templateRTAAnswer?.description ?? RefuseToArbitrateAnswer.description,
21-
};
22-
23-
// Filter out any existing answer with id 0 and add customised Refuse to Arbitrate option
24-
(dispute as DisputeDetails).answers = [
25-
CustomRTA,
26-
...((dispute as DisputeDetails).answers.filter((answer) => answer.id && BigInt(answer.id) !== BigInt(0)) || []),
27-
];
23+
if (templateRTAIndex !== -1) {
24+
dispute.answers[templateRTAIndex] = {
25+
...RefuseToArbitrateAnswer,
26+
description: dispute.answers[templateRTAIndex].description ?? RefuseToArbitrateAnswer.description,
27+
};
28+
} else {
29+
dispute.answers = [RefuseToArbitrateAnswer, ...dispute.answers];
30+
}
2831

2932
return dispute;
3033
};

0 commit comments

Comments
 (0)