Skip to content

Commit

Permalink
Merge branch 'feat/privCred-presentation' of github.com:zksecurity/pa…
Browse files Browse the repository at this point in the history
…llad into feat/privCred-presentation
  • Loading branch information
mitschabaude committed Dec 20, 2024
2 parents 7317269 + ebba555 commit c3c8c76
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/features/src/web-connector/utils/render-payload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type LogicNode = {
right?: LogicNode
key?: string
inner?: LogicNode
data?: Record<string, LogicNode>
data?: Record<string, any>
credentialKey?: string
input?: LogicNode
options?: LogicNode[] | LogicNode
Expand Down Expand Up @@ -179,11 +179,22 @@ const formatLogicNode = (node: LogicNode, level = 0): string => {
.map(([key, value]) => `${key}: ${formatLogicNode(value, level)}`)
.join(`\n${indent}`)
}
case "constant":
if (!node.data) {
throw Error("CONSTANT node must have 'data'")
case "constant": {
if (!node.data || typeof node.data !== "object") {
throw Error("CONSTANT node must have 'data' object")
}
if (node.data._type === "Undefined") {
return "undefined"
}
return JSON.stringify(node.data.value)
}
case "ifThenElse":
if (!node.condition || !node.thenNode || !node.elseNode) {
throw Error(
"IF_THEN_ELSE node must have 'condition', 'thenNode', and 'elseNode'",
)
}
return `${node.data}`
return `${indent}If this condition is true:\n${indent}- ${formatLogicNode(node.condition, level + 1)}\n${indent}Then:\n${indent}- ${formatLogicNode(node.thenNode, level + 1)}\n${indent}Otherwise:\n${indent}- ${formatLogicNode(node.elseNode, level + 1)}`

default:
throw Error(`Unknown node type: ${node.type}`)
Expand Down

0 comments on commit c3c8c76

Please sign in to comment.