1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Nearly finished factoring fiat value into eth-balance

This commit is contained in:
Dan Finlay 2016-09-06 16:45:06 -07:00
parent 58a8f02294
commit 09dd854a96
9 changed files with 19 additions and 109 deletions

View File

@ -10,7 +10,7 @@ const ReactCSSTransitionGroup = require('react-addons-css-transition-group')
const valuesFor = require('./util').valuesFor const valuesFor = require('./util').valuesFor
const Identicon = require('./components/identicon') const Identicon = require('./components/identicon')
const AccountEtherBalance = require('./components/account-eth-balance') const EthBalance = require('./components/eth-balance')
const TransactionList = require('./components/transaction-list') const TransactionList = require('./components/transaction-list')
const ExportAccountView = require('./components/account-export') const ExportAccountView = require('./components/account-export')
const ethUtil = require('ethereumjs-util') const ethUtil = require('ethereumjs-util')
@ -168,7 +168,7 @@ AccountDetailScreen.prototype.render = function () {
}, },
}, [ }, [
h(AccountEtherBalance, { h(EthBalance, {
value: account && account.balance, value: account && account.balance,
style: { style: {
lineHeight: '7px', lineHeight: '7px',

View File

@ -3,7 +3,7 @@ const h = require('react-hyperscript')
const inherits = require('util').inherits const inherits = require('util').inherits
const ethUtil = require('ethereumjs-util') const ethUtil = require('ethereumjs-util')
const AccountEtherBalance = require('../components/account-eth-balance') const EthBalance = require('../components/eth-balance')
const CopyButton = require('../components/copyButton') const CopyButton = require('../components/copyButton')
const Identicon = require('../components/identicon') const Identicon = require('../components/identicon')
@ -50,7 +50,7 @@ NewComponent.prototype.render = function () {
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
}, },
}, ethUtil.toChecksumAddress(identity.address)), }, ethUtil.toChecksumAddress(identity.address)),
h(AccountEtherBalance, { h(EthBalance, {
value: account.balance, value: account.balance,
style: { style: {
lineHeight: '7px', lineHeight: '7px',

View File

@ -245,7 +245,7 @@ App.prototype.renderNetworkDropdown = function () {
label: 'Localhost 8545', label: 'Localhost 8545',
closeMenu: () => this.setState({ isNetworkMenuOpen: false }), closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
action: () => props.dispatch(actions.setRpcTarget('http://localhost:8545')), action: () => props.dispatch(actions.setRpcTarget('http://localhost:8545')),
icon: h('i.fa.fa-question-circle.fa-lg', { ariaHidden: true }), icon: h('i.fa.fa-question-circle.fa-lg'),
activeNetworkRender: props.provider.rpcTarget, activeNetworkRender: props.provider.rpcTarget,
}), }),
@ -253,7 +253,7 @@ App.prototype.renderNetworkDropdown = function () {
label: 'Custom RPC', label: 'Custom RPC',
closeMenu: () => this.setState({ isNetworkMenuOpen: false }), closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
action: () => this.props.dispatch(actions.showConfigPage()), action: () => this.props.dispatch(actions.showConfigPage()),
icon: h('i.fa.fa-question-circle.fa-lg', { ariaHidden: true }), icon: h('i.fa.fa-question-circle.fa-lg'),
}), }),
this.renderCustomOption(props.provider.rpcTarget), this.renderCustomOption(props.provider.rpcTarget),
@ -289,21 +289,21 @@ App.prototype.renderDropdown = function () {
label: 'Settings', label: 'Settings',
closeMenu: () => this.setState({ isMainMenuOpen: !isOpen }), closeMenu: () => this.setState({ isMainMenuOpen: !isOpen }),
action: () => this.props.dispatch(actions.showConfigPage()), action: () => this.props.dispatch(actions.showConfigPage()),
icon: h('i.fa.fa-gear.fa-lg', { ariaHidden: true }), icon: h('i.fa.fa-gear.fa-lg'),
}), }),
h(DropMenuItem, { h(DropMenuItem, {
label: 'Lock', label: 'Lock',
closeMenu: () => this.setState({ isMainMenuOpen: !isOpen }), closeMenu: () => this.setState({ isMainMenuOpen: !isOpen }),
action: () => this.props.dispatch(actions.lockMetamask()), action: () => this.props.dispatch(actions.lockMetamask()),
icon: h('i.fa.fa-lock.fa-lg', { ariaHidden: true }), icon: h('i.fa.fa-lock.fa-lg'),
}), }),
h(DropMenuItem, { h(DropMenuItem, {
label: 'Help', label: 'Help',
closeMenu: () => this.setState({ isMainMenuOpen: !isOpen }), closeMenu: () => this.setState({ isMainMenuOpen: !isOpen }),
action: () => this.props.dispatch(actions.showInfoPage()), action: () => this.props.dispatch(actions.showInfoPage()),
icon: h('i.fa.fa-question.fa-lg', { ariaHidden: true }), icon: h('i.fa.fa-question.fa-lg'),
}), }),
]) ])
} }
@ -312,7 +312,6 @@ App.prototype.renderBackButton = function (style, justArrow = false) {
return ( return (
h('.flex-row', { h('.flex-row', {
key: 'leftArrow', key: 'leftArrow',
transForward: false,
style: style, style: style,
onClick: () => props.dispatch(actions.goBackToInitView()), onClick: () => props.dispatch(actions.goBackToInitView()),
}, [ }, [
@ -515,14 +514,14 @@ App.prototype.renderCustomOption = function (rpcTarget) {
label: 'Custom RPC', label: 'Custom RPC',
closeMenu: () => this.setState({ isNetworkMenuOpen: false }), closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
action: () => this.props.dispatch(actions.showConfigPage()), action: () => this.props.dispatch(actions.showConfigPage()),
icon: h('i.fa.fa-question-circle.fa-lg', { ariaHidden: true }), icon: h('i.fa.fa-question-circle.fa-lg'),
}) })
default: default:
return h(DropMenuItem, { return h(DropMenuItem, {
label: `${rpcTarget}`, label: `${rpcTarget}`,
closeMenu: () => this.setState({ isNetworkMenuOpen: false }), closeMenu: () => this.setState({ isNetworkMenuOpen: false }),
icon: h('i.fa.fa-question-circle.fa-lg', { ariaHidden: true }), icon: h('i.fa.fa-question-circle.fa-lg'),
activeNetworkRender: 'custom', activeNetworkRender: 'custom',
}) })
} }

View File

@ -1,89 +0,0 @@
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const formatBalance = require('../util').formatBalance
const generateBalanceObject = require('../util').generateBalanceObject
const Tooltip = require('./tooltip.js')
const FiatValue = require('./fiat-value')
module.exports = EthBalanceComponent
inherits(EthBalanceComponent, Component)
function EthBalanceComponent () {
Component.call(this)
}
EthBalanceComponent.prototype.render = function () {
var props = this.props
var style = props.style
var width = props.width
return (
h('.ether-balance', {
style: style,
}, [
h('.ether-balance-amount', {
style: {
display: 'inline',
width: width,
},
}, this.renderBalance()),
])
)
}
EthBalanceComponent.prototype.renderBalance = function () {
const props = this.props
const value = formatBalance(props.value, 6)
if (value === 'None') return value
var balanceObj = generateBalanceObject(value, props.shorten ? 1 : 3)
var balance
var splitBalance = value.split(' ')
var ethNumber = splitBalance[0]
var ethSuffix = splitBalance[1]
if (props.shorten) {
balance = balanceObj.shortBalance
} else {
balance = balanceObj.balance
}
var label = balanceObj.label
return (
h('.flex-column', [
h(Tooltip, {
position: 'bottom',
title: `${ethNumber} ${ethSuffix}`,
}, [
h('.flex-row', {
style: {
alignItems: 'flex-end',
lineHeight: '13px',
fontFamily: 'Montserrat Light',
textRendering: 'geometricPrecision',
marginBottom: '5px',
},
}, [
h('div', {
style: {
width: '100%',
textAlign: 'right',
},
}, balance),
h('div', {
style: {
color: '#AEAEAE',
marginLeft: '5px',
},
}, label),
]),
]),
h(FiatValue, { value: props.value }),
])
)
}

View File

@ -19,7 +19,6 @@ EthBalanceComponent.prototype.render = function () {
var needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true var needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true
const value = formatBalance(props.value, 6, needsParse) const value = formatBalance(props.value, 6, needsParse)
var width = props.width var width = props.width
const showFiat = 'showFiat' in props ? props.showFiat : true
return ( return (
@ -44,6 +43,7 @@ EthBalanceComponent.prototype.renderBalance = function (value) {
var splitBalance = value.split(' ') var splitBalance = value.split(' ')
var ethNumber = splitBalance[0] var ethNumber = splitBalance[0]
var ethSuffix = splitBalance[1] var ethSuffix = splitBalance[1]
const showFiat = 'showFiat' in props ? props.showFiat : true
if (props.shorten) { if (props.shorten) {
balance = balanceObj.shortBalance balance = balanceObj.shortBalance
@ -80,7 +80,7 @@ EthBalanceComponent.prototype.renderBalance = function (value) {
}, label), }, label),
]), ]),
fiatValue ? h(FiatValue, { value: props.value }) : null, showFiat ? h(FiatValue, { value: props.value }) : null,
]) ])
) )
} }

