From 2136c39ef21f2630c931a9548a8691f2f7ffe1fa Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Thu, 27 Jun 2019 17:41:37 +0400 Subject: [PATCH] fixing disappearing safe owner when replacing WIP --- .../ManageOwners/ReplaceOwnerModal/index.jsx | 24 +++++++++++++------ .../Settings/ManageOwners/index.jsx | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx index c824b649..1681e90b 100644 --- a/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/ReplaceOwnerModal/index.jsx @@ -5,7 +5,6 @@ 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 { setOwners } from '~/logic/safe/utils' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import OwnerForm from './screens/OwnerForm' import ReviewReplaceOwner from './screens/Review' @@ -30,6 +29,7 @@ type Props = { network: string, threshold: string, createTransaction: Function, + updateSafe: Function } type ActiveScreen = 'checkOwner' | 'reviewReplaceOwner' @@ -43,6 +43,7 @@ export const sendReplaceOwner = async ( owners: List, openSnackbar: Function, createTransaction: Function, + updateSafe: Function, ) => { const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const storedOwners = await gnosisSafe.getOwners() @@ -53,14 +54,13 @@ export const sendReplaceOwner = async ( .encodeABI() // const text = `Replace Owner ${ownerNameToRemove} (${ownerAddressToRemove}) with ${values.ownerName} (${values.ownerAddress})` - const ownersWithoutOldOwner = owners.filter(o => o.address !== ownerAddressToRemove) - const ownersWithNewOwner = ownersWithoutOldOwner.push( - makeOwner({ name: values.ownerName, address: values.ownerAddress }), - ) + const ownerToRemoveIndex = owners.findIndex(o => o.address === ownerAddressToRemove) + const newOwner = makeOwner({ name: values.ownerName, address: values.ownerAddress }) const txHash = createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar) + if (txHash) { - setOwners(safeAddress, ownersWithNewOwner) + updateSafe({ address: safeAddress, owners: owners.set(ownerToRemoveIndex, newOwner) }) } } @@ -76,6 +76,7 @@ const ReplaceOwner = ({ network, threshold, createTransaction, + updateSafe, }: Props) => { const [activeScreen, setActiveScreen] = useState('checkOwner') const [values, setValues] = useState({}) @@ -104,7 +105,16 @@ const ReplaceOwner = ({ const onReplaceOwner = () => { onClose() try { - sendReplaceOwner(values, safeAddress, ownerAddress, ownerName, owners, openSnackbar, createTransaction) + sendReplaceOwner( + values, + safeAddress, + ownerAddress, + ownerName, + owners, + openSnackbar, + createTransaction, + updateSafe, + ) } catch (error) { // eslint-disable-next-line console.log('Error while removing an owner ' + error) diff --git a/src/routes/safe/components/Settings/ManageOwners/index.jsx b/src/routes/safe/components/Settings/ManageOwners/index.jsx index 0e0ae9ac..1ad3d2f5 100644 --- a/src/routes/safe/components/Settings/ManageOwners/index.jsx +++ b/src/routes/safe/components/Settings/ManageOwners/index.jsx @@ -207,6 +207,7 @@ class ManageOwners extends React.Component { threshold={threshold} userAddress={userAddress} createTransaction={createTransaction} + updateSafe={updateSafe} />