fix removing safe owner

This commit is contained in:
Mikhail Mikheev 2019-06-28 13:01:19 +04:00
parent a25443ddd0
commit 32ae4ff807
2 changed files with 16 additions and 4 deletions

View File

@ -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 } from '~/routes/safe/store/models/owner' import { type Owner } 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 CheckOwner from './screens/CheckOwner' import CheckOwner from './screens/CheckOwner'
import ThresholdForm from './screens/ThresholdForm' import ThresholdForm from './screens/ThresholdForm'
@ -31,6 +30,7 @@ type Props = {
threshold: number, threshold: number,
network: string, network: string,
createTransaction: Function, createTransaction: Function,
updateSafe: Function,
} }
type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner' type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner'
@ -44,6 +44,7 @@ export const sendRemoveOwner = 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()
@ -54,9 +55,9 @@ export const sendRemoveOwner = async (
.encodeABI() .encodeABI()
// const text = `Remove Owner ${ownerNameToRemove} (${ownerAddressToRemove})` // const text = `Remove Owner ${ownerNameToRemove} (${ownerAddressToRemove})`
const txHash = createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar) const txHash = await createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar)
if (txHash) { if (txHash) {
setOwners(safeAddress, owners.filter(o => o.address !== ownerAddressToRemove)) updateSafe({ address: safeAddress, owners: owners.filter(o => o.address !== ownerAddressToRemove) })
} }
} }
@ -72,6 +73,7 @@ const RemoveOwner = ({
threshold, threshold,
network, network,
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>({})
@ -109,7 +111,16 @@ const RemoveOwner = ({
const onRemoveOwner = () => { const onRemoveOwner = () => {
onClose() onClose()
try { try {
sendRemoveOwner(values, safeAddress, ownerAddress, ownerName, owners, openSnackbar, createTransaction) sendRemoveOwner(
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)

View File

@ -194,6 +194,7 @@ class ManageOwners extends React.Component<Props, State> {
network={network} network={network}
userAddress={userAddress} userAddress={userAddress}
createTransaction={createTransaction} createTransaction={createTransaction}
updateSafe={updateSafe}
/> />
<ReplaceOwnerModal <ReplaceOwnerModal
onClose={this.onHide('ReplaceOwner')} onClose={this.onHide('ReplaceOwner')}