View File

@ -4,7 +4,7 @@ const inherits = require('util').inherits
const connect = require('react-redux').connect const connect = require('react-redux').connect
const formatBalance = require('../util').formatBalance const formatBalance = require('../util').formatBalance
const generateBalanceObject = require('../util').generateBalanceObject const generateBalanceObject = require('../util').generateBalanceObject
const Tooltip = require('./tooltip.js') const Tooltip = require('./tooltip')
module.exports = connect(mapStateToProps)(FiatValue) module.exports = connect(mapStateToProps)(FiatValue)
@ -25,7 +25,6 @@ FiatValue.prototype.render = function () {
const value = formatBalance(props.value, 6) const value = formatBalance(props.value, 6)
if (value === 'None') return value if (value === 'None') return value
var balanceObj = generateBalanceObject(value, props.shorten ? 1 : 3)
var fiatDisplayNumber, fiatTooltipNumber var fiatDisplayNumber, fiatTooltipNumber
var splitBalance = value.split(' ') var splitBalance = value.split(' ')

View File

@ -75,7 +75,6 @@ Network.prototype.render = function () {
default: default:
return h('.network-indicator', [ return h('.network-indicator', [
h('i.fa.fa-question-circle.fa-lg', { h('i.fa.fa-question-circle.fa-lg', {
ariaHidden: true,
style: { style: {
margin: '10px', margin: '10px',
color: 'rgb(125, 128, 130)', color: 'rgb(125, 128, 130)',

View File

@ -12,11 +12,12 @@ function Tooltip () {
Tooltip.prototype.render = function () { Tooltip.prototype.render = function () {
const props = this.props const props = this.props
const { position, title, children } = props
return h(ReactTooltip, { return h(ReactTooltip, {
position: props.position ? props.position : 'left', position: position || 'left',
title: props.title, title,
fixed: false, fixed: false,
}, props.children) }, children)
} }

View File

@ -77,6 +77,7 @@ TransactionListItem.prototype.render = function () {
value: txParams.value, value: txParams.value,
width: '55px', width: '55px',
shorten: true, shorten: true,
showFiat: false,
style: {fontSize: '15px'}, style: {fontSize: '15px'},
}) : h('.flex-column'), }) : h('.flex-column'),
]) ])