WA-234 Disabling decrease on edge conditions when removing owners

This commit is contained in:
apanizo 2018-06-12 08:59:40 +02:00
parent a213007068
commit 31a0c9a5f2
2 changed files with 19 additions and 3 deletions

View File

@ -11,9 +11,12 @@ type Props = {
numOwners: number, numOwners: number,
threshold: number, threshold: number,
name: string, name: string,
disabled: boolean,
} }
const RemoveOwnerForm = ({ numOwners, threshold, name }: Props) => () => ( const RemoveOwnerForm = ({
numOwners, threshold, name, disabled,
}: Props) => () => (
<Block margin="md"> <Block margin="md">
<Heading tag="h2" margin="lg"> <Heading tag="h2" margin="lg">
Remove Owner { !!name && name } Remove Owner { !!name && name }
@ -26,8 +29,9 @@ const RemoveOwnerForm = ({ numOwners, threshold, name }: Props) => () => (
name={DECREASE_PARAM} name={DECREASE_PARAM}
component={Checkbox} component={Checkbox}
type="checkbox" type="checkbox"
disabled={disabled}
/> />
<Block>Decrease threshold?</Block> <Block>{disabled && '(disabled) '}Decrease threshold?</Block>
</Block> </Block>
</Block> </Block>
) )

View File

@ -27,6 +27,12 @@ type State = {
const SENTINEL_ADDRESS = '0x0000000000000000000000000000000000000001' const SENTINEL_ADDRESS = '0x0000000000000000000000000000000000000001'
export const REMOVE_OWNER_RESET_BUTTON_TEXT = 'RESET' export const REMOVE_OWNER_RESET_BUTTON_TEXT = 'RESET'
const initialValuesFrom = (decreaseMandatory: boolean = false) => ({
[DECREASE_PARAM]: decreaseMandatory,
})
const shouldDecrease = (numOwners: number, threshold: number) => threshold === numOwners
class RemoveOwner extends React.Component<Props, State> { class RemoveOwner extends React.Component<Props, State> {
state = { state = {
done: false, done: false,
@ -67,7 +73,12 @@ class RemoveOwner extends React.Component<Props, State> {
const { safe, name } = this.props const { safe, name } = this.props
const { done } = this.state const { done } = this.state
const steps = getSteps() const steps = getSteps()
const numOwners = safe.get('owners').count()
const threshold = safe.get('threshold')
const finishedButton = <Stepper.FinishButton title={REMOVE_OWNER_RESET_BUTTON_TEXT} /> const finishedButton = <Stepper.FinishButton title={REMOVE_OWNER_RESET_BUTTON_TEXT} />
const decrease = shouldDecrease(numOwners, threshold)
const initialValues = initialValuesFrom(decrease)
const disabled = decrease || threshold === 1
return ( return (
<React.Fragment> <React.Fragment>
@ -77,8 +88,9 @@ class RemoveOwner extends React.Component<Props, State> {
onSubmit={this.onRemoveOwner} onSubmit={this.onRemoveOwner}
steps={steps} steps={steps}
onReset={this.onReset} onReset={this.onReset}
initialValues={initialValues}
> >
<Stepper.Page numOwners={safe.get('owners').count()} threshold={safe.get('threshold')} name={name}> <Stepper.Page numOwners={numOwners} threshold={threshold} name={name} disabled={disabled}>
{ RemoveOwnerForm } { RemoveOwnerForm }
</Stepper.Page> </Stepper.Page>
<Stepper.Page name={name}> <Stepper.Page name={name}>