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 masterCopy = safeMaster.address
|
||||
|
||||
|
||||
const sameMasterCopy = checksummedProxyAddress === masterCopy
|
||||
if (!sameMasterCopy) {
|
||||
errors[FIELD_LOAD_ADDRESS] = SAFE_MASTERCOPY_ERROR
|
||||
|
|
|
@ -33,6 +33,7 @@ const Layout = ({
|
|||
provider, onLoadSafeSubmit, network, userAddress,
|
||||
}: Props) => {
|
||||
const steps = getSteps()
|
||||
const initialValues = {}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
|
@ -44,7 +45,7 @@ const Layout = ({
|
|||
</IconButton>
|
||||
<Heading tag="h2">Load existing Safe</Heading>
|
||||
</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 network={network}>{OwnerList}</Stepper.Page>
|
||||
<Stepper.Page network={network} userAddress={userAddress}>
|
||||
|
|
|
@ -16,9 +16,9 @@ import Hairline from '~/components/layout/Hairline'
|
|||
import {
|
||||
xs, sm, md, lg, border, secondary,
|
||||
} 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 { FIELD_LOAD_ADDRESS } from '~/routes/load/components/fields'
|
||||
import { FIELD_LOAD_ADDRESS, THRESHOLD } from '~/routes/load/components/fields'
|
||||
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
|
||||
|
||||
|
||||
|
@ -76,12 +76,22 @@ type LayoutProps = {
|
|||
type Props = LayoutProps & {
|
||||
values: Object,
|
||||
classes: Object,
|
||||
updateInitialProps: (initialValues: Object) => void,
|
||||
}
|
||||
|
||||
type State = {
|
||||
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> {
|
||||
state = {
|
||||
owners: [],
|
||||
|
@ -91,7 +101,7 @@ class OwnerListComponent extends React.PureComponent<Props, State> {
|
|||
|
||||
componentDidMount = async () => {
|
||||
this.mounted = true
|
||||
const { values } = this.props
|
||||
const { values, updateInitialProps } = this.props
|
||||
|
||||
const safeAddress = values[FIELD_LOAD_ADDRESS]
|
||||
const web3 = getWeb3()
|
||||
|
@ -99,6 +109,10 @@ class OwnerListComponent extends React.PureComponent<Props, State> {
|
|||
const GnosisSafe = getGnosisSafeContract(web3)
|
||||
const gnosisSafe = await GnosisSafe.at(safeAddress)
|
||||
const owners = await gnosisSafe.getOwners()
|
||||
const threshold = await gnosisSafe.getThreshold()
|
||||
|
||||
const initialValues = calculateSafeValues(owners.sort(), threshold, values)
|
||||
updateInitialProps(initialValues)
|
||||
|
||||
if (!owners) {
|
||||
return
|
||||
|
@ -166,11 +180,12 @@ class OwnerListComponent extends React.PureComponent<Props, State> {
|
|||
|
||||
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>
|
||||
<OpenPaper controls={controls} padding={false}>
|
||||
<OwnerListPage
|
||||
network={network}
|
||||
updateInitialProps={updateInitialProps}
|
||||
values={values}
|
||||
/>
|
||||
</OpenPaper>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// @flow
|
||||
export const FIELD_LOAD_NAME: string = 'name'
|
||||
export const FIELD_LOAD_ADDRESS: string = 'address'
|
||||
export const THRESHOLD: Number = 'threshold'
|
||||
|
|
Loading…
Reference in New Issue