aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components
diff options
context:
space:
mode:
authorSimon Liang <simon@divby0.io>2017-08-08 16:49:45 +0800
committerSimon Liang <simon@divby0.io>2017-08-08 16:49:45 +0800
commite8ade42f2aa3af6e0091e939beef3fdf769a2606 (patch)
tree5b9aeb9df48cf218f9fde348fbb9bf9c99eadb11 /ui/app/components
parentd8fff0fc8c25d1bd0a287502ca633a44a7844911 (diff)
downloadtangerine-wallet-browser-e8ade42f2aa3af6e0091e939beef3fdf769a2606.tar
tangerine-wallet-browser-e8ade42f2aa3af6e0091e939beef3fdf769a2606.tar.gz
tangerine-wallet-browser-e8ade42f2aa3af6e0091e939beef3fdf769a2606.tar.bz2
tangerine-wallet-browser-e8ade42f2aa3af6e0091e939beef3fdf769a2606.tar.lz
tangerine-wallet-browser-e8ade42f2aa3af6e0091e939beef3fdf769a2606.tar.xz
tangerine-wallet-browser-e8ade42f2aa3af6e0091e939beef3fdf769a2606.tar.zst
tangerine-wallet-browser-e8ade42f2aa3af6e0091e939beef3fdf769a2606.zip
extracted balance component and renders to the format, also wired in the account name
Diffstat (limited to 'ui/app/components')
-rw-r--r--ui/app/components/balance-component.js89
-rw-r--r--ui/app/components/tx-view.js49
2 files changed, 115 insertions, 23 deletions
diff --git a/ui/app/components/balance-component.js b/ui/app/components/balance-component.js
new file mode 100644
index 000000000..62024895b
--- /dev/null
+++ b/ui/app/components/balance-component.js
@@ -0,0 +1,89 @@
+const Component = require('react').Component
+const h = require('react-hyperscript')
+const inherits = require('util').inherits
+
+const { formatBalance, generateBalanceObject } = require('../util')
+
+module.exports = BalanceComponent
+
+inherits(BalanceComponent, Component)
+function BalanceComponent () {
+ Component.call(this)
+}
+
+BalanceComponent.prototype.render = function () {
+ const props = this.props
+ const { balanceValue } = props
+ const needsParse = 'needsParse' in props ? props.needsParse : true
+ const formattedBalance = balanceValue ? formatBalance(balanceValue, 6, needsParse) : '...'
+
+ return h('div.balance-container', {}, [
+ // laptop: 50px 50px
+ // mobile: 100px 100px
+
+ // TODO: balance icon needs to be passed in
+ h('img.balance-icon', {
+ src: '../images/eth_logo.svg',
+ style: {},
+ }),
+
+ this.renderBalance(formattedBalance),
+ ])
+}
+
+BalanceComponent.prototype.renderBalance = function (formattedBalance) {
+ const props = this.props
+ const { shorten } = props
+ const showFiat = 'showFiat' in props ? props.showFiat : true
+
+ if (formattedBalance === 'None' || formattedBalance === '...') {
+ return h('div.flex-column.balance-display', {}, [
+ h('div.token-amount', {
+ style: {},
+ }, 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}`),
+
+ showFiat ? this.renderFiatValue(formattedBalance) : null,
+ ])
+}
+
+BalanceComponent.prototype.renderFiatValue = function (formattedBalance) {
+
+ const props = this.props
+ const { conversionRate, currentCurrency } = props
+
+ if (formattedBalance === 'None') return formattedBalance
+ var fiatDisplayNumber
+ var splitBalance = formattedBalance.split(' ')
+
+ if (conversionRate !== 0) {
+ fiatDisplayNumber = (Number(splitBalance[0]) * conversionRate).toFixed(2)
+ } else {
+ fiatDisplayNumber = 'N/A'
+ }
+
+ return fiatDisplay(fiatDisplayNumber, currentCurrency)
+}
+
+function fiatDisplay (fiatDisplayNumber, fiatSuffix) {
+ if (fiatDisplayNumber !== 'N/A') {
+ return h('div.fiat-amount', {
+ style: {},
+ }, `${fiatDisplayNumber} ${fiatSuffix}`)
+ } else {
+ return h('div')
+ }
+}
diff --git a/ui/app/components/tx-view.js b/ui/app/components/tx-view.js
index 97b9a89f4..d0337fcb1 100644
--- a/ui/app/components/tx-view.js
+++ b/ui/app/components/tx-view.js
@@ -1,11 +1,15 @@
const Component = require('react').Component
const connect = require('react-redux').connect
const h = require('react-hyperscript')
+const ethUtil = require('ethereumjs-util')
const inherits = require('util').inherits
const actions = require('../actions')
// slideout menu
const WalletView = require('./wallet-view')
+// balance component
+const BalanceComponent = require('./balance-component')
+
const Identicon = require('./identicon')
// const AccountDropdowns = require('./account-dropdowns').AccountDropdowns
// const Content = require('./wallet-content-display')
@@ -15,13 +19,18 @@ module.exports = connect(mapStateToProps, mapDispatchToProps)(TxView)
function mapStateToProps (state) {
return {
sidebarOpen: state.appState.sidebarOpen,
+ identities: state.metamask.identities,
+ accounts: state.metamask.accounts,
+ address: state.metamask.selectedAddress,
+ conversionRate: state.metamask.conversionRate,
+ currentCurrency: state.metamask.currentCurrency,
}
}
function mapDispatchToProps (dispatch) {
return {
- showSidebar: () => {dispatch(actions.showSidebar())},
- hideSidebar: () => {dispatch(actions.hideSidebar())},
+ showSidebar: () => { dispatch(actions.showSidebar()) },
+ hideSidebar: () => { dispatch(actions.hideSidebar()) },
}
}
@@ -40,7 +49,13 @@ function TxView () {
}
TxView.prototype.render = function () {
- const selected = '0x82df11beb942BEeeD58d466fCb0F0791365C7684' // TODO: remove fake address
+
+ var props = this.props
+ var selected = props.address || Object.keys(props.accounts)[0]
+ var checksumAddress = selected && ethUtil.toChecksumAddress(selected)
+ var identity = props.identities[selected]
+ var account = props.accounts[selected]
+ const { conversionRate, currentCurrency } = props
return h('div.tx-view.flex-column', {
style: {},
@@ -62,7 +77,7 @@ TxView.prototype.render = function () {
},
}, []),
- //account display
+ // account display
h('.identicon-wrapper.select-none', {
style: {
marginLeft: '0.9em',
@@ -75,9 +90,9 @@ TxView.prototype.render = function () {
]),
h('span.account-name', {
- style: {}
+ style: {},
}, [
- 'Account 1'
+ identity.name,
]),
]),
@@ -88,25 +103,13 @@ TxView.prototype.render = function () {
style: {},
}, [
- // laptop: 50px 50px
- // mobile: 100px 100px
- h('img.hero-balance-icon', {
- src: '../images/eth_logo.svg',
- style: {}
+ h(BalanceComponent, {
+ balanceValue: account && account.balance,
+ conversionRate,
+ currentCurrency,
+ style: {},
}),
- // laptop: 5vw?
- // phone: 50vw?
- h('div.flex-column.hero-balance-display', {}, [
- h('div.token-amount', {
- style: {}
- }, '1001.124 ETH'),
-
- h('div.fiat-amount', {
- style: {}
- }, '$300,000 USD'),
- ]),
-
// laptop: 10vw?
// phone: 75vw?
h('div.flex-row.flex-center.hero-balance-buttons', {