Skip to content

Commit e76fffc

Browse files
committed
refactor: policies JSON schema, cosmetic policy fixes
1 parent 6b79349 commit e76fffc

11 files changed

+205
-163
lines changed

contracts/config/policies.v2.devnet.json

+17-17
Large diffs are not rendered by default.

contracts/config/policies.v2.mainnet-neo.json

+94-94
Large diffs are not rendered by default.

contracts/config/policies.v2.testnet.json

+17-17
Large diffs are not rendered by default.

contracts/config/policies.v2/Consumo-y-Vecindad.json

-6
This file was deleted.

contracts/config/policies.v2/Curation-Court-Policy.json

-6
This file was deleted.

contracts/config/policies.v2/English-Language-Court-Policy.json

-6
This file was deleted.

contracts/config/policies.v2/General-Court-Policy.json

-5
This file was deleted.

contracts/config/policies.v2/Oracle-Court-Policy.json

-6
This file was deleted.

contracts/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"populate:courts:devnet": "hardhat populate:courts --from v2_devnet --network arbitrumSepoliaDevnet",
5656
"populate:courts:testnet": "hardhat populate:courts --from v2_testnet --network arbitrumSepolia",
5757
"populate:courts:mainnetNeo": "hardhat populate:courts --core-type neo --from v2_mainnet_neo --network arbitrum",
58+
"populate:policiesUris": "scripts/setPoliciesURIs.sh config/policies.v2.{devnet,testnet,mainnet-neo}.json",
5859
"populate:policies:devnet": "hardhat populate:policy-registry --from v2_devnet --network arbitrumSepoliaDevnet",
5960
"populate:policies:testnet": "hardhat populate:policy-registry --from v2_testnet --network arbitrumSepolia",
6061
"populate:policies:mainnetNeo": "hardhat populate:policy-registry --core-type neo --from v2_mainnet_neo --network arbitrum",

contracts/scripts/setPoliciesURIs.sh

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
# Check if at least one input file is provided
4+
if [ "$#" -lt 1 ]; then
5+
echo "Usage: $0 <input_policies_file1> [input_policies_file2 ...]"
6+
exit 1
7+
fi
8+
9+
# Process each input file
10+
for INPUT_FILE in "$@"; do
11+
# Validate file extension
12+
if [[ ! "$INPUT_FILE" =~ \.json$ ]]; then
13+
echo "Error: Input file $INPUT_FILE must have a .json extension"
14+
continue
15+
fi
16+
17+
echo "Processing $INPUT_FILE..."
18+
19+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
20+
INPUT_FILE_WITHOUT_EXTENSION="${INPUT_FILE%.json}"
21+
POLICIES_DIR="$SCRIPT_DIR/../$INPUT_FILE_WITHOUT_EXTENSION"
22+
HASHES_FILE=$(mktemp)
23+
24+
echo "Creating $POLICIES_DIR directory..."
25+
mkdir -p $POLICIES_DIR
26+
27+
# Step 1: Create individual policy files and collect their hashes
28+
echo "Creating individual policy files..."
29+
echo "{" > "$HASHES_FILE"
30+
first=true
31+
32+
jq -c '.[]' "$INPUT_FILE" | while read -r policy; do
33+
name=$(echo "$policy" | jq -r '.name' | tr ' ' '-')
34+
court=$(echo "$policy" | jq -r '.court')
35+
policy_filepath="$POLICIES_DIR/${name}-Policy.json"
36+
37+
# Remove the uri field if it exists and save to a temporary file
38+
echo "$policy" | jq 'del(.uri)' > "$policy_filepath"
39+
40+
# Get IPFS hash
41+
ipfs_hash=$(ipfs add -Q "$policy_filepath")
42+
if [ -n "$ipfs_hash" ]; then
43+
echo "Preparing $name Court ($court): ${name}-Policy.json"
44+
# Add comma for all but the first entry
45+
if [ "$first" = true ]; then
46+
first=false
47+
else
48+
echo "," >> "$HASHES_FILE"
49+
fi
50+
# Store the hash with court as key
51+
echo "\"$court\": \"$ipfs_hash\"" >> "$HASHES_FILE"
52+
else
53+
echo "Failed to get IPFS hash for ${name}-Policy.json"
54+
rm "$HASHES_FILE"
55+
continue 2
56+
fi
57+
done
58+
59+
echo "}" >> "$HASHES_FILE"
60+
61+
# Step 2: Update the input file with URIs
62+
echo "Updating URIs in $INPUT_FILE..."
63+
jq --slurpfile hashes "$HASHES_FILE" '
64+
map(. + {uri: ("/ipfs/" + ($hashes[0][.court | tostring]))})
65+
' "$INPUT_FILE" > "${INPUT_FILE}.tmp" && mv "${INPUT_FILE}.tmp" "$INPUT_FILE"
66+
67+
rm "$HASHES_FILE"
68+
echo "Done! URIs updated in $INPUT_FILE"
69+
echo "----------------------------------------"
70+
done

web/src/pages/Courts/CourtDetails/Description.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ const StyledTabs = styled(Tabs)`
6262
`;
6363

6464
interface IPolicy {
65-
description?: string;
65+
purpose?: string;
6666
requiredSkills?: string;
67-
summary?: string;
67+
rules?: string;
6868
}
6969

7070
const TABS = [
7171
{
7272
text: "Purpose",
7373
value: 0,
7474
path: "purpose",
75-
isVisible: (policy: IPolicy) => !!policy?.description,
75+
isVisible: (policy: IPolicy) => !!policy?.purpose,
7676
},
7777
{
7878
text: "Skills",
@@ -84,7 +84,7 @@ const TABS = [
8484
text: "Policy",
8585
value: 2,
8686
path: "policy",
87-
isVisible: (policy: IPolicy) => !!policy?.summary,
87+
isVisible: (policy: IPolicy) => !!policy?.rules,
8888
},
8989
];
9090

@@ -115,9 +115,9 @@ const Description: React.FC = () => {
115115
<StyledTabs currentValue={currentTab} items={filteredTabs} callback={handleTabChange} />
116116
<TextContainer>
117117
<Routes>
118-
<Route path="purpose" element={formatMarkdown(policy?.description)} />
118+
<Route path="purpose" element={formatMarkdown(policy?.purpose)} />
119119
<Route path="skills" element={formatMarkdown(policy?.requiredSkills)} />
120-
<Route path="policy" element={formatMarkdown(policy?.summary)} />
120+
<Route path="policy" element={formatMarkdown(policy?.rules)} />
121121
<Route path="*" element={<Navigate to={filteredTabs.length > 0 ? filteredTabs[0].path : ""} replace />} />
122122
</Routes>
123123
</TextContainer>

0 commit comments

Comments
 (0)