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,93 +57,86 @@ const OwnerForm = ({
</Row> </Row>
<Hairline /> <Hairline />
<GnoForm onSubmit={handleSubmit}> <GnoForm onSubmit={handleSubmit}>
{(...args) => { {() => (
const formState = args[2] <React.Fragment>
<Block className={classes.formContainer}>
return ( <Row>
<React.Fragment> <Paragraph>
<Block className={classes.formContainer}> Review the owner you want to replace from the active Safe. Then specify the new owner you want to
<Row noMargin> replace it with:
<Paragraph> </Paragraph>
Review the owner you want to replace from the active Safe. Then specify the new owner you want to replace it with:
</Paragraph>
</Row>
<Row noMargin>
<Paragraph>
Current owner
</Paragraph>
</Row>
<Row className={classes.owner}>
<Col xs={1} align="center">
<Identicon address={ownerAddress} diameter={32} />
</Col>
<Col xs={7}>
<Block className={classNames(classes.name, classes.userName)}>
<Paragraph size="lg" noMargin weight="bolder">
{ownerName}
</Paragraph>
<Block align="center" className={classes.user}>
<Paragraph size="md" color="disabled" noMargin>
{ownerAddress}
</Paragraph>
<Link className={classes.open} to={getEtherScanLink(ownerAddress, network)} target="_blank">
<OpenInNew style={openIconStyle} />
</Link>
</Block>
</Block>
</Col>
</Row>
<Row noMargin>
<Paragraph>
New owner
</Paragraph>
</Row>
<Row margin="md">
<Col xs={8}>
<Field
name="ownerName"
component={TextField}
type="text"
validate={composeValidators(required, minMaxLength(1,50))}
placeholder="Owner name*"
text="Owner name*"
className={classes.addressInput}
/>
</Col>
</Row>
<Row margin="md">
<Col xs={8}>
<Field
name="ownerAddress"
component={TextField}
type="text"
validate={composeValidators(required, mustBeEthereumAddress)}
placeholder="Owner address*"
text="Owner address*"
className={classes.addressInput}
/>
</Col>
</Row>
</Block>
<Hairline />
<Row align="center" className={classes.buttonRow}>
<Button className={classes.button} minWidth={140} onClick={onClose}>
Cancel
</Button>
<Button
type="submit"
className={classes.button}
variant="contained"
minWidth={140}
color="primary"
data-testid="review-tx-btn"
>
Next
</Button>
</Row> </Row>
</React.Fragment> <Row>
) <Paragraph>Current owner</Paragraph>
}} </Row>
<Row className={classes.owner}>
<Col xs={1} align="center">
<Identicon address={ownerAddress} diameter={32} />
</Col>
<Col xs={7}>
<Block className={classNames(classes.name, classes.userName)}>
<Paragraph size="lg" noMargin weight="bolder">
{ownerName}
</Paragraph>
<Block align="center" className={classes.user}>
<Paragraph size="md" color="disabled" noMargin>
{ownerAddress}
</Paragraph>
<Link className={classes.open} to={getEtherScanLink(ownerAddress, network)} target="_blank">
<OpenInNew style={openIconStyle} />
</Link>
</Block>
</Block>
</Col>
</Row>
<Row>
<Paragraph>New owner</Paragraph>
</Row>
<Row margin="md">
<Col xs={8}>
<Field
name="ownerName"
component={TextField}
type="text"
validate={composeValidators(required, minMaxLength(1, 50))}
placeholder="Owner name*"
text="Owner name*"
className={classes.addressInput}
/>
</Col>
</Row>
<Row margin="md">
<Col xs={8}>
<Field
name="ownerAddress"
component={TextField}
type="text"
validate={composeValidators(required, mustBeEthereumAddress)}
placeholder="Owner address*"
text="Owner address*"
className={classes.addressInput}
/>
</Col>
</Row>
</Block>
<Hairline />
<Row align="center" className={classes.buttonRow}>
<Button className={classes.button} minWidth={140} onClick={onClose}>
Cancel
</Button>
<Button
type="submit"
className={classes.button}
variant="contained"
minWidth={140}
color="primary"
data-testid="review-tx-btn"
>
Next
</Button>
</Row>
</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',