Fix single default safe, fix redirect when initial route was other than /

This commit is contained in:
Mikhail Mikheev 2019-09-19 15:45:41 +04:00
parent b531ffd057
commit 35bc1c2b3d
6 changed files with 30 additions and 24 deletions

View File

@ -1,7 +1,9 @@
// @flow
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { connect } from 'react-redux'
import { Switch, Redirect, Route } from 'react-router-dom'
import {
Switch, Redirect, Route, withRouter,
} from 'react-router-dom'
import { defaultSafeSelector } from '~/routes/safeList/store/selectors'
import Loader from '~/components/Loader'
import Welcome from './welcome/container'
@ -28,11 +30,18 @@ const SAFE_ADDRESS = `${SAFELIST_ADDRESS}/:${SAFE_PARAM_ADDRESS}`
type RoutesProps = {
defaultSafe?: string,
location: Object,
}
const Routes = ({ defaultSafe }: RoutesProps) => {
const Routes = ({ defaultSafe, location }: RoutesProps) => {
const [isInitialLoad, setIniitialLoad] = useState<boolean>(true)
useEffect(() => {
if (location.pathname !== '/') {
setIniitialLoad(false)
}
}, [])
return (
<Switch>
<Route
@ -69,4 +78,4 @@ export default connect<Object, Object, ?Function, ?Object>(
// $FlowFixMe
(state) => ({ defaultSafe: defaultSafeSelector(state) }),
null,
)(Routes)
)(withRouter(Routes))

View File

@ -24,6 +24,7 @@ export const loadSafe = async (
) => {
const safeProps = await buildSafe(safeAddress, safeName)
safeProps.owners = owners
await addSafe(safeProps)
const storedSafes = (await loadFromStorage(SAFES_KEY)) || {}

View File

@ -1,5 +1,5 @@
// @flow
import { addSafe } from '~/routes/safe/store/actions/addSafe'
import addSafe from '~/routes/safe/store/actions/addSafe'
export type Actions = {
addSafe: Function,

View File

@ -3,8 +3,9 @@ import * as React from 'react'
import { connect } from 'react-redux'
import Page from '~/components/layout/Page'
import {
getAccountsFrom, getThresholdFrom, getNamesFrom, getSafeNameFrom,
getAccountsFrom, getThresholdFrom, getNamesFrom, getSafeNameFrom, getOwnersFrom,
} from '~/routes/open/utils/safeDataExtractor'
import { buildSafe } from '~/routes/safe/store/actions/fetchSafe'
import { getGnosisSafeInstanceAt, deploySafeContract, initContracts } from '~/logic/contracts/safeContracts'
import { checkReceiptStatus } from '~/logic/wallets/ethTransactions'
import { history } from '~/store'
@ -24,19 +25,22 @@ export type OpenState = {
}
export const createSafe = async (values: Object, userAccount: string, addSafe: AddSafe): Promise<OpenState> => {
const accounts = getAccountsFrom(values)
const ownerAddresses = getAccountsFrom(values)
const numConfirmations = getThresholdFrom(values)
const name = getSafeNameFrom(values)
const owners = getNamesFrom(values)
const ownersNames = getNamesFrom(values)
await initContracts()
const safe = await deploySafeContract(accounts, numConfirmations, userAccount)
const safe = await deploySafeContract(ownerAddresses, numConfirmations, userAccount)
await checkReceiptStatus(safe.tx)
const safeAddress = safe.logs[0].args.proxy
const safeContract = await getGnosisSafeInstanceAt(safeAddress)
const safeProps = await buildSafe(safeAddress, name)
const owners = getOwnersFrom(ownersNames, ownerAddresses.sort())
safeProps.owners = owners
addSafe(name, safeContract.address, numConfirmations, owners, accounts)
addSafe(safeProps)
if (stillInOpeningView()) {
const url = {

View File

@ -4,8 +4,8 @@ import { createAction } from 'redux-actions'
import type { Dispatch as ReduxDispatch, GetState } from 'redux'
import { type GlobalState } from '~/store'
import { safesListSelector } from '~/routes/safeList/store/selectors'
import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe'
import { makeOwner, type Owner } from '~/routes/safe/store/models/owner'
import { type Safe } from '~/routes/safe/store/models/safe'
import { makeOwner } from '~/routes/safe/store/models/owner'
import setDefaultSafe from '~/routes/safe/store/actions/setDefaultSafe'
export const ADD_SAFE = 'ADD_SAFE'
@ -24,25 +24,17 @@ export const addSafe = createAction<string, Function, ActionReturn>(ADD_SAFE, (s
safe,
}))
const saveSafe = (name: string, address: string, threshold: number, ownersName: string[], ownersAddress: string[]) => (
const saveSafe = (safe: Safe) => (
dispatch: ReduxDispatch<GlobalState>,
getState: GetState<GlobalState>,
) => {
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
const state = getState()
const safeList = safesListSelector(state)
const safe: Safe = SafeRecord({
name,
address,
threshold,
owners,
})
dispatch(addSafe(safe))
console.log(safeList.size)
if (safeList.size === 0) {
setDefaultSafe(address)
dispatch(setDefaultSafe(safe.address))
}
}

View File

@ -4,7 +4,7 @@ import { List, Map } from 'immutable'
import { type GlobalState } from '~/store/index'
import { makeOwner } from '~/routes/safe/store/models/owner'
import type { SafeProps } from '~/routes/safe/store/models/safe'
import { addSafe } from '~/routes/safe/store/actions/addSafe'
import addSafe from '~/routes/safe/store/actions/addSafe'
import { getOwners, getSafeName } from '~/logic/safe/utils'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'