add eth balance to safe model

This commit is contained in:
Mikhail Mikheev 2019-04-11 20:10:52 +04:00
parent be295d1ef5
commit 5f142bcc75
2 changed files with 6 additions and 8 deletions

View File

@ -7,7 +7,7 @@ import SafeRecord, { type SafeProps } from '~/routes/safe/store/model/safe'
import updateSafe from '~/routes/safe/store/actions/updateSafe' import updateSafe from '~/routes/safe/store/actions/updateSafe'
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 } from '~/logic/wallets/getWeb3' import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
const buildOwnersFrom = ( const buildOwnersFrom = (
safeOwners: string[], safeOwners: string[],
@ -21,6 +21,7 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
const web3 = getWeb3() const web3 = getWeb3()
const SafeContract = await getGnosisSafeContract(web3) const SafeContract = await getGnosisSafeContract(web3)
const gnosisSafe = await SafeContract.at(safeAddress) const gnosisSafe = await SafeContract.at(safeAddress)
const ethBalance = await getBalanceInEtherOf(safeAddress)
const threshold = Number(await gnosisSafe.getThreshold()) const threshold = Number(await gnosisSafe.getThreshold())
const owners = List(buildOwnersFrom(await gnosisSafe.getOwners(), await getOwners(safeAddress))) const owners = List(buildOwnersFrom(await gnosisSafe.getOwners(), await getOwners(safeAddress)))
@ -30,6 +31,7 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
name: safeName, name: safeName,
threshold, threshold,
owners, owners,
ethBalance,
} }
return SafeRecord(safe) return SafeRecord(safe)

View File

@ -2,12 +2,12 @@
import { List, Record, Map } from 'immutable' import { List, Record, Map } from 'immutable'
import type { RecordFactory, RecordOf } from 'immutable' import type { RecordFactory, RecordOf } from 'immutable'
import type { Owner } from '~/routes/safe/store/model/owner' import type { Owner } from '~/routes/safe/store/model/owner'
import { ETH_ADDRESS } from '~/logic/tokens/utils/tokenHelpers'
export type SafeProps = { export type SafeProps = {
name: string, name: string,
address: string, address: string,
threshold: number, threshold: number,
ethBalance: string,
owners: List<Owner>, owners: List<Owner>,
tokens?: List<Object>, tokens?: List<Object>,
} }
@ -16,13 +16,9 @@ const SafeRecord: RecordFactory<SafeProps> = Record({
name: '', name: '',
address: '', address: '',
threshold: 0, threshold: 0,
ethBalance: 0,
owners: List([]), owners: List([]),
tokens: List([ tokens: List([]),
{
address: ETH_ADDRESS,
balance: '0',
},
]),
}) })
// Tokens is a list of currently enabled tokens for the safe with balances // Tokens is a list of currently enabled tokens for the safe with balances