From fc220940840ca589251569a53f8ffdbb4f850ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Tue, 28 May 2019 17:39:00 +0200 Subject: [PATCH] Remove old implementation of remove owner --- .../RemoveOwner/RemoveOwnerForm/index.jsx | 50 -------- .../components/RemoveOwner/Review/index.jsx | 47 ------- .../safe/components/RemoveOwner/actions.js | 12 -- .../safe/components/RemoveOwner/index.jsx | 121 ------------------ .../safe/components/RemoveOwner/selector.js | 21 --- 5 files changed, 251 deletions(-) delete mode 100644 src/routes/safe/components/RemoveOwner/RemoveOwnerForm/index.jsx delete mode 100644 src/routes/safe/components/RemoveOwner/Review/index.jsx delete mode 100644 src/routes/safe/components/RemoveOwner/actions.js delete mode 100644 src/routes/safe/components/RemoveOwner/index.jsx delete mode 100644 src/routes/safe/components/RemoveOwner/selector.js diff --git a/src/routes/safe/components/RemoveOwner/RemoveOwnerForm/index.jsx b/src/routes/safe/components/RemoveOwner/RemoveOwnerForm/index.jsx deleted file mode 100644 index 5f1a61a4..00000000 --- a/src/routes/safe/components/RemoveOwner/RemoveOwnerForm/index.jsx +++ /dev/null @@ -1,50 +0,0 @@ -// @flow -import * as React from 'react' -import Field from '~/components/forms/Field' -import SnackbarContent from '~/components/SnackbarContent' -import OpenPaper from '~/components/Stepper/OpenPaper' -import Checkbox from '~/components/forms/Checkbox' -import Block from '~/components/layout/Block' -import Heading from '~/components/layout/Heading' - -export const DECREASE_PARAM = 'decrease' - -type Props = { - numOwners: number, - threshold: number, - name: string, - disabled: boolean, - pendingTransactions: boolean, -} - -const RemoveOwnerForm = ({ - numOwners, threshold, name, disabled, pendingTransactions, -}: Props) => ( - controls: React.Node, -) => ( - - - Remove Owner - {' '} - {!!name && name} - - - {`Actual number of owners: ${numOwners}, threhsold of safe: ${threshold}`} - - {pendingTransactions && ( - - )} - - - - {disabled && '(disabled) '} - Decrease threshold? - - - -) - -export default RemoveOwnerForm diff --git a/src/routes/safe/components/RemoveOwner/Review/index.jsx b/src/routes/safe/components/RemoveOwner/Review/index.jsx deleted file mode 100644 index f9e35c2d..00000000 --- a/src/routes/safe/components/RemoveOwner/Review/index.jsx +++ /dev/null @@ -1,47 +0,0 @@ -// @flow -import * as React from 'react' -import CircularProgress from '@material-ui/core/CircularProgress' -import Block from '~/components/layout/Block' -import OpenPaper from '~/components/Stepper/OpenPaper' -import Bold from '~/components/layout/Bold' -import Heading from '~/components/layout/Heading' -import Paragraph from '~/components/layout/Paragraph' -import { DECREASE_PARAM } from '~/routes/safe/components/RemoveOwner/RemoveOwnerForm' - -type Props = { - name: string, -} - -type FormProps = { - values: Object, - submitting: boolean, -} - -const spinnerStyle = { - minHeight: '50px', -} - -const Review = ({ name }: Props) => (controls: React.Node, { values, submitting }: FormProps) => { - const text = values[DECREASE_PARAM] - ? 'This operation will decrease the threshold of the safe' - : 'This operation will not modify the threshold of the safe' - - return ( - - Review the Remove Owner operation - - Owner Name: - {' '} - {name} - - - {text} - - - { submitting && } - - - ) -} - -export default Review diff --git a/src/routes/safe/components/RemoveOwner/actions.js b/src/routes/safe/components/RemoveOwner/actions.js deleted file mode 100644 index 32f51f38..00000000 --- a/src/routes/safe/components/RemoveOwner/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/RemoveOwner/index.jsx b/src/routes/safe/components/RemoveOwner/index.jsx deleted file mode 100644 index d82592ab..00000000 --- a/src/routes/safe/components/RemoveOwner/index.jsx +++ /dev/null @@ -1,121 +0,0 @@ -// @flow -import * as React from 'react' -import Stepper from '~/components/Stepper' -import { connect } from 'react-redux' -import { type Safe } from '~/routes/safe/store/models/safe' -import { createTransaction } from '~/logic/safe/safeFrontendOperations' -import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' -import RemoveOwnerForm, { DECREASE_PARAM } from './RemoveOwnerForm' -import Review from './Review' -import selector, { type SelectorProps } from './selector' -import actions, { type Actions } from './actions' - -const getSteps = () => [ - 'Fill Owner Form', 'Review Remove order operation', -] - -type Props = SelectorProps & Actions & { - safe: Safe, - threshold: number, - name: string, - userToRemove: string, -} - -type State = { - done: boolean, -} - -const SENTINEL_ADDRESS = '0x0000000000000000000000000000000000000001' -export const REMOVE_OWNER_RESET_BUTTON_TEXT = 'RESET' - -export const initialValuesFrom = (decreaseMandatory: boolean = false) => ({ - [DECREASE_PARAM]: decreaseMandatory, -}) - -export const shouldDecrease = (numOwners: number, threshold: number) => threshold === numOwners - -export const removeOwner = async ( - values: Object, - safe: Safe, - threshold: number, - userToRemove: string, - name: string, - executor: string, -) => { - const safeAddress = safe.get('address') - const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) - const nonce = await gnosisSafe.nonce() - const newThreshold = values[DECREASE_PARAM] ? threshold - 1 : threshold - const storedOwners = await gnosisSafe.getOwners() - const index = storedOwners.findIndex(ownerAddress => ownerAddress === userToRemove) - const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1] - const data = gnosisSafe.contract.removeOwner(prevAddress, userToRemove, newThreshold).encodeABI() - const text = name || userToRemove - - return createTransaction(safe, `Remove Owner ${text}`, safeAddress, '0', nonce, executor, data) -} - -class RemoveOwner extends React.Component { - state = { - done: false, - } - - onRemoveOwner = async (values: Object) => { - try { - const { - safe, threshold, executor, fetchTransactions, userToRemove, name, - } = this.props - await removeOwner(values, safe, threshold, userToRemove, name, executor) - 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, name, pendingTransactions } = this.props - const { done } = this.state - const steps = getSteps() - const numOwners = safe.get('owners').count() - const threshold = safe.get('threshold') - const finishedButton = - const decrease = shouldDecrease(numOwners, threshold) - const initialValues = initialValuesFrom(decrease) - const disabled = decrease || threshold === 1 - - return ( - - - - { RemoveOwnerForm } - - - { Review } - - - - ) - } -} - -export default connect(selector, actions)(RemoveOwner) diff --git a/src/routes/safe/components/RemoveOwner/selector.js b/src/routes/safe/components/RemoveOwner/selector.js deleted file mode 100644 index 92dacedb..00000000 --- a/src/routes/safe/components/RemoveOwner/selector.js +++ /dev/null @@ -1,21 +0,0 @@ -// @flow -import { List } from 'immutable' -import { createStructuredSelector, createSelector } from 'reselect' -import { userAccountSelector } from '~/logic/wallets/store/selectors' -import { type Transaction } from '~/routes/safe/store/models/transaction' -import { safeTransactionsSelector } from '~/routes/safe/store/selectors/index' - -const pendingTransactionsSelector = createSelector( - safeTransactionsSelector, - (transactions: List) => transactions.findEntry((tx: Transaction) => tx.get('isExecuted')), -) - -export type SelectorProps = { - executor: typeof userAccountSelector, - pendingTransactions: typeof pendingTransactionsSelector, -} - -export default createStructuredSelector({ - executor: userAccountSelector, - pendingTransactions: pendingTransactionsSelector, -})