Active tokens WIP, needs debugging: tokens get washed after safe update

This commit is contained in:
Mikhail Mikheev 2019-04-12 20:06:34 +04:00
parent 595731d192
commit 910382c5f2
4 changed files with 16 additions and 17 deletions

View File

@ -20,7 +20,7 @@ class SafeView extends React.Component<Props> {
} = this.props
fetchSafe(safeUrl)
loadActiveTokens(safeUrl)
// loadActiveTokens(safeUrl)
fetchTokenBalances(safe, activeTokens)
this.intervalId = setInterval(() => {
@ -38,7 +38,7 @@ class SafeView extends React.Component<Props> {
safeUrl, activeTokens, fetchSafe, fetchTokenBalances, safe,
} = this.props
fetchSafe(safeUrl)
fetchSafe(safeUrl, true)
fetchTokenBalances(safe, activeTokens)
}

View File

@ -8,6 +8,7 @@ import { addSafe } from '~/routes/safe/store/actions/addSafe'
import { getOwners, getSafeName } from '~/logic/safe/utils'
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
import updateSafe from '~/routes/safe/store/actions/updateSafe'
const buildOwnersFrom = (
safeOwners: string[],
@ -37,12 +38,16 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
return SafeRecord(safe)
}
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
export default (safeAddress: string, update: boolean = false) => async (dispatch: ReduxDispatch<GlobalState>) => {
try {
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
const safeRecord = await buildSafe(safeAddress, safeName)
return dispatch(addSafe(safeRecord))
const safe = await buildSafe(safeAddress, safeName)
console.log(safe.toJS())
if (update) {
dispatch(updateSafe(safe))
} else {
dispatch(addSafe(safe))
}
} catch (err) {
// eslint-disable-next-line
console.error('Error while updating safe information: ', err)

View File

@ -1,21 +1,15 @@
// @flow
import type { Dispatch as ReduxDispatch } from 'redux'
import { Map, List } from 'immutable'
import { List } from 'immutable'
import { BigNumber } from 'bignumber.js'
import { type GlobalState } from '~/store/index'
import { type Token } from '~/logic/tokens/store/model/token'
import { ETH_ADDRESS } from '~/logic/tokens/utils/tokenHelpers'
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
import SafeTokenRecord from '~/routes/safe/store/models/safeToken'
import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens'
import type { Safe } from '~/routes/safe/store/model/safe'
import type { Safe } from '~/routes/safe/store/models/safe'
import updateSafe from './updateSafe'
export const calculateBalanceOf = async (tokenAddress: string, safeAddress: string, decimals: number = 18) => {
if (tokenAddress === ETH_ADDRESS) {
const ethBalance = await getBalanceInEtherOf(safeAddress)
return ethBalance
}
const erc20Token = await getStandardTokenContract()
let balance = 0
@ -36,7 +30,7 @@ const fetchTokenBalances = (safe: Safe, tokens: List<Token>) => async (dispatch:
try {
const withBalances = await Promise.all(
tokens.map(async token => ({
tokens.map(async token => SafeTokenRecord({
address: token.address,
balance: await calculateBalanceOf(token.address, safe.address, token.decimals),
})),

View File

@ -61,7 +61,7 @@ export default handleActions<State, *>(
const safe = action.payload
const safeAddress = safe.address
return state.mergeIn(safeAddress, safe)
return state.mergeIn([safeAddress], safe)
},
[ADD_SAFE]: (state: State, action: ActionType<Function>): State => {
const { safe }: { safe: Safe } = action.payload