WA-234 fetch safe info regularly in safe view

This commit is contained in:
apanizo 2018-06-07 22:25:32 +02:00
parent aec0b50200
commit 2da7eab781
6 changed files with 61 additions and 42 deletions

View File

@ -1,13 +1,13 @@
// @flow
import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
import fetchBalance from '~/routes/safe/store/actions/fetchBalance'
import fetchDailyLimit from '~/routes/safe/store/actions/fetchDailyLimit'
export type Actions = {
fetchSafe: typeof fetchSafe,
fetchBalance: typeof fetchBalance,
fetchDailyLimit: typeof fetchDailyLimit,
}
export default {
fetchSafe,
fetchBalance,
fetchDailyLimit,
}

View File

@ -14,17 +14,12 @@ type Props = Actions & SelectorProps & {
class SafeView extends React.PureComponent<Props> {
componentDidMount() {
this.intervalId = setInterval(() => {
const { safe, fetchBalance } = this.props
const { safe, fetchSafe, fetchBalance } = this.props
if (!safe) { return }
const safeAddress: string = safe.get('address')
fetchBalance(safeAddress)
fetchSafe(safe)
}, 1500)
const { fetchDailyLimit, safe } = this.props
if (safe) {
fetchDailyLimit(safe.get('address'))
}
}
componentWillUnmount() {

View File

@ -0,0 +1,42 @@
// @flow
import type { Dispatch as ReduxDispatch } from 'redux'
import { List } from 'immutable'
import { type GlobalState } from '~/store/index'
import { makeOwner } from '~/routes/safe/store/model/owner'
import { type SafeProps, type Safe, makeSafe } from '~/routes/safe/store/model/safe'
import { makeDailyLimit } from '~/routes/safe/store/model/dailyLimit'
import { getDailyLimitFrom } from '~/routes/safe/component/Withdrawn/withdrawn'
import { getGnosisSafeInstanceAt } from '~/wallets/safeContracts'
import updateSafe from '~/routes/safe/store/actions/updateSafe'
const buildOwnersFrom = (safeOwners: string[], storedOwners: Object[]) => (
safeOwners.map((ownerAddress: string) => {
const foundOwner = storedOwners.find(owner => owner.address === ownerAddress)
return makeOwner(foundOwner || { name: 'UNKNOWN', address: ownerAddress })
})
)
export const buildSafe = async (storedSafe: Object) => {
const safeAddress = storedSafe.address
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const dailyLimit = makeDailyLimit(await getDailyLimitFrom(safeAddress, 0))
const threshold = Number(await gnosisSafe.getThreshold())
const owners = List(buildOwnersFrom(await gnosisSafe.getOwners(), storedSafe.owners))
const safe: SafeProps = {
address: safeAddress,
dailyLimit,
name: storedSafe.name,
threshold,
owners,
}
return makeSafe(safe)
}
export default (safe: Safe) => async (dispatch: ReduxDispatch<GlobalState>) => {
const safeRecord = await buildSafe(safe.toJSON())
return dispatch(updateSafe(safeRecord))
}

View File

@ -1,40 +1,11 @@
// @flow
import type { Dispatch as ReduxDispatch } from 'redux'
import { List, Map } from 'immutable'
import { Map } from 'immutable'
import { type GlobalState } from '~/store/index'
import { makeOwner } from '~/routes/safe/store/model/owner'
import { type SafeProps, type Safe, makeSafe } from '~/routes/safe/store/model/safe'
import { makeDailyLimit } from '~/routes/safe/store/model/dailyLimit'
import { getDailyLimitFrom } from '~/routes/safe/component/Withdrawn/withdrawn'
import { getGnosisSafeInstanceAt } from '~/wallets/safeContracts'
import { load, SAFES_KEY } from '~/utils/localStorage'
import updateSafes from '~/routes/safe/store/actions/updateSafes'
const buildOwnersFrom = (safeOwners: string[], storedOwners: Object[]) => (
safeOwners.map((ownerAddress: string) => {
const foundOwner = storedOwners.find(owner => owner.address === ownerAddress)
return makeOwner(foundOwner || { name: 'UNKNOWN', address: ownerAddress })
})
)
const buildSafe = async (storedSafe: Object) => {
const safeAddress = storedSafe.address
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const dailyLimit = makeDailyLimit(await getDailyLimitFrom(safeAddress, 0))
const threshold = Number(await gnosisSafe.getThreshold())
const owners = List(buildOwnersFrom(await gnosisSafe.getOwners(), storedSafe.owners))
const safe: SafeProps = {
address: safeAddress,
dailyLimit,
name: storedSafe.name,
threshold,
owners,
}
return makeSafe(safe)
}
import { buildSafe } from '~/routes/safe/store/actions/fetchSafe'
import { type Safe } from '~/routes/safe/store/model/safe'
const buildSafesFrom = async (loadedSafes: Object): Promise<Map<string, Safe>> => {
const safes = Map()

View File

@ -0,0 +1,8 @@
// @flow
import { createAction } from 'redux-actions'
export const UPDATE_SAFE = 'UPDATE_SAFE'
const updateSafe = createAction(UPDATE_SAFE)
export default updateSafe

View File

@ -8,6 +8,7 @@ import { saveSafes } from '~/utils/localStorage'
import { makeDailyLimit } from '~/routes/safe/store/model/dailyLimit'
import updateThreshold, { UPDATE_THRESHOLD } from '~/routes/safe/store/actions/updateThreshold'
import updateSafes, { UPDATE_SAFES } from '~/routes/safe/store/actions/updateSafes'
import updateSafe, { UPDATE_SAFE } from '~/routes/safe/store/actions/updateSafe'
export const SAFE_REDUCER_ID = 'safes'
@ -25,6 +26,8 @@ action: AddSafeType
*/
export default handleActions({
[UPDATE_SAFE]: (state: State, action: ActionType<typeof updateSafe>): State =>
state.set(action.payload.get('address'), action.payload),
[UPDATE_SAFES]: (state: State, action: ActionType<typeof updateSafes>): State =>
action.payload,
[ADD_SAFE]: (state: State, action: ActionType<typeof addSafe>): State => {