Remove old implementation of add owner to a Safe
This commit is contained in:
parent
7d40428f5b
commit
ca729f1707
|
@ -1,70 +0,0 @@
|
||||||
// @flow
|
|
||||||
import * as React from 'react'
|
|
||||||
import Field from '~/components/forms/Field'
|
|
||||||
import OpenPaper from '~/components/Stepper/OpenPaper'
|
|
||||||
import TextField from '~/components/forms/TextField'
|
|
||||||
import Checkbox from '~/components/forms/Checkbox'
|
|
||||||
import {
|
|
||||||
composeValidators, required, mustBeEthereumAddress, uniqueAddress,
|
|
||||||
} from '~/components/forms/validator'
|
|
||||||
import Block from '~/components/layout/Block'
|
|
||||||
import Heading from '~/components/layout/Heading'
|
|
||||||
|
|
||||||
export const CONFIRMATIONS_ERROR = 'Number of confirmations can not be higher than the number of owners'
|
|
||||||
|
|
||||||
export const NAME_PARAM = 'name'
|
|
||||||
export const OWNER_ADDRESS_PARAM = 'ownerAddress'
|
|
||||||
export const INCREASE_PARAM = 'increase'
|
|
||||||
|
|
||||||
export const safeFieldsValidation = (values: Object) => {
|
|
||||||
const errors = {}
|
|
||||||
|
|
||||||
if (Number.parseInt(values.owners, 10) < Number.parseInt(values.confirmations, 10)) {
|
|
||||||
errors.confirmations = CONFIRMATIONS_ERROR
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors
|
|
||||||
}
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
numOwners: number,
|
|
||||||
threshold: number,
|
|
||||||
addresses: string[],
|
|
||||||
}
|
|
||||||
|
|
||||||
const AddOwnerForm = ({ addresses, numOwners, threshold }: Props) => (controls: React.Node) => (
|
|
||||||
<OpenPaper controls={controls}>
|
|
||||||
<Heading tag="h2" margin="lg">
|
|
||||||
Add Owner
|
|
||||||
</Heading>
|
|
||||||
<Heading tag="h4" margin="lg">
|
|
||||||
{`Actual number of owners: ${numOwners}, with threshold: ${threshold}`}
|
|
||||||
</Heading>
|
|
||||||
<Block margin="md">
|
|
||||||
<Field
|
|
||||||
name={NAME_PARAM}
|
|
||||||
component={TextField}
|
|
||||||
type="text"
|
|
||||||
validate={required}
|
|
||||||
placeholder="Owner Name*"
|
|
||||||
text="Owner Name*"
|
|
||||||
/>
|
|
||||||
</Block>
|
|
||||||
<Block margin="md">
|
|
||||||
<Field
|
|
||||||
name={OWNER_ADDRESS_PARAM}
|
|
||||||
component={TextField}
|
|
||||||
type="text"
|
|
||||||
validate={composeValidators(required, mustBeEthereumAddress, uniqueAddress(addresses))}
|
|
||||||
placeholder="Owner address*"
|
|
||||||
text="Owner address*"
|
|
||||||
/>
|
|
||||||
</Block>
|
|
||||||
<Block margin="md">
|
|
||||||
<Field name={INCREASE_PARAM} component={Checkbox} type="checkbox" />
|
|
||||||
<Block>Increase threshold?</Block>
|
|
||||||
</Block>
|
|
||||||
</OpenPaper>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default AddOwnerForm
|
|
|
@ -1,48 +0,0 @@
|
||||||
// @flow
|
|
||||||
import * as React from 'react'
|
|
||||||
import CircularProgress from '@material-ui/core/CircularProgress'
|
|
||||||
import OpenPaper from '~/components/Stepper/OpenPaper'
|
|
||||||
import Block from '~/components/layout/Block'
|
|
||||||
import Bold from '~/components/layout/Bold'
|
|
||||||
import Heading from '~/components/layout/Heading'
|
|
||||||
import Paragraph from '~/components/layout/Paragraph'
|
|
||||||
import { NAME_PARAM, OWNER_ADDRESS_PARAM, INCREASE_PARAM } from '~/routes/safe/components/AddOwner/AddOwnerForm'
|
|
||||||
|
|
||||||
type FormProps = {
|
|
||||||
values: Object,
|
|
||||||
submitting: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
const spinnerStyle = {
|
|
||||||
minHeight: '50px',
|
|
||||||
}
|
|
||||||
|
|
||||||
const Review = () => (controls: React.Node, { values, submitting }: FormProps) => {
|
|
||||||
const text = values[INCREASE_PARAM]
|
|
||||||
? 'This operation will increase the threshold of the safe'
|
|
||||||
: 'This operation will not modify the threshold of the safe'
|
|
||||||
|
|
||||||
return (
|
|
||||||
<OpenPaper controls={controls}>
|
|
||||||
<Heading tag="h2">Review the Add Owner operation</Heading>
|
|
||||||
<Paragraph align="left">
|
|
||||||
<Bold>Owner Name: </Bold>
|
|
||||||
{' '}
|
|
||||||
{values[NAME_PARAM]}
|
|
||||||
</Paragraph>
|
|
||||||
<Paragraph align="left">
|
|
||||||
<Bold>Owner Address: </Bold>
|
|
||||||
{' '}
|
|
||||||
{values[OWNER_ADDRESS_PARAM]}
|
|
||||||
</Paragraph>
|
|
||||||
<Paragraph align="left">
|
|
||||||
<Bold>{text}</Bold>
|
|
||||||
</Paragraph>
|
|
||||||
<Block style={spinnerStyle}>
|
|
||||||
{ submitting && <CircularProgress size={50} /> }
|
|
||||||
</Block>
|
|
||||||
</OpenPaper>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Review
|
|
|
@ -1,12 +0,0 @@
|
||||||
// @flow
|
|
||||||
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
|
|
||||||
|
|
||||||
type FetchTransactions = typeof fetchTransactions
|
|
||||||
|
|
||||||
export type Actions = {
|
|
||||||
fetchTransactions: FetchTransactions,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
fetchTransactions,
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
// @flow
|
|
||||||
import * as React from 'react'
|
|
||||||
import { List } from 'immutable'
|
|
||||||
import Stepper from '~/components/Stepper'
|
|
||||||
import { connect } from 'react-redux'
|
|
||||||
import { type Safe } from '~/routes/safe/store/models/safe'
|
|
||||||
import { type Owner, makeOwner } from '~/routes/safe/store/models/owner'
|
|
||||||
import { setOwners } from '~/logic/safe/utils'
|
|
||||||
import { createTransaction } from '~/logic/safe/safeFrontendOperations'
|
|
||||||
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
|
|
||||||
import AddOwnerForm, { NAME_PARAM, OWNER_ADDRESS_PARAM, INCREASE_PARAM } from './AddOwnerForm'
|
|
||||||
import Review from './Review'
|
|
||||||
import selector, { type SelectorProps } from './selector'
|
|
||||||
import actions, { type Actions } from './actions'
|
|
||||||
|
|
||||||
const getSteps = () => ['Fill Owner Form', 'Review Add order operation']
|
|
||||||
|
|
||||||
type Props = SelectorProps &
|
|
||||||
Actions & {
|
|
||||||
safe: Safe,
|
|
||||||
threshold: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
type State = {
|
|
||||||
done: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ADD_OWNER_RESET_BUTTON_TEXT = 'RESET'
|
|
||||||
|
|
||||||
const getOwnerAddressesFrom = (owners: List<Owner>) => {
|
|
||||||
if (!owners) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
return owners.map((owner: Owner) => owner.get('address'))
|
|
||||||
}
|
|
||||||
|
|
||||||
export const addOwner = async (values: Object, safe: Safe, threshold: number, executor: string) => {
|
|
||||||
const safeAddress = safe.get('address')
|
|
||||||
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
|
|
||||||
const nonce = await gnosisSafe.nonce()
|
|
||||||
|
|
||||||
const newThreshold = values[INCREASE_PARAM] ? threshold + 1 : threshold
|
|
||||||
const newOwnerAddress = values[OWNER_ADDRESS_PARAM]
|
|
||||||
const newOwnerName = values[NAME_PARAM]
|
|
||||||
|
|
||||||
const data = gnosisSafe.contract.methods.addOwnerWithThreshold(newOwnerAddress, newThreshold).encodeABI()
|
|
||||||
await createTransaction(safe, `Add Owner ${newOwnerName}`, safeAddress, '0', nonce, executor, data)
|
|
||||||
setOwners(safeAddress, safe.get('owners').push(makeOwner({ name: newOwnerName, address: newOwnerAddress })))
|
|
||||||
}
|
|
||||||
|
|
||||||
class AddOwner extends React.Component<Props, State> {
|
|
||||||
state = {
|
|
||||||
done: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
onAddOwner = async (values: Object) => {
|
|
||||||
try {
|
|
||||||
const {
|
|
||||||
safe, threshold, userAddress, fetchTransactions,
|
|
||||||
} = this.props
|
|
||||||
await addOwner(values, safe, threshold, userAddress)
|
|
||||||
fetchTransactions(safe.get('address'))
|
|
||||||
this.setState({ done: true })
|
|
||||||
} catch (error) {
|
|
||||||
this.setState({ done: false })
|
|
||||||
// eslint-disable-next-line
|
|
||||||
console.log('Error while adding owner ' + error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onReset = () => {
|
|
||||||
this.setState({ done: false })
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { safe } = this.props
|
|
||||||
const { done } = this.state
|
|
||||||
const steps = getSteps()
|
|
||||||
const finishedButton = <Stepper.FinishButton title={ADD_OWNER_RESET_BUTTON_TEXT} />
|
|
||||||
const addresses = getOwnerAddressesFrom(safe.get('owners'))
|
|
||||||
|
|
||||||
return (
|
|
||||||
<React.Fragment>
|
|
||||||
<Stepper
|
|
||||||
finishedTransaction={done}
|
|
||||||
finishedButton={finishedButton}
|
|
||||||
onSubmit={this.onAddOwner}
|
|
||||||
steps={steps}
|
|
||||||
onReset={this.onReset}
|
|
||||||
>
|
|
||||||
<Stepper.Page numOwners={safe.get('owners').count()} threshold={safe.get('threshold')} addresses={addresses}>
|
|
||||||
{AddOwnerForm}
|
|
||||||
</Stepper.Page>
|
|
||||||
<Stepper.Page>{Review}</Stepper.Page>
|
|
||||||
</Stepper>
|
|
||||||
</React.Fragment>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default connect(
|
|
||||||
selector,
|
|
||||||
actions,
|
|
||||||
)(AddOwner)
|
|
|
@ -1,11 +0,0 @@
|
||||||
// @flow
|
|
||||||
import { createStructuredSelector } from 'reselect'
|
|
||||||
import { userAccountSelector } from '~/logic/wallets/store/selectors'
|
|
||||||
|
|
||||||
export type SelectorProps = {
|
|
||||||
userAddress: userAccountSelector,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default createStructuredSelector({
|
|
||||||
userAddress: userAccountSelector,
|
|
||||||
})
|
|
Loading…
Reference in New Issue