fix removing safe owner

This commit is contained in:
Mikhail Mikheev 2019-06-27 15:15:00 +04:00
parent 8e8cd13674
commit 60ba580308
4 changed files with 90 additions and 110 deletions

View File

@ -1,16 +1,15 @@
// @flow // @flow
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { List } from 'immutable' import { List } from 'immutable'
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 Safe } from '~/routes/safe/store/models/safe'
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 { 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'
import ReviewRemoveOwner from './screens/Review' import ReviewRemoveOwner from './screens/Review'
import { withStyles } from '@material-ui/core/styles'
const styles = () => ({ const styles = () => ({
biggerModalWindow: { biggerModalWindow: {
@ -31,7 +30,6 @@ type Props = {
owners: List<Owner>, owners: List<Owner>,
threshold: number, threshold: number,
network: string, network: string,
userAddress: string,
createTransaction: Function, createTransaction: Function,
} }
type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner' type ActiveScreen = 'checkOwner' | 'selectThreshold' | 'reviewRemoveOwner'
@ -51,8 +49,10 @@ export const sendRemoveOwner = async (
const storedOwners = await gnosisSafe.getOwners() const storedOwners = await gnosisSafe.getOwners()
const index = storedOwners.findIndex(ownerAddress => ownerAddress === ownerAddressToRemove) const index = storedOwners.findIndex(ownerAddress => ownerAddress === ownerAddressToRemove)
const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1] const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1]
const txData = gnosisSafe.contract.methods.removeOwner(prevAddress, ownerAddressToRemove, values.threshold).encodeABI() const txData = gnosisSafe.contract.methods
const text = `Remove Owner ${ownerNameToRemove} (${ownerAddressToRemove})` .removeOwner(prevAddress, ownerAddressToRemove, values.threshold)
.encodeABI()
// const text = `Remove Owner ${ownerNameToRemove} (${ownerAddressToRemove})`
const txHash = createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar) const txHash = createTransaction(safeAddress, safeAddress, 0, txData, openSnackbar)
if (txHash) { if (txHash) {
@ -71,7 +71,6 @@ const RemoveOwner = ({
owners, owners,
threshold, threshold,
network, network,
userAddress,
createTransaction, createTransaction,
}: Props) => { }: Props) => {
const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner') const [activeScreen, setActiveScreen] = useState<ActiveScreen>('checkOwner')
@ -93,7 +92,7 @@ const RemoveOwner = ({
} }
} }
const ownerSubmitted = (newValues: Object) => { const ownerSubmitted = () => {
setActiveScreen('selectThreshold') setActiveScreen('selectThreshold')
} }

View File

@ -4,16 +4,15 @@ import classNames from 'classnames/bind'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import Close from '@material-ui/icons/Close' import Close from '@material-ui/icons/Close'
import IconButton from '@material-ui/core/IconButton' import IconButton from '@material-ui/core/IconButton'
import OpenInNew from '@material-ui/icons/OpenInNew'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Row from '~/components/layout/Row' import Row from '~/components/layout/Row'
import GnoForm from '~/components/forms/GnoForm'
import Col from '~/components/layout/Col' import Col from '~/components/layout/Col'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import Block from '~/components/layout/Block' import Block from '~/components/layout/Block'
import Hairline from '~/components/layout/Hairline' import Hairline from '~/components/layout/Hairline'
import Link from '~/components/layout/Link' import Link from '~/components/layout/Link'
import Identicon from '~/components/Identicon' import Identicon from '~/components/Identicon'
import OpenInNew from '@material-ui/icons/OpenInNew'
import { getEtherScanLink } from '~/logic/wallets/getWeb3' import { getEtherScanLink } from '~/logic/wallets/getWeb3'
import { styles } from './style' import { styles } from './style'
import { secondary } from '~/theme/variables' import { secondary } from '~/theme/variables'
@ -94,7 +93,7 @@ const CheckOwner = ({
variant="contained" variant="contained"
minWidth={140} minWidth={140}
color="primary" color="primary"
data-testid="review-tx-btn" onClick={handleSubmit}
> >
Next Next
</Button> </Button>

View File

@ -4,6 +4,7 @@ import classNames from 'classnames/bind'
import { withStyles } from '@material-ui/core/styles' import { withStyles } from '@material-ui/core/styles'
import Close from '@material-ui/icons/Close' import Close from '@material-ui/icons/Close'
import IconButton from '@material-ui/core/IconButton' import IconButton from '@material-ui/core/IconButton'
import OpenInNew from '@material-ui/icons/OpenInNew'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Row from '~/components/layout/Row' import Row from '~/components/layout/Row'
import GnoForm from '~/components/forms/GnoForm' import GnoForm from '~/components/forms/GnoForm'
@ -15,13 +16,9 @@ import Field from '~/components/forms/Field'
import TextField from '~/components/forms/TextField' import TextField from '~/components/forms/TextField'
import Identicon from '~/components/Identicon' import Identicon from '~/components/Identicon'
import Link from '~/components/layout/Link' import Link from '~/components/layout/Link'
import OpenInNew from '@material-ui/icons/OpenInNew'
import { getEtherScanLink } from '~/logic/wallets/getWeb3' import { getEtherScanLink } from '~/logic/wallets/getWeb3'
import { import {
composeValidators, composeValidators, required, mustBeEthereumAddress, minMaxLength,
required,
mustBeEthereumAddress,
minMaxLength,
} from '~/components/forms/validator' } from '~/components/forms/validator'
import { styles } from './style' import { styles } from './style'
import { secondary } from '~/theme/variables' import { secondary } from '~/theme/variables'
@ -41,12 +38,7 @@ type Props = {
} }
const OwnerForm = ({ const OwnerForm = ({
classes, classes, onClose, ownerAddress, ownerName, network, onSubmit,
onClose,
ownerAddress,
ownerName,
network,
onSubmit,
}: Props) => { }: Props) => {
const handleSubmit = (values) => { const handleSubmit = (values) => {
onSubmit(values) onSubmit(values)
@ -65,21 +57,17 @@ const OwnerForm = ({
</Row> </Row>
<Hairline /> <Hairline />
<GnoForm onSubmit={handleSubmit}> <GnoForm onSubmit={handleSubmit}>
{(...args) => { {() => (
const formState = args[2]
return (
<React.Fragment> <React.Fragment>
<Block className={classes.formContainer}> <Block className={classes.formContainer}>
<Row noMargin> <Row>
<Paragraph> <Paragraph>
Review the owner you want to replace from the active Safe. Then specify the new owner you want to replace it with: Review the owner you want to replace from the active Safe. Then specify the new owner you want to
replace it with:
</Paragraph> </Paragraph>
</Row> </Row>
<Row noMargin> <Row>
<Paragraph> <Paragraph>Current owner</Paragraph>
Current owner
</Paragraph>
</Row> </Row>
<Row className={classes.owner}> <Row className={classes.owner}>
<Col xs={1} align="center"> <Col xs={1} align="center">
@ -101,10 +89,8 @@ const OwnerForm = ({
</Block> </Block>
</Col> </Col>
</Row> </Row>
<Row noMargin> <Row>
<Paragraph> <Paragraph>New owner</Paragraph>
New owner
</Paragraph>
</Row> </Row>
<Row margin="md"> <Row margin="md">
<Col xs={8}> <Col xs={8}>
@ -112,7 +98,7 @@ const OwnerForm = ({
name="ownerName" name="ownerName"
component={TextField} component={TextField}
type="text" type="text"
validate={composeValidators(required, minMaxLength(1,50))} validate={composeValidators(required, minMaxLength(1, 50))}
placeholder="Owner name*" placeholder="Owner name*"
text="Owner name*" text="Owner name*"
className={classes.addressInput} className={classes.addressInput}
@ -150,8 +136,7 @@ const OwnerForm = ({
</Button> </Button>
</Row> </Row>
</React.Fragment> </React.Fragment>
) )}
}}
</GnoForm> </GnoForm>
</React.Fragment> </React.Fragment>
) )

View File

@ -16,9 +16,6 @@ export const styles = () => ({
'&:hover $actions': { '&:hover $actions': {
visibility: 'initial', visibility: 'initial',
}, },
'&:focus $actions': {
visibility: 'initial',
},
}, },
actions: { actions: {
justifyContent: 'flex-end', justifyContent: 'flex-end',