Skip to content

chore(web): update-templates-for-submit-list-flow #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2024
Merged
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
187 changes: 96 additions & 91 deletions web/src/utils/submitListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { IList, IListData, IListMetadata, ListField } from "context/SubmitListCo
import { prepareArbitratorExtradata } from "./prepareArbitratorExtradata";
import { Address, Log, decodeEventLog, isAddress, parseAbi, parseEther, zeroAddress } from "viem";
import { isUndefined } from ".";
import { KLEROS_ARBITRATOR, TEMPLATE_REGISTRY } from "consts/arbitration";
import { TEMPLATE_REGISTRY } from "consts/arbitration";
import { ItemDetailsFragment, Status } from "src/graphql/graphql";
import { arbitrum } from "viem/chains";
import { netlifyUri } from "src/generatedNetlifyInfo.json";
import { DEFAULT_CHAIN } from "consts/chains";

export const constructListParams = (listData: IListData, listMetadata: IListMetadata) => {
const baseTemplate = { ...listData } as IList;
Expand All @@ -25,8 +23,8 @@ export const constructListParams = (listData: IListData, listMetadata: IListMeta
baseTemplate.arbitratorExtraData = prepareArbitratorExtradata(listData.courtId ?? "1", listData.numberOfJurors) ?? "";
baseTemplate.templateRegistryParams = {
templateRegistry: TEMPLATE_REGISTRY,
registrationTemplateParameters: [constructRegistrationTemplate(listMetadata), ""],
removalTemplateParameters: [constructRemovalTemplate(listMetadata), ""],
registrationTemplateParameters: [registrationTemplate, dataMappings],
removalTemplateParameters: [removalTemplate, dataMappings],
};
return baseTemplate;
};
Expand Down Expand Up @@ -73,92 +71,6 @@ export const retrieveSubmittedListId = (eventLog: Log) =>
topics: eventLog.topics,
}).args._itemID;

const constructRegistrationTemplate = (listMetadata: IListMetadata) => {
return JSON.stringify({
title: `Add ${
listMetadata.itemName
? isVowel(listMetadata.itemName[0])
? `an ${listMetadata.itemName.toLowerCase()}`
: `a ${listMetadata.itemName.toLowerCase()}`
: "an item"
} to ${listMetadata.title}`,
description: `Someone requested to add ${
listMetadata.itemName
? isVowel(listMetadata.itemName[0])
? `an ${listMetadata.itemName.toLowerCase()}`
: `a ${listMetadata.itemName.toLowerCase()}`
: "an item"
} to ${listMetadata.title}`,
question: `Does the ${
(listMetadata.itemName && listMetadata.itemName.toLowerCase()) || "item"
} comply with the required criteria?`,
answers: [
{
title: "Yes, Add It",
description: `Select this if you think the ${
(listMetadata.itemName && listMetadata.itemName.toLowerCase()) || "item"
} complies with the required criteria and should be added.`,
},
{
title: "No, Don't Add It",
description: `Select this if you think the ${
(listMetadata.itemName && listMetadata.itemName.toLowerCase()) || "item"
} does not comply with the required criteria and should not be added.`,
},
],
category: "Curated Lists",

policyURI: listMetadata.policyURI,
frontendUrl: `${netlifyUri}/#/lists/item/{{ itemID }}@{{listAddress}}`,
//TODO : this will depend on the chain the dispute is created on?
arbitratorChainID: DEFAULT_CHAIN,
arbitratorAddress: KLEROS_ARBITRATOR,
});
};

const constructRemovalTemplate = (listMetadata: IListMetadata) => {
return JSON.stringify({
title: `Remove ${
listMetadata.itemName
? isVowel(listMetadata.itemName[0])
? `an ${listMetadata.itemName.toLowerCase()}`
: `a ${listMetadata.itemName.toLowerCase()}`
: "an item"
} from ${listMetadata.title}`,
description: `Someone requested to remove ${
listMetadata.itemName
? isVowel(listMetadata.itemName[0])
? `an ${listMetadata.itemName.toLowerCase()}`
: `a ${listMetadata.itemName.toLowerCase()}`
: "an item"
} from ${listMetadata.title}`,
question: `Does the ${
(listMetadata.itemName && listMetadata.itemName.toLowerCase()) || "item"
} comply with the required criteria?`,
answers: [
{
title: "Yes, Remove It",
description: `Select this if you think the ${
(listMetadata.itemName && listMetadata.itemName.toLowerCase()) || "item"
} does not comply with the required criteria and should not be added.`,
},
{
title: "No, Don't Remove It",
description: `Select this if you think the ${
(listMetadata.itemName && listMetadata.itemName.toLowerCase()) || "item"
} complies with the required criteria and should be added.`,
},
],
category: "Curated Lists",

policyURI: listMetadata.policyURI,
frontendUrl: `${netlifyUri}/#/lists/item/{{ itemID }}@{{listAddress}}`,
arbitratorChainID: DEFAULT_CHAIN,
arbitratorAddress: KLEROS_ARBITRATOR,
});
};
const isVowel = (x: string) => /[aeiouAEIOU]/.test(x);

