fixing disappearing safe owner when replacing WIP
This commit is contained in:
parent
7c389ca49a
commit
2136c39ef2
|
@ -5,7 +5,6 @@ import { withStyles } from '@material-ui/core/styles'
|
||||||
import { SharedSnackbarConsumer } from '~/components/SharedSnackBar'
|
import { SharedSnackbarConsumer } from '~/components/SharedSnackBar'
|
||||||
import Modal from '~/components/Modal'
|
import Modal from '~/components/Modal'
|
||||||
import { type Owner, makeOwner } from '~/routes/safe/store/models/owner'
|
import { type Owner, makeOwner } from '~/routes/safe/store/models/owner'
|
||||||
import { setOwners } from '~/logic/safe/utils'
|
|
||||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
||||||
import OwnerForm from './screens/OwnerForm'
|
import OwnerForm from './screens/OwnerForm'
|
||||||
import ReviewReplaceOwner from './screens/Review'
|
import ReviewReplaceOwner from './screens/Review'
|
||||||
|
@ -30,6 +29,7 @@ type Props = {
|
||||||
network: string,
|
network: string,
|
||||||
threshold: string,
|
threshold: string,
|
||||||
createTransaction: Function,
|
createTransaction: Function,
|
||||||
|
updateSafe: Function
|
||||||
}
|
}
|
||||||
type ActiveScreen = 'checkOwner' | 'reviewReplaceOwner'
|
type ActiveScreen = 'checkOwner' | 'reviewReplaceOwner'
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ export const sendReplaceOwner = async (
|
||||||
owners: List<Owner>,
|
owners: List<Owner>,
|
||||||
openSnackbar: Function,
|
openSnackbar: Function,
|
||||||
createTransaction: Function,
|
createTransaction: Function,
|
||||||
|
updateSafe: Function,
|
||||||
) => {
|
) => {
|
||||||
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
|
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
|
||||||
const storedOwners = await gnosisSafe.getOwners()
|
const storedOwners = await gnosisSafe.getOwners()
|
||||||
|
@ -53,14 +54,13 @@ export const sendReplaceOwner = async (
|
||||||
.encodeABI()
|
.encodeABI()
|
||||||
// const text = `Replace Owner ${ownerNameToRemove} (${ownerAddressToRemove}) with ${values.ownerName} (${values.ownerAddress})`
|
// const text = `Replace Owner ${ownerNameToRemove} (${ownerAddressToRemove}) with ${values.ownerName} (${values.ownerAddress})`
|
||||||
|
|
||||||
const ownersWithoutOldOwner = owners.filter(o => o.address !== ownerAddressToRemove)
|
const ownerToRemoveIndex = owners.findIndex(o => o.address === ownerAddressToRemove)
|
||||||
const ownersWithNewOwner = ownersWithoutOldOwner.push(
|
const newOwner = makeOwner({ name: values.ownerName, address: values.ownerAddress })
|
||||||
makeOwner({ name: values.ownerName, address: values.ownerAddress }),
|
|
||||||
)
|
|
||||||
|
|
||||||
const txHash = createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar)
|
const txHash = createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar)
|
||||||
|
|
||||||
if (txHash) {
|
if (txHash) {
|
||||||
setOwners(safeAddress, ownersWithNewOwner)
|
updateSafe({ address: safeAddress, owners: owners.set(ownerToRemoveIndex, newOwner) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ const ReplaceOwner = ({
|
||||||
network,
|
network,
|
||||||
threshold,
|
threshold,
|
||||||
createTransaction,
|
createTransaction,
|
||||||
|
updateSafe,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner')
|
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner')
|
||||||
const [values, setValues] = useState<Object>({})
|
const [values, setValues] = useState<Object>({})
|
||||||
|
@ -104,7 +105,16 @@ const ReplaceOwner = ({
|
||||||
const onReplaceOwner = () => {
|
const onReplaceOwner = () => {
|
||||||
onClose()
|
onClose()
|
||||||
try {
|
try {
|
||||||
sendReplaceOwner(values, safeAddress, ownerAddress, ownerName, owners, openSnackbar, createTransaction)
|
sendReplaceOwner(
|
||||||
|
values,
|
||||||
|
safeAddress,
|
||||||
|
ownerAddress,
|
||||||
|
ownerName,
|
||||||
|
owners,
|
||||||
|
openSnackbar,
|
||||||
|
createTransaction,
|
||||||
|
updateSafe,
|
||||||
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.log('Error while removing an owner ' + error)
|
console.log('Error while removing an owner ' + error)
|
||||||
|
|
|
@ -207,6 +207,7 @@ class ManageOwners extends React.Component<Props, State> {
|
||||||
threshold={threshold}
|
threshold={threshold}
|
||||||
userAddress={userAddress}
|
userAddress={userAddress}
|
||||||
createTransaction={createTransaction}
|
createTransaction={createTransaction}
|
||||||
|
updateSafe={updateSafe}
|
||||||
/>
|
/>
|
||||||
<EditOwnerModal
|
<EditOwnerModal
|
||||||
onClose={this.onHide('EditOwner')}
|
onClose={this.onHide('EditOwner')}
|
||||||
|
|
Loading…
Reference in New Issue