From 80766125377a67c9be2ecb05dcd316417c670394 Mon Sep 17 00:00:00 2001 From: juliopavila Date: Tue, 7 Jun 2022 13:09:43 -0300 Subject: [PATCH 1/2] Add the ability to remove targets --- packages/app/src/services/rolesModifierContract.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/app/src/services/rolesModifierContract.ts b/packages/app/src/services/rolesModifierContract.ts index 70b27d8c4..d42ec77f7 100644 --- a/packages/app/src/services/rolesModifierContract.ts +++ b/packages/app/src/services/rolesModifierContract.ts @@ -133,6 +133,9 @@ export const updateRole = async ( const removeMemberTxs = role.members.remove.map((member) => rolesModifierContract.populateTransaction.assignRoles(member, [role.id], [false]), ) + const removeTargetTxs = role.targets.remove.map((target) => + rolesModifierContract.populateTransaction.revokeTarget(role.id, target), + ) const txs = [...role.targets.list, ...role.targets.add].map(async (target) => { const updateEvents = role.getTargetUpdate(target.id) @@ -263,11 +266,12 @@ export const updateRole = async ( }) const targetTxs = (await Promise.all([...txs])).flat() + const targetActionsTxs = await Promise.all([...removeTargetTxs]) const memberTxs = await Promise.all([...addMemberTxs, ...removeMemberTxs]) - console.log("txs", [...memberTxs, ...targetTxs]) + console.log("txs", [...memberTxs, ...targetTxs, ...targetActionsTxs]) - return [...memberTxs, ...targetTxs] + return [...memberTxs, ...targetTxs, ...targetActionsTxs] } export const executeTxsGnosisSafe = async (txs: PopulatedTransaction[]) => { From a3f05294b76519c0342b840135f961654530f1cc Mon Sep 17 00:00:00 2001 From: juliopavila Date: Thu, 16 Jun 2022 13:54:57 -0300 Subject: [PATCH 2/2] Add new UI validations --- .../app/src/components/views/Role/RoleTableRow.tsx | 3 ++- .../components/views/Role/targets/RoleTargets.tsx | 3 ++- packages/app/src/services/rolesModifierContract.ts | 14 ++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/app/src/components/views/Role/RoleTableRow.tsx b/packages/app/src/components/views/Role/RoleTableRow.tsx index 22c82007d..861e070ae 100644 --- a/packages/app/src/components/views/Role/RoleTableRow.tsx +++ b/packages/app/src/components/views/Role/RoleTableRow.tsx @@ -51,12 +51,13 @@ const RoleTableRow = ({ role }: Props): React.ReactElement => { const { module } = useParams() const navigate = useNavigate() const handleNavigation = () => navigate(`/${module}/roles/${role.name}`) + const targets = role.targets.filter((target) => target.type !== "None") return ( {`Role #${role.name}`} {`${role.members.length} Members`} - {`${role.targets.length} Targets`} + {`${targets.length} Targets`} diff --git a/packages/app/src/components/views/Role/targets/RoleTargets.tsx b/packages/app/src/components/views/Role/targets/RoleTargets.tsx index d9422aeb2..86652d655 100644 --- a/packages/app/src/components/views/Role/targets/RoleTargets.tsx +++ b/packages/app/src/components/views/Role/targets/RoleTargets.tsx @@ -12,6 +12,7 @@ export const RoleTargets = () => { const handleOpenAddTargetModal = () => setAddTargetModalIsOpen(true) const targets = [...state.targets.list, ...state.targets.add] + const renderTarget = targets.filter((target) => target.type !== "None") const getStatus = (target: Target) => { if (state.targets.remove.includes(target.address)) return EntityStatus.REMOVE @@ -26,7 +27,7 @@ export const RoleTargets = () => { return ( <> rolesModifierContract.populateTransaction.assignRoles(member, [role.id], [false]), ) - const removeTargetTxs = role.targets.remove.map((target) => - rolesModifierContract.populateTransaction.revokeTarget(role.id, target), - ) + const removeTargetTxs = role.targets.remove.map((target) => { + console.log("[removeTargetTxs] revoke target", [role.id, target]) + return rolesModifierContract.populateTransaction.revokeTarget(role.id, target) + }) + const txs = [...role.targets.list, ...role.targets.add].map(async (target) => { const updateEvents = role.getTargetUpdate(target.id) @@ -267,11 +269,11 @@ export const updateRole = async ( const targetTxs = (await Promise.all([...txs])).flat() const targetActionsTxs = await Promise.all([...removeTargetTxs]) - const memberTxs = await Promise.all([...addMemberTxs, ...removeMemberTxs]) + const memberTxs = await Promise.all([...addMemberTxs, ...removeMemberTxs, ...targetActionsTxs]) - console.log("txs", [...memberTxs, ...targetTxs, ...targetActionsTxs]) + console.log("txs", [...memberTxs, ...targetTxs]) - return [...memberTxs, ...targetTxs, ...targetActionsTxs] + return [...memberTxs, ...targetTxs] } export const executeTxsGnosisSafe = async (txs: PopulatedTransaction[]) => {