Creating opening route (no components yet)

This commit is contained in:
apanizo 2018-09-25 13:35:10 +02:00
parent fe745e2c03
commit 19c8f77d2f
2 changed files with 19 additions and 16 deletions

View File

@ -7,6 +7,8 @@ import { getAccountsFrom, getThresholdFrom, getNamesFrom, getSafeNameFrom, getDa
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { getGnosisSafeContract, deploySafeContract, initContracts } from '~/logic/contracts/safeContracts' import { getGnosisSafeContract, deploySafeContract, initContracts } from '~/logic/contracts/safeContracts'
import { checkReceiptStatus } from '~/logic/wallets/ethTransactions' import { checkReceiptStatus } from '~/logic/wallets/ethTransactions'
import { history } from '~/store'
import { OPENING_ADDRESS, stillInOpeningView, SAFELIST_ADDRESS } from '~/routes/routes'
import selector from './selector' import selector from './selector'
import actions, { type Actions, type AddSafe } from './actions' import actions, { type Actions, type AddSafe } from './actions'
import Layout from '../components/Layout' import Layout from '../components/Layout'
@ -18,7 +20,6 @@ type Props = Actions & {
export type OpenState = { export type OpenState = {
safeAddress: string, safeAddress: string,
safeTx: string,
} }
export const createSafe = async (values: Object, userAccount: string, addSafe: AddSafe): Promise<OpenState> => { export const createSafe = async (values: Object, userAccount: string, addSafe: AddSafe): Promise<OpenState> => {
@ -40,24 +41,21 @@ export const createSafe = async (values: Object, userAccount: string, addSafe: A
addSafe(name, safeContract.address, numConfirmations, dailyLimit, owners, accounts) addSafe(name, safeContract.address, numConfirmations, dailyLimit, owners, accounts)
if (stillInOpeningView()) {
const url = `${SAFELIST_ADDRESS}/${safeContract.address}`
history.push(url)
}
// returning info for testing purposes, in app is fully async
return { safeAddress: safeContract.address, safeTx: safe } return { safeAddress: safeContract.address, safeTx: safe }
} }
class Open extends React.Component<Props, OpenState> { class Open extends React.Component<Props> {
constructor() {
super()
this.state = {
safeAddress: '',
safeTx: '',
}
}
onCallSafeContractSubmit = async (values) => { onCallSafeContractSubmit = async (values) => {
try { try {
const { userAccount, addSafe } = this.props const { userAccount, addSafe } = this.props
const safeInstance = await createSafe(values, userAccount, addSafe) createSafe(values, userAccount, addSafe)
this.setState(safeInstance) history.push(OPENING_ADDRESS)
} catch (error) { } catch (error) {
// eslint-disable-next-line // eslint-disable-next-line
console.log('Error while creating the Safe' + error) console.log('Error while creating the Safe' + error)
@ -65,7 +63,6 @@ class Open extends React.Component<Props, OpenState> {
} }
render() { render() {
const { safeAddress, safeTx } = this.state
const { provider, userAccount } = this.props const { provider, userAccount } = this.props
return ( return (
@ -73,8 +70,6 @@ class Open extends React.Component<Props, OpenState> {
<Layout <Layout
provider={provider} provider={provider}
userAccount={userAccount} userAccount={userAccount}
safeAddress={safeAddress}
safeTx={safeTx}
onCallSafeContractSubmit={this.onCallSafeContractSubmit} onCallSafeContractSubmit={this.onCallSafeContractSubmit}
/> />
</Page> </Page>

View File

@ -1,6 +1,14 @@
// @flow // @flow
import { history } from '~/store'
export const SAFE_PARAM_ADDRESS = 'address' export const SAFE_PARAM_ADDRESS = 'address'
export const SAFELIST_ADDRESS = '/safes' export const SAFELIST_ADDRESS = '/safes'
export const OPEN_ADDRESS = '/open' export const OPEN_ADDRESS = '/open'
export const WELCOME_ADDRESS = '/welcome' export const WELCOME_ADDRESS = '/welcome'
export const SETTINS_ADDRESS = '/settings' export const SETTINS_ADDRESS = '/settings'
export const OPENING_ADDRESS = '/opening'
export const stillInOpeningView = () => {
const path = history.location.pathname
return path === OPENING_ADDRESS
}