mirror of
https://github.com/status-im/safe-react.git
synced 2025-02-02 21:03:28 +00:00
WA-234 Adding Review process when changing threshold
This commit is contained in:
parent
4b2e0d3beb
commit
260e7e1280
@ -13,7 +13,7 @@ import selector, { type SelectorProps } from './selector'
|
|||||||
import actions, { type Actions } from './actions'
|
import actions, { type Actions } from './actions'
|
||||||
|
|
||||||
const getSteps = () => [
|
const getSteps = () => [
|
||||||
'Fill Owner Form', 'Review Withdrawn',
|
'Fill Owner Form', 'Review Add order operation',
|
||||||
]
|
]
|
||||||
|
|
||||||
type Props = SelectorProps & Actions & {
|
type Props = SelectorProps & Actions & {
|
||||||
|
@ -64,7 +64,7 @@ class GnoSafe extends React.PureComponent<SafeProps, State> {
|
|||||||
onEditThreshold = () => {
|
onEditThreshold = () => {
|
||||||
const { safe } = this.props
|
const { safe } = this.props
|
||||||
|
|
||||||
this.setState({ component: <Threshold numOwners={safe.get('owners').count()} safe={safe} onReset={this.onListTransactions} /> })
|
this.setState({ component: <Threshold numOwners={safe.get('owners').count()} safe={safe} /> })
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddOwner = () => {
|
onAddOwner = () => {
|
||||||
|
31
src/routes/safe/component/Threshold/Review/index.jsx
Normal file
31
src/routes/safe/component/Threshold/Review/index.jsx
Normal file
@ -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) => (
|
||||||
|
<Block>
|
||||||
|
<Heading tag="h2">Review the Threshold operation</Heading>
|
||||||
|
<Paragraph align="left">
|
||||||
|
<Bold>The new threshold will be: </Bold> {values[THRESHOLD_PARAM]}
|
||||||
|
</Paragraph>
|
||||||
|
<Block style={spinnerStyle}>
|
||||||
|
{ submitting && <CircularProgress size={50} /> }
|
||||||
|
</Block>
|
||||||
|
</Block>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default Review
|
43
src/routes/safe/component/Threshold/ThresholdForm/index.jsx
Normal file
43
src/routes/safe/component/Threshold/ThresholdForm/index.jsx
Normal file
@ -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) => () => (
|
||||||
|
<Block margin="md">
|
||||||
|
<Heading tag="h2" margin="lg">
|
||||||
|
{'Change safe\'s threshold'}
|
||||||
|
</Heading>
|
||||||
|
<Heading tag="h4" margin="lg">
|
||||||
|
{`Safe's owners: ${numOwners} and Safe's threshold: ${safe.get('confirmations')}`}
|
||||||
|
</Heading>
|
||||||
|
<Block margin="md">
|
||||||
|
<Field
|
||||||
|
name={THRESHOLD_PARAM}
|
||||||
|
component={TextField}
|
||||||
|
type="text"
|
||||||
|
validate={composeValidators(
|
||||||
|
required,
|
||||||
|
mustBeInteger,
|
||||||
|
minValue(1),
|
||||||
|
maxValue(numOwners),
|
||||||
|
)}
|
||||||
|
placeholder="New threshold"
|
||||||
|
text="Safe's threshold"
|
||||||
|
/>
|
||||||
|
</Block>
|
||||||
|
</Block>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default ThresholdForm
|
@ -1,105 +1,82 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import Block from '~/components/layout/Block'
|
import Stepper from '~/components/Stepper'
|
||||||
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 { connect } from 'react-redux'
|
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 { getSafeEthereumInstance, createTransaction } from '~/routes/safe/component/AddTransaction/createTransactions'
|
||||||
import { sleep } from '~/utils/timer'
|
import { sleep } from '~/utils/timer'
|
||||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||||
|
import ThresholdForm, { THRESHOLD_PARAM } from './ThresholdForm'
|
||||||
import selector, { type SelectorProps } from './selector'
|
import selector, { type SelectorProps } from './selector'
|
||||||
import actions, { type Actions } from './actions'
|
import actions, { type Actions } from './actions'
|
||||||
|
import Review from './Review'
|
||||||
|
|
||||||
type ThresholdProps = {
|
type Props = SelectorProps & Actions & {
|
||||||
numOwners: number,
|
numOwners: number,
|
||||||
safe: Safe,
|
safe: Safe,
|
||||||
}
|
|
||||||
|
|
||||||
type Props = SelectorProps & Actions & ThresholdProps & {
|
|
||||||
onReset: () => void,
|
onReset: () => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
const THRESHOLD_PARAM = 'threshold'
|
const getSteps = () => [
|
||||||
|
'Fill Change threshold Form', 'Review change threshold operation',
|
||||||
const ThresholdComponent = ({ numOwners, safe }: ThresholdProps) => () => (
|
]
|
||||||
<Block margin="md">
|
|
||||||
<Heading tag="h2" margin="lg">
|
|
||||||
{'Change safe\'s threshold'}
|
|
||||||
</Heading>
|
|
||||||
<Heading tag="h4" margin="lg">
|
|
||||||
{`Safe's owners: ${numOwners} and Safe's threshold: ${safe.get('confirmations')}`}
|
|
||||||
</Heading>
|
|
||||||
<Block margin="md">
|
|
||||||
<Field
|
|
||||||
name={THRESHOLD_PARAM}
|
|
||||||
component={TextField}
|
|
||||||
type="text"
|
|
||||||
validate={composeValidators(
|
|
||||||
required,
|
|
||||||
mustBeInteger,
|
|
||||||
minValue(1),
|
|
||||||
maxValue(numOwners),
|
|
||||||
)}
|
|
||||||
placeholder="New threshold"
|
|
||||||
text="Safe's threshold"
|
|
||||||
/>
|
|
||||||
</Block>
|
|
||||||
</Block>
|
|
||||||
)
|
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
initialValues: Object,
|
done: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const CHANGE_THRESHOLD_RESET_BUTTON_TEXT = 'RESET'
|
||||||
|
|
||||||
class Threshold extends React.PureComponent<Props, State> {
|
class Threshold extends React.PureComponent<Props, State> {
|
||||||
state = {
|
state = {
|
||||||
initialValues: {},
|
done: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
onThreshold = async (values: Object) => {
|
onThreshold = async (values: Object) => {
|
||||||
const { safe, userAddress } = this.props // , fetchThreshold } = this.props
|
try {
|
||||||
const newThreshold = values[THRESHOLD_PARAM]
|
const { safe, userAddress } = this.props // , fetchThreshold } = this.props
|
||||||
const gnosisSafe = await getSafeEthereumInstance(safe.get('address'))
|
const newThreshold = values[THRESHOLD_PARAM]
|
||||||
const nonce = Date.now()
|
const gnosisSafe = await getSafeEthereumInstance(safe.get('address'))
|
||||||
const data = gnosisSafe.contract.changeThreshold.getData(newThreshold)
|
const nonce = Date.now()
|
||||||
await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safe.get('address'), 0, nonce, userAddress, data)
|
const data = gnosisSafe.contract.changeThreshold.getData(newThreshold)
|
||||||
await sleep(1500)
|
await createTransaction(safe, `Change Safe's threshold [${nonce}]`, safe.get('address'), 0, nonce, userAddress, data)
|
||||||
this.props.fetchTransactions()
|
await sleep(1500)
|
||||||
this.props.fetchThreshold(safe.get('address'))
|
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() {
|
render() {
|
||||||
const { numOwners, onReset, safe } = this.props
|
const { numOwners, safe } = this.props
|
||||||
|
const { done } = this.state
|
||||||
|
const steps = getSteps()
|
||||||
|
const finishedButton = <Stepper.FinishButton title={CHANGE_THRESHOLD_RESET_BUTTON_TEXT} />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GnoForm
|
<React.Fragment>
|
||||||
onSubmit={this.onThreshold}
|
<Stepper
|
||||||
render={ThresholdComponent({ numOwners, safe })}
|
finishedTransaction={done}
|
||||||
padding={15}
|
finishedButton={finishedButton}
|
||||||
initialValues={this.state.initialValues}
|
onSubmit={this.onThreshold}
|
||||||
>
|
steps={steps}
|
||||||
{(submitting: boolean, submitSucceeded: boolean) => (
|
onReset={this.onReset}
|
||||||
<Row align="end" margin="lg" grow>
|
>
|
||||||
<Col xs={12} center="xs">
|
<Stepper.Page numOwners={numOwners} safe={safe}>
|
||||||
<Button
|
{ ThresholdForm }
|
||||||
variant="raised"
|
</Stepper.Page>
|
||||||
color="primary"
|
<Stepper.Page>
|
||||||
onClick={submitSucceeded ? onReset : undefined}
|
{ Review }
|
||||||
type={submitSucceeded ? 'button' : 'submit'}
|
</Stepper.Page>
|
||||||
disabled={submitting}
|
</Stepper>
|
||||||
>
|
</React.Fragment>
|
||||||
{ submitSucceeded ? 'VISIT TXs' : 'FINISH' }
|
|
||||||
</Button>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
)}
|
|
||||||
</GnoForm>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user