From 260e7e128017e5621524777343d7737387c61b5d Mon Sep 17 00:00:00 2001 From: apanizo Date: Thu, 7 Jun 2018 15:29:06 +0200 Subject: [PATCH] WA-234 Adding Review process when changing threshold --- src/routes/safe/component/AddOwner/index.jsx | 2 +- src/routes/safe/component/Safe/index.jsx | 2 +- .../safe/component/Threshold/Review/index.jsx | 31 +++++ .../Threshold/ThresholdForm/index.jsx | 43 ++++++ src/routes/safe/component/Threshold/index.jsx | 125 +++++++----------- 5 files changed, 127 insertions(+), 76 deletions(-) create mode 100644 src/routes/safe/component/Threshold/Review/index.jsx create mode 100644 src/routes/safe/component/Threshold/ThresholdForm/index.jsx diff --git a/src/routes/safe/component/AddOwner/index.jsx b/src/routes/safe/component/AddOwner/index.jsx index 4869314f..61f95978 100644 --- a/src/routes/safe/component/AddOwner/index.jsx +++ b/src/routes/safe/component/AddOwner/index.jsx @@ -13,7 +13,7 @@ import selector, { type SelectorProps } from './selector' import actions, { type Actions } from './actions' const getSteps = () => [ - 'Fill Owner Form', 'Review Withdrawn', + 'Fill Owner Form', 'Review Add order operation', ] type Props = SelectorProps & Actions & { diff --git a/src/routes/safe/component/Safe/index.jsx b/src/routes/safe/component/Safe/index.jsx index 648d315e..06062d50 100644 --- a/src/routes/safe/component/Safe/index.jsx +++ b/src/routes/safe/component/Safe/index.jsx @@ -64,7 +64,7 @@ class GnoSafe extends React.PureComponent { onEditThreshold = () => { const { safe } = this.props - this.setState({ component: }) + this.setState({ component: }) } onAddOwner = () => { diff --git a/src/routes/safe/component/Threshold/Review/index.jsx b/src/routes/safe/component/Threshold/Review/index.jsx new file mode 100644 index 00000000..0483e876 --- /dev/null +++ b/src/routes/safe/component/Threshold/Review/index.jsx @@ -0,0 +1,31 @@ +// @flow +import * as React from 'react' +import { CircularProgress } from 'material-ui/Progress' +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 { THRESHOLD_PARAM } from '~/routes/safe/component/Threshold/ThresholdForm' + +type FormProps = { + values: Object, + submitting: boolean, +} + +const spinnerStyle = { + minHeight: '50px', +} + +const Review = () => ({ values, submitting }: FormProps) => ( + + Review the Threshold operation + + The new threshold will be: {values[THRESHOLD_PARAM]} + + + { submitting && } + + +) + +export default Review diff --git a/src/routes/safe/component/Threshold/ThresholdForm/index.jsx b/src/routes/safe/component/Threshold/ThresholdForm/index.jsx new file mode 100644 index 00000000..b155238a --- /dev/null +++ b/src/routes/safe/component/Threshold/ThresholdForm/index.jsx @@ -0,0 +1,43 @@ +// @flow +import * as React from 'react' +import Block from '~/components/layout/Block' +import Heading from '~/components/layout/Heading' +import Field from '~/components/forms/Field' +import TextField from '~/components/forms/TextField' +import { composeValidators, minValue, maxValue, mustBeInteger, required } from '~/components/forms/validator' +import { type Safe } from '~/routes/safe/store/model/safe' + +export const THRESHOLD_PARAM = 'threshold' + +type ThresholdProps = { + numOwners: number, + safe: Safe, +} + +const ThresholdForm = ({ numOwners, safe }: ThresholdProps) => () => ( + + + {'Change safe\'s threshold'} + + + {`Safe's owners: ${numOwners} and Safe's threshold: ${safe.get('confirmations')}`} + + + + + +) + +export default ThresholdForm diff --git a/src/routes/safe/component/Threshold/index.jsx b/src/routes/safe/component/Threshold/index.jsx index f7fffec8..5d144efe 100644 --- a/src/routes/safe/component/Threshold/index.jsx +++ b/src/routes/safe/component/Threshold/index.jsx @@ -1,105 +1,82 @@ // @flow import * as React from 'react' -import Block from '~/components/layout/Block' -import Heading from '~/components/layout/Heading' -import Field from '~/components/forms/Field' -import TextField from '~/components/forms/TextField' -import GnoForm from '~/components/forms/GnoForm' +import Stepper from '~/components/Stepper' import { connect } from 'react-redux' -import Button from '~/components/layout/Button' -import Col from '~/components/layout/Col' -import Row from '~/components/layout/Row' -import { composeValidators, minValue, maxValue, mustBeInteger, required } from '~/components/forms/validator' import { getSafeEthereumInstance, createTransaction } from '~/routes/safe/component/AddTransaction/createTransactions' import { sleep } from '~/utils/timer' import { type Safe } from '~/routes/safe/store/model/safe' +import ThresholdForm, { THRESHOLD_PARAM } from './ThresholdForm' import selector, { type SelectorProps } from './selector' import actions, { type Actions } from './actions' +import Review from './Review' -type ThresholdProps = { +type Props = SelectorProps & Actions & { numOwners: number, safe: Safe, -} - -type Props = SelectorProps & Actions & ThresholdProps & { onReset: () => void, } -const THRESHOLD_PARAM = 'threshold' - -const ThresholdComponent = ({ numOwners, safe }: ThresholdProps) => () => ( - - - {'Change safe\'s threshold'} - - - {`Safe's owners: ${numOwners} and Safe's threshold: ${safe.get('confirmations')}`} - - - - - -) +const getSteps = () => [ + 'Fill Change threshold Form', 'Review change threshold operation', +] type State = { - initialValues: Object, + done: boolean, } +export const CHANGE_THRESHOLD_RESET_BUTTON_TEXT = 'RESET' + class Threshold extends React.PureComponent { state = { - initialValues: {}, + done: false, } onThreshold = async (values: Object) => { - const { safe, userAddress } = this.props // , fetchThreshold } = this.props - const newThreshold = values[THRESHOLD_PARAM] - const gnosisSafe = await getSafeEthereumInstance(safe.get('address')) - const nonce = Date.now() - const data = gnosisSafe.contract.changeThreshold.getData(newThreshold) - await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safe.get('address'), 0, nonce, userAddress, data) - await sleep(1500) - this.props.fetchTransactions() - this.props.fetchThreshold(safe.get('address')) + try { + const { safe, userAddress } = this.props // , fetchThreshold } = this.props + const newThreshold = values[THRESHOLD_PARAM] + const gnosisSafe = await getSafeEthereumInstance(safe.get('address')) + const nonce = Date.now() + const data = gnosisSafe.contract.changeThreshold.getData(newThreshold) + await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safe.get('address'), 0, nonce, userAddress, data) + await sleep(1500) + await this.props.fetchTransactions() + await this.props.fetchThreshold(safe.get('address')) + this.setState({ done: true }) + } catch (error) { + this.setState({ done: false }) + // eslint-disable-next-line + console.log('Error while changing threshold ' + error) + } + } + + onReset = () => { + this.setState({ done: false }) } render() { - const { numOwners, onReset, safe } = this.props + const { numOwners, safe } = this.props + const { done } = this.state + const steps = getSteps() + const finishedButton = return ( - - {(submitting: boolean, submitSucceeded: boolean) => ( - - - - - - )} - + + + + { ThresholdForm } + + + { Review } + + + ) } }