Skip to content

Commit

Permalink
Allow enabling multisig for pools (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored May 3, 2024
1 parent 468af1f commit 51388c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
39 changes: 23 additions & 16 deletions centrifuge-app/src/pages/IssuerPool/Access/PoolManagers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComputedMultisig, computeMultisig, PoolMetadata } from '@centrifuge/centrifuge-js'
import { useCentrifugeTransaction } from '@centrifuge/centrifuge-react'
import { Button } from '@centrifuge/fabric'
import { Button, Text } from '@centrifuge/fabric'
import { Form, FormikProvider, useFormik } from 'formik'
import * as React from 'react'
import { combineLatest, switchMap } from 'rxjs'
Expand All @@ -12,6 +12,7 @@ import { diffPermissions } from '../Configuration/Admins'
import { MultisigForm } from './MultisigForm'

export type PoolManagersInput = {
enabled: boolean
adminMultisig: {
signers: string[]
threshold: number
Expand All @@ -28,6 +29,7 @@ export function PoolManagers({ poolId }: { poolId: string }) {

const initialValues: PoolManagersInput = React.useMemo(
() => ({
enabled: !!access.multisig,
adminMultisig: {
signers: access.multisig?.signers || [],
threshold: access.multisig?.threshold || 1,
Expand All @@ -36,15 +38,6 @@ export function PoolManagers({ poolId }: { poolId: string }) {
[access?.multisig]
)

const storedManagerPermissions = poolPermissions
? Object.entries(poolPermissions)
.filter(([addr, p]) => p.roles.length && initialValues.adminMultisig.signers.includes(addr))
.map(([address, permissions]) => ({
address,
roles: Object.fromEntries(permissions.roles.map((role) => [role, true])),
}))
: []

const { execute, isLoading } = useCentrifugeTransaction(
'Update pool managers',
(cent) =>
Expand All @@ -71,7 +64,7 @@ export function PoolManagers({ poolId }: { poolId: string }) {
metadataTx,
...permissionTx.method.args[0],
api.tx.proxy.addProxy(newMultisig.address, 'Any', 0),
api.tx.proxy.removeProxy(access.multisig!.address, 'Any', 0),
...access.adminDelegates.map((proxy) => api.tx.proxy.removeProxy(proxy.delegatee, 'Any', 0)),
])
return cent.wrapSignAndSend(api, tx, options)
})
Expand Down Expand Up @@ -103,7 +96,7 @@ export function PoolManagers({ poolId }: { poolId: string }) {
[
newMultisig,
diffPermissions(
storedManagerPermissions,
access.managerPermissions,
values.adminMultisig.signers.map((address) => ({
address,
roles: { InvestorAdmin: true, LiquidityAdmin: true },
Expand All @@ -130,15 +123,25 @@ export function PoolManagers({ poolId }: { poolId: string }) {
adminMultisig.signers.length !== initialValues.adminMultisig.signers.length ||
!adminMultisig.signers.every((s) => initialValues.adminMultisig.signers.includes(s))

if (!access.multisig) return null

return (
<FormikProvider value={form}>
<Form>
<PageSection
title="Pool managers"
headerRight={
isEditing ? (
!form.values.enabled ? (
<Button
variant="secondary"
onClick={() => {
setIsEditing(true)
form.setFieldValue('enabled', true, false)
}}
small
key="edit"
>
Enable
</Button>
) : isEditing ? (
<ButtonGroup variant="small">
<Button variant="secondary" onClick={() => setIsEditing(false)} small>
Cancel
Expand All @@ -161,7 +164,11 @@ export function PoolManagers({ poolId }: { poolId: string }) {
)
}
>
<MultisigForm isEditing={isEditing} isLoading={isLoading} />
{!form.values.enabled ? (
<Text>Pool managers not enabled</Text>
) : (
<MultisigForm isEditing={isEditing} isLoading={isLoading} />
)}
</PageSection>
</Form>
</FormikProvider>
Expand Down
3 changes: 3 additions & 0 deletions centrifuge-app/src/utils/usePermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export function usePoolAccess(poolId: string) {
roles: Object.fromEntries(permissions.roles.map((role) => [role, true])),
}))
: []

const missingAdminPermissions = diffPermissions(
[storedAdminRoles],
[{ address: storedAdminRoles.address, roles: { InvestorAdmin: true } }]
Expand All @@ -361,6 +362,8 @@ export function usePoolAccess(poolId: string) {
[metadata?.adminMultisig]
),
adminPermissions,
adminDelegates,
managerPermissions: storedManagerPermissions,
missingPermissions: [...missingAdminPermissions, ...missingManagerPermissions],
missingAdminPermissions,
missingManagerPermissions,
Expand Down

0 comments on commit 51388c8

Please sign in to comment.