Fix edit, remove and replace owners
This commit is contained in:
parent
89dbe7895a
commit
482da14439
|
@ -6,6 +6,7 @@ import { SharedSnackbarConsumer } from '~/components/SharedSnackBar'
|
|||
import Modal from '~/components/Modal'
|
||||
import { type Owner, makeOwner } from '~/routes/safe/store/models/owner'
|
||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
||||
import { getOwners } from '~/logic/safe/utils'
|
||||
import OwnerForm from './screens/OwnerForm'
|
||||
import ThresholdForm from './screens/ThresholdForm'
|
||||
import ReviewAddOwner from './screens/Review'
|
||||
|
@ -35,7 +36,7 @@ type ActiveScreen = 'selectOwner' | 'selectThreshold' | 'reviewAddOwner'
|
|||
export const sendAddOwner = async (
|
||||
values: Object,
|
||||
safeAddress: string,
|
||||
owners: List<Owner>,
|
||||
ownersOld: List<Owner>,
|
||||
openSnackbar: Function,
|
||||
createTransaction: Function,
|
||||
updateSafe: Function,
|
||||
|
@ -45,10 +46,21 @@ export const sendAddOwner = async (
|
|||
|
||||
const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar)
|
||||
|
||||
const owners = []
|
||||
const storedOwners = await getOwners(safeAddress)
|
||||
storedOwners.forEach((value, key) => owners.push(makeOwner({
|
||||
address: key,
|
||||
name: (values.ownerAddress.toLowerCase() === key.toLowerCase()) ? values.ownerName : value,
|
||||
})))
|
||||
const newOwnerIndex = List(owners).findIndex(o => o.address.toLowerCase() === values.ownerAddress.toLowerCase())
|
||||
if (newOwnerIndex < 0) {
|
||||
owners.push(makeOwner({ address: values.ownerAddress, name: values.ownerName }))
|
||||
}
|
||||
|
||||
if (txHash) {
|
||||
updateSafe({
|
||||
address: safeAddress,
|
||||
owners: owners.push(makeOwner({ name: values.ownerName, address: values.ownerAddress })),
|
||||
owners: List(owners),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ import { List } from 'immutable'
|
|||
import { withStyles } from '@material-ui/core/styles'
|
||||
import { SharedSnackbarConsumer } from '~/components/SharedSnackBar'
|
||||
import Modal from '~/components/Modal'
|
||||
import { type Owner } from '~/routes/safe/store/models/owner'
|
||||
import { type Owner, makeOwner } from '~/routes/safe/store/models/owner'
|
||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
||||
import { getOwners } from '~/logic/safe/utils'
|
||||
import CheckOwner from './screens/CheckOwner'
|
||||
import ThresholdForm from './screens/ThresholdForm'
|
||||
import ReviewRemoveOwner from './screens/Review'
|
||||
|
@ -41,23 +42,31 @@ export const sendRemoveOwner = async (
|
|||
safeAddress: string,
|
||||
ownerAddressToRemove: string,
|
||||
ownerNameToRemove: string,
|
||||
owners: List<Owner>,
|
||||
ownersOld: List<Owner>,
|
||||
openSnackbar: Function,
|
||||
createTransaction: Function,
|
||||
updateSafe: Function,
|
||||
) => {
|
||||
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
|
||||
const storedOwners = await gnosisSafe.getOwners()
|
||||
const index = storedOwners.findIndex(ownerAddress => ownerAddress === ownerAddressToRemove)
|
||||
const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1]
|
||||
const safeOwners = await gnosisSafe.getOwners()
|
||||
const index = safeOwners.findIndex(ownerAddress => ownerAddress.toLowerCase() === ownerAddressToRemove.toLowerCase())
|
||||
const prevAddress = index === 0 ? SENTINEL_ADDRESS : safeOwners[index - 1]
|
||||
const txData = gnosisSafe.contract.methods
|
||||
.removeOwner(prevAddress, ownerAddressToRemove, values.threshold)
|
||||
.encodeABI()
|
||||
// const text = `Remove Owner ${ownerNameToRemove} (${ownerAddressToRemove})`
|
||||
|
||||
const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar)
|
||||
|
||||
let owners = []
|
||||
const storedOwners = await getOwners(safeAddress)
|
||||
storedOwners.forEach((value, key) => owners.push(makeOwner({ address: key, name: value })))
|
||||
owners = List(owners).filter(o => o.address.toLowerCase() !== ownerAddressToRemove.toLowerCase())
|
||||
|
||||
if (txHash) {
|
||||
updateSafe({ address: safeAddress, owners: owners.filter(o => o.address !== ownerAddressToRemove) })
|
||||
updateSafe({
|
||||
address: safeAddress,
|
||||
owners,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { withStyles } from '@material-ui/core/styles'
|
|||
import { SharedSnackbarConsumer } from '~/components/SharedSnackBar'
|
||||
import Modal from '~/components/Modal'
|
||||
import { type Owner, makeOwner } from '~/routes/safe/store/models/owner'
|
||||
import { getOwners } from '~/logic/safe/utils'
|
||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
||||
import OwnerForm from './screens/OwnerForm'
|
||||
import ReviewReplaceOwner from './screens/Review'
|
||||
|
@ -40,27 +41,38 @@ export const sendReplaceOwner = async (
|
|||
safeAddress: string,
|
||||
ownerAddressToRemove: string,
|
||||
ownerNameToRemove: string,
|
||||
owners: List<Owner>,
|
||||
ownersOld: List<Owner>,
|
||||
openSnackbar: Function,
|
||||
createTransaction: Function,
|
||||
updateSafe: Function,
|
||||
) => {
|
||||
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
|
||||
const storedOwners = await gnosisSafe.getOwners()
|
||||
const index = storedOwners.findIndex(ownerAddress => ownerAddress === ownerAddressToRemove)
|
||||
const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1]
|
||||
const safeOwners = await gnosisSafe.getOwners()
|
||||
const index = safeOwners.findIndex(ownerAddress => ownerAddress.toLowerCase() === ownerAddressToRemove.toLowerCase())
|
||||
const prevAddress = index === 0 ? SENTINEL_ADDRESS : safeOwners[index - 1]
|
||||
const txData = gnosisSafe.contract.methods
|
||||
.swapOwner(prevAddress, ownerAddressToRemove, values.ownerAddress)
|
||||
.encodeABI()
|
||||
// const text = `Replace Owner ${ownerNameToRemove} (${ownerAddressToRemove}) with ${values.ownerName} (${values.ownerAddress})`
|
||||
|
||||
const ownerToRemoveIndex = owners.findIndex(o => o.address === ownerAddressToRemove)
|
||||
const newOwner = makeOwner({ name: values.ownerName, address: values.ownerAddress })
|
||||
|
||||
const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar)
|
||||
|
||||
let owners = []
|
||||
const storedOwners = await getOwners(safeAddress)
|
||||
storedOwners.forEach((value, key) => owners.push(makeOwner({
|
||||
address: key,
|
||||
name: (values.ownerAddress.toLowerCase() === key.toLowerCase()) ? values.ownerName : value,
|
||||
})))
|
||||
const newOwnerIndex = List(owners).findIndex(o => o.address.toLowerCase() === values.ownerAddress.toLowerCase())
|
||||
if (newOwnerIndex < 0) {
|
||||
owners.push(makeOwner({ address: values.ownerAddress, name: values.ownerName }))
|
||||
}
|
||||
owners = List(owners).filter(o => o.address.toLowerCase() !== ownerAddressToRemove.toLowerCase())
|
||||
|
||||
if (txHash) {
|
||||
updateSafe({ address: safeAddress, owners: owners.set(ownerToRemoveIndex, newOwner) })
|
||||
updateSafe({
|
||||
address: safeAddress,
|
||||
owners,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,6 +147,7 @@ const ReplaceOwner = ({
|
|||
onClose={onClose}
|
||||
ownerAddress={ownerAddress}
|
||||
ownerName={ownerName}
|
||||
owners={owners}
|
||||
network={network}
|
||||
onSubmit={ownerSubmitted}
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue