Refactor removing owners
This commit is contained in:
parent
aacd242da0
commit
5b3a4de489
|
@ -2,6 +2,7 @@
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import Field from '~/components/forms/Field'
|
import Field from '~/components/forms/Field'
|
||||||
import SnackbarContent from '~/components/SnackbarContent'
|
import SnackbarContent from '~/components/SnackbarContent'
|
||||||
|
import OpenPaper from '~/components/Stepper/OpenPaper'
|
||||||
import Checkbox from '~/components/forms/Checkbox'
|
import Checkbox from '~/components/forms/Checkbox'
|
||||||
import Block from '~/components/layout/Block'
|
import Block from '~/components/layout/Block'
|
||||||
import Heading from '~/components/layout/Heading'
|
import Heading from '~/components/layout/Heading'
|
||||||
|
@ -18,8 +19,8 @@ type Props = {
|
||||||
|
|
||||||
const RemoveOwnerForm = ({
|
const RemoveOwnerForm = ({
|
||||||
numOwners, threshold, name, disabled, pendingTransactions,
|
numOwners, threshold, name, disabled, pendingTransactions,
|
||||||
}: Props) => () => (
|
}: Props) => (controls: React$Node) => (
|
||||||
<Block margin="md">
|
<OpenPaper controls={controls}>
|
||||||
<Heading tag="h2" margin="lg">
|
<Heading tag="h2" margin="lg">
|
||||||
Remove Owner { !!name && name }
|
Remove Owner { !!name && name }
|
||||||
</Heading>
|
</Heading>
|
||||||
|
@ -41,7 +42,7 @@ const RemoveOwnerForm = ({
|
||||||
/>
|
/>
|
||||||
<Block>{disabled && '(disabled) '}Decrease threshold?</Block>
|
<Block>{disabled && '(disabled) '}Decrease threshold?</Block>
|
||||||
</Block>
|
</Block>
|
||||||
</Block>
|
</OpenPaper>
|
||||||
)
|
)
|
||||||
|
|
||||||
export default RemoveOwnerForm
|
export default RemoveOwnerForm
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import CircularProgress from '@material-ui/core/CircularProgress'
|
import CircularProgress from '@material-ui/core/CircularProgress'
|
||||||
import Block from '~/components/layout/Block'
|
import Block from '~/components/layout/Block'
|
||||||
|
import OpenPaper from '~/components/Stepper/OpenPaper'
|
||||||
import Bold from '~/components/layout/Bold'
|
import Bold from '~/components/layout/Bold'
|
||||||
import Heading from '~/components/layout/Heading'
|
import Heading from '~/components/layout/Heading'
|
||||||
import Paragraph from '~/components/layout/Paragraph'
|
import Paragraph from '~/components/layout/Paragraph'
|
||||||
|
@ -20,13 +21,13 @@ const spinnerStyle = {
|
||||||
minHeight: '50px',
|
minHeight: '50px',
|
||||||
}
|
}
|
||||||
|
|
||||||
const Review = ({ name }: Props) => ({ values, submitting }: FormProps) => {
|
const Review = ({ name }: Props) => (controls: React$Node, { values, submitting }: FormProps) => {
|
||||||
const text = values[DECREASE_PARAM]
|
const text = values[DECREASE_PARAM]
|
||||||
? 'This operation will decrease the threshold of the safe'
|
? 'This operation will decrease the threshold of the safe'
|
||||||
: 'This operation will not modify the threshold of the safe'
|
: 'This operation will not modify the threshold of the safe'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Block>
|
<OpenPaper controls={controls}>
|
||||||
<Heading tag="h2">Review the Remove Owner operation</Heading>
|
<Heading tag="h2">Review the Remove Owner operation</Heading>
|
||||||
<Paragraph align="left">
|
<Paragraph align="left">
|
||||||
<Bold>Owner Name: </Bold> {name}
|
<Bold>Owner Name: </Bold> {name}
|
||||||
|
@ -37,7 +38,7 @@ const Review = ({ name }: Props) => ({ values, submitting }: FormProps) => {
|
||||||
<Block style={spinnerStyle}>
|
<Block style={spinnerStyle}>
|
||||||
{ submitting && <CircularProgress size={50} /> }
|
{ submitting && <CircularProgress size={50} /> }
|
||||||
</Block>
|
</Block>
|
||||||
</Block>
|
</OpenPaper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Stepper from '~/components/Stepper'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||||
import { getSafeEthereumInstance, createTransaction } from '~/logic/safe/safeFrontendOperations'
|
import { getSafeEthereumInstance, createTransaction } from '~/logic/safe/safeFrontendOperations'
|
||||||
|
import { signaturesViaMetamask } from '~/config'
|
||||||
import RemoveOwnerForm, { DECREASE_PARAM } from './RemoveOwnerForm'
|
import RemoveOwnerForm, { DECREASE_PARAM } from './RemoveOwnerForm'
|
||||||
import Review from './Review'
|
import Review from './Review'
|
||||||
import selector, { type SelectorProps } from './selector'
|
import selector, { type SelectorProps } from './selector'
|
||||||
|
@ -41,10 +42,10 @@ export const removeOwner = async (
|
||||||
name: string,
|
name: string,
|
||||||
executor: string,
|
executor: string,
|
||||||
) => {
|
) => {
|
||||||
const nonce = Date.now()
|
|
||||||
const newThreshold = values[DECREASE_PARAM] ? threshold - 1 : threshold
|
|
||||||
const safeAddress = safe.get('address')
|
const safeAddress = safe.get('address')
|
||||||
const gnosisSafe = await getSafeEthereumInstance(safeAddress)
|
const gnosisSafe = await getSafeEthereumInstance(safeAddress)
|
||||||
|
const nonce = signaturesViaMetamask() ? await gnosisSafe.nonce() : Date.now()
|
||||||
|
const newThreshold = values[DECREASE_PARAM] ? threshold - 1 : threshold
|
||||||
const storedOwners = await gnosisSafe.getOwners()
|
const storedOwners = await gnosisSafe.getOwners()
|
||||||
const index = storedOwners.findIndex(ownerAddress => ownerAddress === userToRemove)
|
const index = storedOwners.findIndex(ownerAddress => ownerAddress === userToRemove)
|
||||||
const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1]
|
const prevAddress = index === 0 ? SENTINEL_ADDRESS : storedOwners[index - 1]
|
||||||
|
|
Loading…
Reference in New Issue