Skip to content

Commit

Permalink
Merge pull request #292 from gnosisguild/sdk-process-annotations
Browse files Browse the repository at this point in the history
sdk: add processAnnotations function
  • Loading branch information
jfschwarz authored Sep 24, 2024
2 parents 3f20a48 + ca6a7e7 commit 39682e9
Show file tree
Hide file tree
Showing 21 changed files with 887 additions and 1,006 deletions.
2 changes: 1 addition & 1 deletion packages/app/app/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
// bsc,
polygon,
gnosis,
} from "@wagmi/core/chains" // cannot import from wagmi/chains because that one declares "use client;"
} from "wagmi/chains"

export const CHAINS = {
[mainnet.id]: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DiffFlag, Preset } from "../types"
import { Preset } from "zodiac-roles-sdk/annotations"
import { DiffFlag } from "../types"
import { diffPermissions, diffPresets } from "./diff"

describe("diff", () => {
Expand Down Expand Up @@ -193,9 +194,9 @@ const PRESET: Preset = {
title: "DeFi Kit",
version: "1.0.0",
},
pathKey: "/permissions/gor/cowswap/swap",
pathParams: {},
queryParams: {
path: "/permissions/gor/cowswap/swap",
params: {},
query: {
sell: [
"0x6B175474E89094C44Da98b954EedeAC495271d0F",
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
Expand Down
11 changes: 6 additions & 5 deletions packages/app/components/permissions/PermissionsDiff/diff.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PermissionCoerced, targetId, permissionId } from "zodiac-roles-sdk"
import { DiffFlag, PermissionsDiff, Preset } from "../types"
import { Preset } from "zodiac-roles-sdk/annotations"
import { DiffFlag, PermissionsDiff } from "../types"
import { comparePermissionIds } from "../groupPermissions"

export const diffPermissions = (
Expand Down Expand Up @@ -161,15 +162,15 @@ export const diffPresets = (

// 2) new path key in right: Hidden / Added
rightSorted.forEach((r) => {
if (!leftSorted.some((l) => l.pathKey === r.pathKey)) {
if (!leftSorted.some((l) => l.path === r.path)) {
diffLeft.set(r, { flag: DiffFlag.Hidden })
diffRight.set(r, { flag: DiffFlag.Added })
}
})

// 3) missing path key in right: Removed / Hidden
leftSorted.forEach((l) => {
if (!rightSorted.some((r) => r.pathKey === l.pathKey)) {
if (!rightSorted.some((r) => r.path === l.path)) {
diffLeft.set(l, { flag: DiffFlag.Removed })
diffRight.set(l, { flag: DiffFlag.Hidden })
}
Expand All @@ -182,7 +183,7 @@ export const diffPresets = (
if (diffLeft.has(l)) return

const r = rightSorted.find(
(r) => !diffRight.has(r) && r.pathKey === l.pathKey && r.uri !== l.uri
(r) => !diffRight.has(r) && r.path === l.path && r.uri !== l.uri
)

if (r) {
Expand Down Expand Up @@ -213,7 +214,7 @@ export const diffPresets = (
if (diffRight.has(r)) return

const l = leftSorted.find(
(l) => !diffLeft.has(l) && l.pathKey === r.pathKey && l.uri !== r.uri
(l) => !diffLeft.has(l) && l.path === r.path && l.uri !== r.uri
)

if (l) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cn from "classnames"
import { ChainId } from "@/app/chains"
import Flex from "@/ui/Flex"
import Box from "@/ui/Box"
import { processAnnotations } from "../annotations"
import { processAnnotations } from "../processAnnotations"
import { diffPermissions, diffPresets } from "./diff"
import { PresetsAndPermissionsView } from "../PermissionsList"
import classes from "./style.module.css"
Expand Down
5 changes: 3 additions & 2 deletions packages/app/components/permissions/PermissionsList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {
Target,
reconstructPermissions,
} from "zodiac-roles-sdk"
import { Preset } from "zodiac-roles-sdk/annotations"
import { ChainId } from "@/app/chains"
import Flex from "@/ui/Flex"
import PresetItem from "../PresetItem"
import TargetItem from "../TargetItem"
import { processAnnotations } from "../annotations"
import { processAnnotations } from "../processAnnotations"
import { groupPermissions } from "../groupPermissions"
import { PermissionsDiff, Preset, PresetsDiff } from "../types"
import { PermissionsDiff, PresetsDiff } from "../types"

interface Props {
targets: Target[]
Expand Down
14 changes: 6 additions & 8 deletions packages/app/components/permissions/PresetItem/Parameter.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { Preset } from "zodiac-roles-sdk/annotations"
import Flex from "@/ui/Flex"
import { OpenAPIParameter, Preset } from "../types"
import classes from "./style.module.css"
import LabeledData from "@/ui/LabeledData"

const Parameter: React.FC<{
parameter: OpenAPIParameter
queryParams: Preset["queryParams"]
pathParams: Preset["pathParams"]
}> = ({ parameter, queryParams, pathParams }) => {
parameter: Preset["operation"]["parameters"][number]
params: Preset["params"]
query: Preset["query"]
}> = ({ parameter, params, query }) => {
// we only support path and query parameters
if (parameter.in !== "path" && parameter.in !== "query") return null
const value = (
parameter.in === "path"
? pathParams[parameter.name]
: queryParams[parameter.name]
parameter.in === "path" ? params[parameter.name] : query[parameter.name]
) as string | number | string[] | number[] | undefined

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Preset } from "zodiac-roles-sdk/annotations"
import Flex from "@/ui/Flex"
import { Preset } from "../types"
import classes from "./style.module.css"
import Anchor from "@/ui/Anchor"

Expand Down
7 changes: 4 additions & 3 deletions packages/app/components/permissions/PresetItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Preset, PresetsDiff } from "../types"
import { Preset } from "zodiac-roles-sdk/annotations"
import { PresetsDiff } from "../types"
import IndividualPermissions from "./IndividualPermissions"
import PresetInfo from "./PresetInfo"
import Parameter from "./Parameter"
Expand Down Expand Up @@ -46,8 +47,8 @@ const PresetItemMain: React.FC<Props> = ({ preset, chainId, diff }) => {
<Parameter
key={parameter.name}
parameter={parameter}
pathParams={preset.pathParams}
queryParams={preset.queryParams}
params={preset.params}
query={preset.query}
/>
))}
</Flex>
Expand Down
Loading

0 comments on commit 39682e9

Please sign in to comment.