From d2117638b8bd5004a05ad9c9beaa42ffee540e70 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Thu, 13 Jun 2019 14:54:46 -0400 Subject: [PATCH] add proper display per token --- src/components/base/CurrencySelect.jsx | 5 +++-- src/utils/conversions.js | 3 ++- src/utils/currencies.js | 14 ++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/base/CurrencySelect.jsx b/src/components/base/CurrencySelect.jsx index 4ea4299..676abdd 100644 --- a/src/components/base/CurrencySelect.jsx +++ b/src/components/base/CurrencySelect.jsx @@ -42,10 +42,11 @@ function CurrencySelect({ const latestAllowances = {} currencies.forEach(async c => { if (c.contract) { + const { humanReadibleFn } = c const amount = await c.contract.methods.balanceOf(account).call() const allowance = await getLpAllowance(c.contract) - latestBalances[c.value] = toEther(amount) - latestAllowances[c.value] = toEther(allowance) + latestBalances[c.value] = humanReadibleFn(amount) + latestAllowances[c.value] = humanReadibleFn(allowance) } else { latestBalances[c.value] = '0' latestAllowances[c.value] = '0' diff --git a/src/utils/conversions.js b/src/utils/conversions.js index 2340c0c..bf47220 100644 --- a/src/utils/conversions.js +++ b/src/utils/conversions.js @@ -1,4 +1,5 @@ /*global web3*/ -export const toEther = amount => web3.utils.fromWei(amount, 'ether') +export const toEther = (amount, scale = 'ether') => web3.utils.fromWei(amount, scale) export const toWei = (amount, scale = 'ether') => web3.utils.toWei(amount, scale) +export const compoundWhole = amount => (Number(amount) / (10**8)).toString() diff --git a/src/utils/currencies.js b/src/utils/currencies.js index c3afc3a..c90d363 100644 --- a/src/utils/currencies.js +++ b/src/utils/currencies.js @@ -3,6 +3,7 @@ import DAI from '../embarkArtifacts/contracts/DAI' import cDAI from '../embarkArtifacts/contracts/cDAI' import cETH from '../embarkArtifacts/contracts/cETH' import sntIco from 'cryptocurrency-icons/svg/color/snt.svg' +import { toEther, compoundWhole } from './conversions' export const TOKEN_ICON_API = 'https://raw.githubusercontent.com/TrustWallet/tokens/master/images' export const TOKEN_COIN_API = 'https://raw.githubusercontent.com/TrustWallet/tokens/master/coins' @@ -13,33 +14,38 @@ export const currencies = [ label: 'cETH', img: `${TOKEN_API}/0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5.png`, width: '5%', - contract: cETH + contract: cETH, + humanReadibleFn: compoundWhole, }, { value: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', label: 'Wrapped Ether', img: `${TOKEN_COIN_API}/60.png`, width: '5%', + humanReadibleFn: toEther, }, { value: SNT._address, label: 'SNT', img: sntIco, - contract: SNT + contract: SNT, + humanReadibleFn: toEther, }, { value: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', label: 'DAI', img: `${TOKEN_API}/0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359.png`, width: '5%', - contract: DAI + contract: DAI, + humanReadibleFn: toEther, }, { value: '0xf5dce57282a584d2746faf1593d3121fcac444dc', label: 'cDAI', img: `${TOKEN_API}/0xf5dce57282a584d2746faf1593d3121fcac444dc.png`, width: '5%', - contract: cDAI + contract: cDAI, + humanReadibleFn: compoundWhole, } ]