From ca729f1707d7aad97ad10488a139d1bace6be039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Fri, 24 May 2019 20:34:23 +0200 Subject: [PATCH] Remove old implementation of add owner to a Safe --- .../AddOwner/AddOwnerForm/index.jsx | 70 ------------ .../safe/components/AddOwner/Review/index.jsx | 48 -------- .../safe/components/AddOwner/actions.js | 12 -- src/routes/safe/components/AddOwner/index.jsx | 105 ------------------ .../safe/components/AddOwner/selector.js | 11 -- 5 files changed, 246 deletions(-) delete mode 100644 src/routes/safe/components/AddOwner/AddOwnerForm/index.jsx delete mode 100644 src/routes/safe/components/AddOwner/Review/index.jsx delete mode 100644 src/routes/safe/components/AddOwner/actions.js delete mode 100644 src/routes/safe/components/AddOwner/index.jsx delete mode 100644 src/routes/safe/components/AddOwner/selector.js diff --git a/src/routes/safe/components/AddOwner/AddOwnerForm/index.jsx b/src/routes/safe/components/AddOwner/AddOwnerForm/index.jsx deleted file mode 100644 index b756f2d3..00000000 --- a/src/routes/safe/components/AddOwner/AddOwnerForm/index.jsx +++ /dev/null @@ -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) => ( - - - Add Owner - - - {`Actual number of owners: ${numOwners}, with threshold: ${threshold}`} - - - - - - - - - - Increase threshold? - - -) - -export default AddOwnerForm diff --git a/src/routes/safe/components/AddOwner/Review/index.jsx b/src/routes/safe/components/AddOwner/Review/index.jsx deleted file mode 100644 index 4ce516ad..00000000 --- a/src/routes/safe/components/AddOwner/Review/index.jsx +++ /dev/null @@ -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 ( - - Review the Add Owner operation - - Owner Name: - {' '} - {values[NAME_PARAM]} - - - Owner Address: - {' '} - {values[OWNER_ADDRESS_PARAM]} - - - {text} - - - { submitting && } - - - ) -} - -export default Review diff --git a/src/routes/safe/components/AddOwner/actions.js b/src/routes/safe/components/AddOwner/actions.js deleted file mode 100644 index 32f51f38..00000000 --- a/src/routes/safe/components/AddOwner/actions.js +++ /dev/null @@ -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, -} diff --git a/src/routes/safe/components/AddOwner/index.jsx b/src/routes/safe/components/AddOwner/index.jsx deleted file mode 100644 index 920f056e..00000000 --- a/src/routes/safe/components/AddOwner/index.jsx +++ /dev/null @@ -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) => { - 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 { - 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 = - const addresses = getOwnerAddressesFrom(safe.get('owners')) - - return ( - - - - {AddOwnerForm} - - {Review} - - - ) - } -} - -export default connect( - selector, - actions, -)(AddOwner) diff --git a/src/routes/safe/components/AddOwner/selector.js b/src/routes/safe/components/AddOwner/selector.js deleted file mode 100644 index cefe3460..00000000 --- a/src/routes/safe/components/AddOwner/selector.js +++ /dev/null @@ -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, -})