export const constructItemWithMockValues = (data: IListMetadata): ItemDetailsFragment => {
const props: ListField & { value: ReturnType<typeof getMockValueForType> }[] = [];
for (const column of data.columns) {
Expand Down Expand Up @@ -200,3 +112,96 @@ const getMockValueForType = (type: string) => {
return "Ethereum";
}
};

const sharedTemplateProperties = `
"policyURI": "{{{policyURI}}}",
"frontendUrl": "https://curate-v2.kleros.builders/#/lists/item/{{itemID}}",
"arbitrableChainID": "421614",
"arbitrableAddress": "{{arbitrableAddress}}",
"arbitratorChainID": "421614",
"arbitratorAddress": "0xD08Ab99480d02bf9C092828043f611BcDFEA917b",
"metadata": {
"itemName": "{{itemName}}",
"itemDescription": "{{itemDescription}}",
"registryTitle": "{{registryTitle}}",
"registryDescription": "{{registryDescription}}"
},
"category": "Curated Lists",
"version": "1.0"`;

const registrationTemplate = `{
"$schema": "../NewDisputeTemplate.schema.json",
"title": "Add a {{itemName}} to {{registryTitle}}",
"description": "Someone requested to add an {{itemName}} to {{registryTitle}}",
"question": "Does the {{itemName}} comply with the required criteria?",
"answers": [
{
"title": "Yes, Add It",
"description": "Select this if you think that the {{itemName}} does comply with the required criteria and should be added."
},
{
"title": "No, Don't Add It",
"description": "Select this if you think that the {{itemName}} does not comply with the required criteria and should not be added."
}
], ${sharedTemplateProperties}
}
`;

const removalTemplate = `{
"$schema": "../NewDisputeTemplate.schema.json",
"title": "Remove a {{itemName}} from {{registryTitle}}",
"description": "Someone requested to remove a {{itemName}} from {{registryTitle}}",
"question": "Does the {{itemName}} comply with the required criteria?",
"answers": [
{
"title": "Yes, Remove It",
"description": "Select this if you think that the {{itemName}} does not comply with the required criteria and should be removed."
},
{
"title": "No, Don't Remove It",
"description": "Select this if you think that the {{itemName}} does comply with the required criteria and should not be removed."
}
], ${sharedTemplateProperties}
}
`;

const dataMappings = `[
{
"type": "graphql",
"endpoint": "https://gateway-arbitrum.network.thegraph.com/api/{{{graphApiKey}}}/subgraphs/id/H93eWJbDpYKAtkLmsMn7Su3ZLZwAwLN5VoyvQH4NbGAv",
"query": "query SearchRequestByDisputeID($externalDisputeID: BigInt!) { requests(where: { externalDisputeID: $externalDisputeID }) { id disputeID submissionTime resolved requester { id } challenger { id } arbitrator arbitratorExtraData deposit disputeOutcome requestType item { id itemID data status registry { id title description policyURI } } } }",
"variables": {
"externalDisputeID": "{{externalDisputeID}}"
},
"seek": [
"requests[0].item.registry.title",
"requests[0].item.registry.description",
"requests[0].item.registry.policyURI",
"requests[0].item.id",
"requests[0].item.data",
"requests[0].item.status",
"requests[0].item.registry.id"
],
"populate": [
"registryTitle",
"registryDescription",
"policyURI",
"itemID",
"itemData",
"itemStatus",
"listAddress"
]
},
{
"type": "json",
"value": "{{{itemData}}}",
"seek": [
"columns[0].label",
"columns[0].description"
],
"populate": [
"itemName",
"itemDescription"
]
}
]`;
Loading