Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to remove targets #129

Merged
merged 2 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/app/src/components/views/Role/RoleTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<TableRow key={role.id} className={classes.tableRow} onClick={handleNavigation}>
<TableCell className={classes.tableCell}>{`Role #${role.name}`}</TableCell>
<TableCell className={classes.tableCell}>{`${role.members.length} Members`}</TableCell>
<TableCell className={classes.tableCell}>{`${role.targets.length} Targets`}</TableCell>
<TableCell className={classes.tableCell}>{`${targets.length} Targets`}</TableCell>
<TableCell className={classes.tableCell}>
<Box display="flex" justifyContent="flex-end">
<Box sx={{ mr: 1 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +27,7 @@ export const RoleTargets = () => {
return (
<>
<MenuEntity
list={targets}
list={renderTarget}
name={{ singular: "Target", plural: "Targets" }}
tutorialLink="https://gnosis.github.io/zodiac/docs/tutorial-modifier-roles/add-role#targets"
onAdd={handleOpenAddTargetModal}
Expand Down
8 changes: 7 additions & 1 deletion packages/app/src/services/rolesModifierContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ 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) => {
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)

Expand Down Expand Up @@ -263,7 +268,8 @@ export const updateRole = async (
})

const targetTxs = (await Promise.all([...txs])).flat()
const memberTxs = await Promise.all([...addMemberTxs, ...removeMemberTxs])
const targetActionsTxs = await Promise.all([...removeTargetTxs])
const memberTxs = await Promise.all([...addMemberTxs, ...removeMemberTxs, ...targetActionsTxs])

console.log("txs", [...memberTxs, ...targetTxs])

Expand Down