Skip to content

Commit

Permalink
Merge pull request #157 from gnosis/app-various-bugfixes
Browse files Browse the repository at this point in the history
App various bugfixes
  • Loading branch information
auryn-macmillan committed Dec 6, 2022
2 parents 7e81426 + 8ec96b8 commit 3247c0a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 20 deletions.
5 changes: 4 additions & 1 deletion packages/app/src/components/views/Role/RoleMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ export const RoleMenu = () => {
</Box>
</Box>
) : (
[<RoleMembers />, <RoleTargets />]
<>
<RoleMembers />
<RoleTargets />
</>
)}
</Box>
{(memberChanges || targetChanges) && !txProposedInSafe && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ export const TargetConfiguration = ({ target }: TargetConfigurationProps) => {
const type = !allowTarget ? ConditionType.WILDCARDED : ConditionType.SCOPED
setTargetClearance({ targetId: target.id, option: type })
setAllowTarget((current) => !current)

const conditions = Object.keys(target.conditions).reduce(
(map, key) => ({
...map,
[key]: { ...target.conditions[key], params: [], type: ConditionType.BLOCKED },
}),
{},
)

setTargetConditions({
targetId: target.id,
conditions,
})
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import classNames from "classnames"
import React, { useMemo, useState } from "react"
import { TargetFunctionParams } from "./TargetFunctionParams"
import { ConditionType, ExecutionOption, FunctionCondition } from "../../../../typings/role"
import { getFunctionConditionType } from "../../../../utils/conditions"
import { Checkbox } from "../../../commons/input/Checkbox"
import { ZodiacPaper } from "zodiac-ui-components"
import { ExecutionTypeSelect } from "./ExecutionTypeSelect"
Expand Down Expand Up @@ -84,8 +83,15 @@ export const TargetFunction = ({ func, functionConditions, onChange }: TargetFun
}

const handleFunctionCheck = (checked: boolean) => {
const type = checked ? ConditionType.WILDCARDED : getFunctionConditionType(functionConditions.params)
onChange({ ...functionConditions, sighash: Interface.getSighash(func), type })
const type =
checked && functionConditions?.type !== ConditionType.SCOPED ? ConditionType.WILDCARDED : ConditionType.BLOCKED

return onChange({
...functionConditions,
params: [],
sighash: Interface.getSighash(func),
type,
})
}

const handleOpen = () => setOpen(!open)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react"
import React from "react"
import { makeStyles, Typography } from "@material-ui/core"
import { ParamConditionInput } from "./ParamConditionInput"
import { ConditionType, FunctionCondition, ParamCondition } from "../../../../typings/role"
Expand Down Expand Up @@ -37,8 +37,6 @@ const useStyles = makeStyles((theme) => ({
export const TargetFunctionParams = ({ func, funcConditions, disabled, onChange }: TargetFunctionParamsProps) => {
const classes = useStyles()

const [originalType] = useState(funcConditions.type)

const handleConditionChange = (index: number, value?: ParamCondition) => {
let newConditions
if (value) {
Expand All @@ -47,10 +45,11 @@ export const TargetFunctionParams = ({ func, funcConditions, disabled, onChange
} else {
newConditions = funcConditions.params.filter((param) => param.index !== index)
}
const type: ConditionType = newConditions.length ? ConditionType.SCOPED : originalType
const type: ConditionType = newConditions.length ? ConditionType.SCOPED : ConditionType.WILDCARDED
onChange({ ...funcConditions, type, params: newConditions })
}

// TODO: we need to prefill the current values (without it being added to the changes, since it's not a change)
return (
<>
{func.inputs.map((param, index) => (
Expand Down
37 changes: 28 additions & 9 deletions packages/app/src/services/rolesModifierContract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { BigNumberish, BytesLike, ethers, PopulatedTransaction } from "ethers"
import { Roles, Roles__factory } from "../contracts/type"
import SafeAppsSDK, { BaseTransaction, GatewayTransactionDetails } from "@gnosis.pm/safe-apps-sdk"
import { ConditionType, FuncParams, FunctionCondition, ParamComparison, ParamCondition, Target } from "../typings/role"
import {
ConditionType,
FuncParams,
FunctionCondition,
ParamComparison,
ParamCondition,
ParameterType,
Target,
} from "../typings/role"
import { Level, RoleContextState } from "../components/views/Role/RoleContext"
import { FunctionFragment, Interface } from "@ethersproject/abi"
import { _signer } from "../hooks/useWallet"
Expand Down Expand Up @@ -69,9 +77,9 @@ function getFunctionTransaction(
const param = funcCondition.params.find((param) => param.index === i)
if (param) {
const type = func.inputs[param.index]
const value = ethers.utils.defaultAbiCoder.encode([type], [param.value])
const value = ethers.utils.defaultAbiCoder.encode([type], param.value)
isParamScoped.push(true)
paramType.push(param.type)
paramType.push(getParameterTypeInt(param.type))
paramComp.push(getParamComparisonInt(param.condition))
compValue.push(value)
} else {
Expand Down Expand Up @@ -225,17 +233,17 @@ export const updateRole = async (
target.address,
sighash,
paramCondition.index,
paramCondition.type,
paramCondition.condition,
getParameterTypeInt(paramCondition.type),
getParamComparisonInt(paramCondition.condition),
encodedValue,
])
return rolesModifierContract.populateTransaction.scopeParameter(
role.id,
target.address,
sighash,
paramCondition.index,
paramCondition.type,
paramCondition.condition,
getParameterTypeInt(paramCondition.type),
getParamComparisonInt(paramCondition.condition),
encodedValue,
)
} else {
Expand All @@ -248,15 +256,15 @@ export const updateRole = async (
target.address,
sighash,
paramCondition.index,
paramCondition.type,
getParameterTypeInt(paramCondition.type),
encodedValues || [],
])
return rolesModifierContract.populateTransaction.scopeParameterAsOneOf(
role.id,
target.address,
sighash,
paramCondition.index,
paramCondition.type,
getParameterTypeInt(paramCondition.type),
encodedValues || [],
)
}
Expand Down Expand Up @@ -324,3 +332,14 @@ function getParamComparisonInt(paramComparison: ParamComparison): number {
return 3
}
}

function getParameterTypeInt(parameterType: ParameterType): number {
switch (parameterType) {
case ParameterType.STATIC:
return 0
case ParameterType.DYNAMIC:
return 1
case ParameterType.DYNAMIC32:
return 2
}
}
6 changes: 3 additions & 3 deletions packages/app/src/typings/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export enum ParamComparison {
}

export enum ParameterType {
STATIC,
DYNAMIC,
DYNAMIC32,
STATIC = "Static",
DYNAMIC = "Dynamic",
DYNAMIC32 = "Dynamic32",
}

export enum ParamNativeType {
Expand Down

1 comment on commit 3247c0a

@vercel
Copy link

@vercel vercel bot commented on 3247c0a Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.