Add initial values and threshold to load Safe
This commit is contained in:
parent
de95d10d43
commit
853427c1b2
|
@ -71,7 +71,7 @@ export const safeFieldsValidation = async (values: Object) => {
|
||||||
)
|
)
|
||||||
const safeMaster = await getSafeMasterContract()
|
const safeMaster = await getSafeMasterContract()
|
||||||
const masterCopy = safeMaster.address
|
const masterCopy = safeMaster.address
|
||||||
|
|
||||||
const sameMasterCopy = checksummedProxyAddress === masterCopy
|
const sameMasterCopy = checksummedProxyAddress === masterCopy
|
||||||
if (!sameMasterCopy) {
|
if (!sameMasterCopy) {
|
||||||
errors[FIELD_LOAD_ADDRESS] = SAFE_MASTERCOPY_ERROR
|
errors[FIELD_LOAD_ADDRESS] = SAFE_MASTERCOPY_ERROR
|
||||||
|
|
|
@ -33,6 +33,7 @@ const Layout = ({
|
||||||
provider, onLoadSafeSubmit, network, userAddress,
|
provider, onLoadSafeSubmit, network, userAddress,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const steps = getSteps()
|
const steps = getSteps()
|
||||||
|
const initialValues = {}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -44,7 +45,7 @@ const Layout = ({
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Heading tag="h2">Load existing Safe</Heading>
|
<Heading tag="h2">Load existing Safe</Heading>
|
||||||
</Row>
|
</Row>
|
||||||
<Stepper onSubmit={onLoadSafeSubmit} steps={steps} testId="load-safe-form">
|
<Stepper onSubmit={onLoadSafeSubmit} steps={steps} initialValues={initialValues} testId="load-safe-form">
|
||||||
<Stepper.Page validate={safeFieldsValidation}>{DetailsForm}</Stepper.Page>
|
<Stepper.Page validate={safeFieldsValidation}>{DetailsForm}</Stepper.Page>
|
||||||
<Stepper.Page network={network}>{OwnerList}</Stepper.Page>
|
<Stepper.Page network={network}>{OwnerList}</Stepper.Page>
|
||||||
<Stepper.Page network={network} userAddress={userAddress}>
|
<Stepper.Page network={network} userAddress={userAddress}>
|
||||||
|
|
|
@ -16,9 +16,9 @@ import Hairline from '~/components/layout/Hairline'
|
||||||
import {
|
import {
|
||||||
xs, sm, md, lg, border, secondary,
|
xs, sm, md, lg, border, secondary,
|
||||||
} from '~/theme/variables'
|
} from '~/theme/variables'
|
||||||
import { getOwnerNameBy } from '~/routes/open/components/fields'
|
import { getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields'
|
||||||
import { getEtherScanLink, getWeb3 } from '~/logic/wallets/getWeb3'
|
import { getEtherScanLink, getWeb3 } from '~/logic/wallets/getWeb3'
|
||||||
import { FIELD_LOAD_ADDRESS } from '~/routes/load/components/fields'
|
import { FIELD_LOAD_ADDRESS, THRESHOLD } from '~/routes/load/components/fields'
|
||||||
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
|
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,12 +76,22 @@ type LayoutProps = {
|
||||||
type Props = LayoutProps & {
|
type Props = LayoutProps & {
|
||||||
values: Object,
|
values: Object,
|
||||||
classes: Object,
|
classes: Object,
|
||||||
|
updateInitialProps: (initialValues: Object) => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
owners: Array<string>,
|
owners: Array<string>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const calculateSafeValues = (owners: Array<string>, threshold: Number, values: Object) => {
|
||||||
|
const initialValues = { ...values }
|
||||||
|
for (let i = 0; i < owners.length; i += 1) {
|
||||||
|
initialValues[getOwnerAddressBy(i)] = owners[i]
|
||||||
|
}
|
||||||
|
initialValues[THRESHOLD] = threshold
|
||||||
|
return initialValues
|
||||||
|
}
|
||||||
|
|
||||||
class OwnerListComponent extends React.PureComponent<Props, State> {
|
class OwnerListComponent extends React.PureComponent<Props, State> {
|
||||||
state = {
|
state = {
|
||||||
owners: [],
|
owners: [],
|
||||||
|
@ -91,7 +101,7 @@ class OwnerListComponent extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
componentDidMount = async () => {
|
componentDidMount = async () => {
|
||||||
this.mounted = true
|
this.mounted = true
|
||||||
const { values } = this.props
|
const { values, updateInitialProps } = this.props
|
||||||
|
|
||||||
const safeAddress = values[FIELD_LOAD_ADDRESS]
|
const safeAddress = values[FIELD_LOAD_ADDRESS]
|
||||||
const web3 = getWeb3()
|
const web3 = getWeb3()
|
||||||
|
@ -99,6 +109,10 @@ class OwnerListComponent extends React.PureComponent<Props, State> {
|
||||||
const GnosisSafe = getGnosisSafeContract(web3)
|
const GnosisSafe = getGnosisSafeContract(web3)
|
||||||
const gnosisSafe = await GnosisSafe.at(safeAddress)
|
const gnosisSafe = await GnosisSafe.at(safeAddress)
|
||||||
const owners = await gnosisSafe.getOwners()
|
const owners = await gnosisSafe.getOwners()
|
||||||
|
const threshold = await gnosisSafe.getThreshold()
|
||||||
|
|
||||||
|
const initialValues = calculateSafeValues(owners.sort(), threshold, values)
|
||||||
|
updateInitialProps(initialValues)
|
||||||
|
|
||||||
if (!owners) {
|
if (!owners) {
|
||||||
return
|
return
|
||||||
|
@ -166,11 +180,12 @@ class OwnerListComponent extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
const OwnerListPage = withStyles(styles)(OwnerListComponent)
|
const OwnerListPage = withStyles(styles)(OwnerListComponent)
|
||||||
|
|
||||||
const OwnerList = (network: string) => (controls: React$Node, { values }: Object) => (
|
const OwnerList = ({ updateInitialProps }: Object, network: string) => (controls: React$Node, { values }: Object) => (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<OpenPaper controls={controls} padding={false}>
|
<OpenPaper controls={controls} padding={false}>
|
||||||
<OwnerListPage
|
<OwnerListPage
|
||||||
network={network}
|
network={network}
|
||||||
|
updateInitialProps={updateInitialProps}
|
||||||
values={values}
|
values={values}
|
||||||
/>
|
/>
|
||||||
</OpenPaper>
|
</OpenPaper>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
// @flow
|
// @flow
|
||||||
export const FIELD_LOAD_NAME: string = 'name'
|
export const FIELD_LOAD_NAME: string = 'name'
|
||||||
export const FIELD_LOAD_ADDRESS: string = 'address'
|
export const FIELD_LOAD_ADDRESS: string = 'address'
|
||||||
|
export const THRESHOLD: Number = 'threshold'
|
||||||
|
|
Loading…
Reference in New Issue