Skip to content

Commit

Permalink
refactor: policies JSON schema, cosmetic policy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuidl committed Jan 24, 2025
1 parent 6b79349 commit e76fffc
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 163 deletions.
34 changes: 17 additions & 17 deletions contracts/config/policies.v2.devnet.json

Large diffs are not rendered by default.

188 changes: 94 additions & 94 deletions contracts/config/policies.v2.mainnet-neo.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions contracts/config/policies.v2.testnet.json

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions contracts/config/policies.v2/Consumo-y-Vecindad.json

This file was deleted.

6 changes: 0 additions & 6 deletions contracts/config/policies.v2/Curation-Court-Policy.json

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions contracts/config/policies.v2/General-Court-Policy.json

This file was deleted.

6 changes: 0 additions & 6 deletions contracts/config/policies.v2/Oracle-Court-Policy.json

This file was deleted.

1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"populate:courts:devnet": "hardhat populate:courts --from v2_devnet --network arbitrumSepoliaDevnet",
"populate:courts:testnet": "hardhat populate:courts --from v2_testnet --network arbitrumSepolia",
"populate:courts:mainnetNeo": "hardhat populate:courts --core-type neo --from v2_mainnet_neo --network arbitrum",
"populate:policiesUris": "scripts/setPoliciesURIs.sh config/policies.v2.{devnet,testnet,mainnet-neo}.json",
"populate:policies:devnet": "hardhat populate:policy-registry --from v2_devnet --network arbitrumSepoliaDevnet",
"populate:policies:testnet": "hardhat populate:policy-registry --from v2_testnet --network arbitrumSepolia",
"populate:policies:mainnetNeo": "hardhat populate:policy-registry --core-type neo --from v2_mainnet_neo --network arbitrum",
Expand Down
70 changes: 70 additions & 0 deletions contracts/scripts/setPoliciesURIs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# Check if at least one input file is provided
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <input_policies_file1> [input_policies_file2 ...]"
exit 1
fi

# Process each input file
for INPUT_FILE in "$@"; do
# Validate file extension
if [[ ! "$INPUT_FILE" =~ \.json$ ]]; then
echo "Error: Input file $INPUT_FILE must have a .json extension"
continue
fi

echo "Processing $INPUT_FILE..."

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
INPUT_FILE_WITHOUT_EXTENSION="${INPUT_FILE%.json}"
POLICIES_DIR="$SCRIPT_DIR/../$INPUT_FILE_WITHOUT_EXTENSION"
HASHES_FILE=$(mktemp)

echo "Creating $POLICIES_DIR directory..."
mkdir -p $POLICIES_DIR

# Step 1: Create individual policy files and collect their hashes
echo "Creating individual policy files..."
echo "{" > "$HASHES_FILE"
first=true

jq -c '.[]' "$INPUT_FILE" | while read -r policy; do
name=$(echo "$policy" | jq -r '.name' | tr ' ' '-')
court=$(echo "$policy" | jq -r '.court')
policy_filepath="$POLICIES_DIR/${name}-Policy.json"

# Remove the uri field if it exists and save to a temporary file
echo "$policy" | jq 'del(.uri)' > "$policy_filepath"

# Get IPFS hash
ipfs_hash=$(ipfs add -Q "$policy_filepath")
if [ -n "$ipfs_hash" ]; then
echo "Preparing $name Court ($court): ${name}-Policy.json"
# Add comma for all but the first entry
if [ "$first" = true ]; then
first=false
else
echo "," >> "$HASHES_FILE"
fi
# Store the hash with court as key
echo "\"$court\": \"$ipfs_hash\"" >> "$HASHES_FILE"
else
echo "Failed to get IPFS hash for ${name}-Policy.json"
rm "$HASHES_FILE"
continue 2
fi
done

echo "}" >> "$HASHES_FILE"

# Step 2: Update the input file with URIs
echo "Updating URIs in $INPUT_FILE..."
jq --slurpfile hashes "$HASHES_FILE" '
map(. + {uri: ("/ipfs/" + ($hashes[0][.court | tostring]))})
' "$INPUT_FILE" > "${INPUT_FILE}.tmp" && mv "${INPUT_FILE}.tmp" "$INPUT_FILE"

rm "$HASHES_FILE"
echo "Done! URIs updated in $INPUT_FILE"
echo "----------------------------------------"
done
12 changes: 6 additions & 6 deletions web/src/pages/Courts/CourtDetails/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ const StyledTabs = styled(Tabs)`
`;

interface IPolicy {
description?: string;
purpose?: string;
requiredSkills?: string;
summary?: string;
rules?: string;
}

const TABS = [
{
text: "Purpose",
value: 0,
path: "purpose",
isVisible: (policy: IPolicy) => !!policy?.description,
isVisible: (policy: IPolicy) => !!policy?.purpose,
},
{
text: "Skills",
Expand All @@ -84,7 +84,7 @@ const TABS = [
text: "Policy",
value: 2,
path: "policy",
isVisible: (policy: IPolicy) => !!policy?.summary,
isVisible: (policy: IPolicy) => !!policy?.rules,
},
];

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

0 comments on commit e76fffc

Please sign in to comment.