fix token balance calculation rounding issue by using bignumber not from web3

This commit is contained in:
Mikhail Mikheev 2019-03-26 17:14:52 +04:00
parent a302742e27
commit 0e97f41c54
1 changed files with 2 additions and 15 deletions

View File

@ -1,6 +1,7 @@
// @flow
import { List, Map } from 'immutable'
import contract from 'truffle-contract'
import { BigNumber } from 'bignumber.js'
import type { Dispatch as ReduxDispatch } from 'redux'
import StandardToken from '@gnosis.pm/util-contracts/build/contracts/GnosisStandardToken.json'
import HumanFriendlyToken from '@gnosis.pm/util-contracts/build/contracts/HumanFriendlyToken.json'
@ -35,7 +36,6 @@ export const getStandardTokenContract = ensureOnce(createStandardTokenContract)
export const calculateBalanceOf = async (tokenAddress: string, address: string, decimals: number) => {
const erc20Token = await getStandardTokenContract()
const web3 = getWeb3()
let balance = 0
try {
@ -45,20 +45,7 @@ export const calculateBalanceOf = async (tokenAddress: string, address: string,
console.error('Failed to fetch token balances: ', err)
}
console.log(
tokenAddress,
balance.toString(),
10 ** decimals,
web3.utils
.toBN(balance)
.div(web3.utils.toBN(10).pow(web3.utils.toBN(decimals)))
.toString(),
)
return web3.utils
.toBN(balance)
.div(web3.utils.toBN(10).pow(web3.utils.toBN(decimals)))
.toString()
return new BigNumber(balance).div(10 ** decimals).toString()
}
export const fetchTokensData = async () => {