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 } = this.props
fetchSafe(safeUrl) fetchSafe(safeUrl)
loadActiveTokens(safeUrl) // loadActiveTokens(safeUrl)
fetchTokenBalances(safe, activeTokens) fetchTokenBalances(safe, activeTokens)
this.intervalId = setInterval(() => { this.intervalId = setInterval(() => {
@ -38,7 +38,7 @@ class SafeView extends React.Component<Props> {
safeUrl, activeTokens, fetchSafe, fetchTokenBalances, safe, safeUrl, activeTokens, fetchSafe, fetchTokenBalances, safe,
} = this.props } = this.props
fetchSafe(safeUrl) fetchSafe(safeUrl, true)
fetchTokenBalances(safe, activeTokens) 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 { getOwners, getSafeName } from '~/logic/safe/utils'
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts' import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3' import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
import updateSafe from '~/routes/safe/store/actions/updateSafe'
const buildOwnersFrom = ( const buildOwnersFrom = (
safeOwners: string[], safeOwners: string[],
@ -37,12 +38,16 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
return SafeRecord(safe) return SafeRecord(safe)
} }
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => { export default (safeAddress: string, update: boolean = false) => async (dispatch: ReduxDispatch<GlobalState>) => {
try { try {
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE' const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
const safeRecord = await buildSafe(safeAddress, safeName) const safe = await buildSafe(safeAddress, safeName)
console.log(safe.toJS())
return dispatch(addSafe(safeRecord)) if (update) {
dispatch(updateSafe(safe))
} else {
dispatch(addSafe(safe))
}
} catch (err) { } catch (err) {
// eslint-disable-next-line // eslint-disable-next-line
console.error('Error while updating safe information: ', err) console.error('Error while updating safe information: ', err)

View File

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

View File

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