aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/balance-component.js
diff options
context:
space:
mode:
authorSimon Liang <simon@divby0.io>2017-08-08 20:15:30 +0800
committerSimon Liang <simon@divby0.io>2017-08-08 20:15:30 +0800
commit0db627d9793d91e2e3000a0650f6659a5d5dd67a (patch)
treebdf211f961e515e5a1d0b8f3260b7cdf44b3fcfa /ui/app/components/balance-component.js
parente8ade42f2aa3af6e0091e939beef3fdf769a2606 (diff)
downloadtangerine-wallet-browser-0db627d9793d91e2e3000a0650f6659a5d5dd67a.tar
tangerine-wallet-browser-0db627d9793d91e2e3000a0650f6659a5d5dd67a.tar.gz
tangerine-wallet-browser-0db627d9793d91e2e3000a0650f6659a5d5dd67a.tar.bz2
tangerine-wallet-browser-0db627d9793d91e2e3000a0650f6659a5d5dd67a.tar.lz
tangerine-wallet-browser-0db627d9793d91e2e3000a0650f6659a5d5dd67a.tar.xz
tangerine-wallet-browser-0db627d9793d91e2e3000a0650f6659a5d5dd67a.tar.zst
tangerine-wallet-browser-0db627d9793d91e2e3000a0650f6659a5d5dd67a.zip
refactored and added unit test
Diffstat (limited to 'ui/app/components/balance-component.js')
-rw-r--r--ui/app/components/balance-component.js49
1 files changed, 26 insertions, 23 deletions
diff --git a/ui/app/components/balance-component.js b/ui/app/components/balance-component.js
index 62024895b..47da24c74 100644
--- a/ui/app/components/balance-component.js
+++ b/ui/app/components/balance-component.js
@@ -44,17 +44,12 @@ BalanceComponent.prototype.renderBalance = function (formattedBalance) {
])
}
- var balanceObj = generateBalanceObject(formattedBalance, shorten ? 1 : 3)
- var balanceValue = shorten ? balanceObj.shortBalance : balanceObj.balance
-
- var label = balanceObj.label
-
// laptop: 5vw?
// phone: 50vw?
return h('div.flex-column.balance-display', {}, [
h('div.token-amount', {
style: {},
- }, `${balanceValue} ${label}`),
+ }, this.getTokenBalance(formattedBalance, shorten)),
showFiat ? this.renderFiatValue(formattedBalance) : null,
])
@@ -65,25 +60,33 @@ BalanceComponent.prototype.renderFiatValue = function (formattedBalance) {
const props = this.props
const { conversionRate, currentCurrency } = props
- if (formattedBalance === 'None') return formattedBalance
- var fiatDisplayNumber
- var splitBalance = formattedBalance.split(' ')
+ const fiatDisplayNumber = this.getFiatDisplayNumber(formattedBalance, conversionRate)
- if (conversionRate !== 0) {
- fiatDisplayNumber = (Number(splitBalance[0]) * conversionRate).toFixed(2)
- } else {
- fiatDisplayNumber = 'N/A'
- }
+ return this.renderFiatAmount(fiatDisplayNumber, currentCurrency)
+}
+
+BalanceComponent.prototype.renderFiatAmount = function (fiatDisplayNumber, fiatSuffix) {
+ if (fiatDisplayNumber === 'N/A') return null
- return fiatDisplay(fiatDisplayNumber, currentCurrency)
+ return h('div.fiat-amount', {
+ style: {},
+ }, `${fiatDisplayNumber} ${fiatSuffix}`)
}
-function fiatDisplay (fiatDisplayNumber, fiatSuffix) {
- if (fiatDisplayNumber !== 'N/A') {
- return h('div.fiat-amount', {
- style: {},
- }, `${fiatDisplayNumber} ${fiatSuffix}`)
- } else {
- return h('div')
- }
+BalanceComponent.prototype.getTokenBalance = function (formattedBalance, shorten) {
+ const balanceObj = generateBalanceObject(formattedBalance, shorten ? 1 : 3)
+
+ const balanceValue = shorten ? balanceObj.shortBalance : balanceObj.balance
+ const label = balanceObj.label
+
+ return `${balanceValue} ${label}`
+}
+
+BalanceComponent.prototype.getFiatDisplayNumber = function (formattedBalance, conversionRate) {
+ if (formattedBalance === 'None') return formattedBalance
+ if (conversionRate === 0) return 'N/A'
+
+ const splitBalance = formattedBalance.split(' ')
+
+ return (Number(splitBalance[0]) * conversionRate).toFixed(2)
}