Refactor get Safe instance

This commit is contained in:
Germán Martínez 2019-05-20 18:21:56 +02:00
parent ef9f6ae575
commit 5e37453ac6
2 changed files with 5 additions and 12 deletions

View File

@ -17,10 +17,9 @@ import {
sm, md, lg, border, secondary, sm, md, lg, border, secondary,
} from '~/theme/variables' } from '~/theme/variables'
import { getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields' import { getOwnerNameBy, getOwnerAddressBy } from '~/routes/open/components/fields'
import { getEtherScanLink, getWeb3 } from '~/logic/wallets/getWeb3' import { getEtherScanLink } from '~/logic/wallets/getWeb3'
import { FIELD_LOAD_ADDRESS, THRESHOLD } from '~/routes/load/components/fields' import { FIELD_LOAD_ADDRESS, THRESHOLD } from '~/routes/load/components/fields'
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
const openIconStyle = { const openIconStyle = {
height: '16px', height: '16px',
@ -102,12 +101,9 @@ class OwnerListComponent extends React.PureComponent<Props, State> {
componentDidMount = async () => { componentDidMount = async () => {
this.mounted = true this.mounted = true
const { values, updateInitialProps } = this.props const { values, updateInitialProps } = this.props
const safeAddress = values[FIELD_LOAD_ADDRESS] const safeAddress = values[FIELD_LOAD_ADDRESS]
const web3 = getWeb3()
const GnosisSafe = getGnosisSafeContract(web3) const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const gnosisSafe = await GnosisSafe.at(safeAddress)
const owners = await gnosisSafe.getOwners() const owners = await gnosisSafe.getOwners()
const threshold = await gnosisSafe.getThreshold() const threshold = await gnosisSafe.getThreshold()

View File

@ -11,9 +11,8 @@ import selector, { type SelectorProps } from './selector'
import actions, { type Actions } from './actions' import actions, { type Actions } from './actions'
import Layout from '../components/Layout' import Layout from '../components/Layout'
import { getNamesFrom, getOwnersFrom } from '~/routes/open/utils/safeDataExtractor' import { getNamesFrom, getOwnersFrom } from '~/routes/open/utils/safeDataExtractor'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS } from '../components/fields' import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS } from '../components/fields'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
type Props = SelectorProps & Actions type Props = SelectorProps & Actions
@ -41,9 +40,7 @@ class Load extends React.Component<Props> {
const safeAddress = values[FIELD_LOAD_ADDRESS] const safeAddress = values[FIELD_LOAD_ADDRESS]
const ownerNames = getNamesFrom(values) const ownerNames = getNamesFrom(values)
const web3 = getWeb3() const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const GnosisSafe = getGnosisSafeContract(web3)
const gnosisSafe = await GnosisSafe.at(safeAddress)
const ownerAddresses = await gnosisSafe.getOwners() const ownerAddresses = await gnosisSafe.getOwners()
const owners = getOwnersFrom(ownerNames, ownerAddresses.sort()) const owners = getOwnersFrom(ownerNames, ownerAddresses.sort())