Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visual indicator when displaying a cached balance. #5854

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
"balance": {
"message": "Balance"
},
"balanceOutdated": {
"message": "Balance may be outdated"
},
"balances": {
"message": "Token balance(s)"
},
Expand Down
1 change: 1 addition & 0 deletions development/states/confirm-sig-requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"name": "Send Account 4"
}
},
"cachedBalances": {},
"unapprovedTxs": {},
"currentCurrency": "USD",
"conversionRate": 1200.88200327,
Expand Down
1 change: 1 addition & 0 deletions development/states/currency-localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"name": "Send Account 4"
}
},
"cachedBalances": {},
"unapprovedTxs": {},
"currentCurrency": "USD",
"conversionRate": 19855,
Expand Down
1 change: 1 addition & 0 deletions development/states/send-edit.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"name": "Send Account 4"
}
},
"cachedBalances": {},
"assetImages": {},
"unapprovedTxs": {},
"currentCurrency": "USD",
Expand Down
1 change: 1 addition & 0 deletions development/states/send-new-ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"name": "Send Account 4"
}
},
"cachedBalances": {},
"unapprovedTxs": {},
"currentCurrency": "USD",
"conversionRate": 1200.88200327,
Expand Down
1 change: 1 addition & 0 deletions development/states/tx-list-items.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"name": "Send Account 4"
}
},
"cachedBalances": {},
"currentCurrency": "USD",
"conversionRate": 1200.88200327,
"conversionDate": 1489013762,
Expand Down
1 change: 1 addition & 0 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"name": "Test Account 2"
}
},
"cachedBalances": {},
"unapprovedTxs": {
"8393540981007587": {
"id": 8393540981007587,
Expand Down
1 change: 1 addition & 0 deletions test/unit/ui/app/selectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Selectors', function () {
'address': '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
},
},
cachedBalances: {},
},
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ export default class CurrencyDisplay extends PureComponent {
value: PropTypes.string,
numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
hideLabel: PropTypes.bool,
hideTitle: PropTypes.bool,
}

render () {
const { className, displayValue, prefix, prefixComponent, style, suffix } = this.props
const { className, displayValue, prefix, prefixComponent, style, suffix, hideTitle } = this.props
const text = `${prefix || ''}${displayValue}`
const title = `${text} ${suffix}`

return (
<div
className={classnames('currency-display-component', className)}
style={style}
title={title}
title={!hideTitle && title || null}
>
{ prefixComponent}
{ prefixComponent }
<span className="currency-display-component__text">{ text }</span>
{
suffix && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { checksumAddress } from '../../../util'
import Identicon from '../../identicon'
import UserPreferencedCurrencyDisplay from '../../user-preferenced-currency-display'
import { PRIMARY, SECONDARY } from '../../../constants/common'
import Tooltip from '../../tooltip-v2'

export default class AccountListItem extends Component {

Expand All @@ -16,6 +18,7 @@ export default class AccountListItem extends Component {
displayBalance: PropTypes.bool,
handleClick: PropTypes.func,
icon: PropTypes.node,
balanceIsCached: PropTypes.bool,
};

static contextTypes = {
Expand All @@ -30,6 +33,7 @@ export default class AccountListItem extends Component {
displayBalance = true,
handleClick,
icon = null,
balanceIsCached,
} = this.props

const { name, address, balance } = account || {}
Expand Down Expand Up @@ -58,16 +62,34 @@ export default class AccountListItem extends Component {

{
displayBalance && (
<div className="account-list-item__account-balances">
<UserPreferencedCurrencyDisplay
type={PRIMARY}
value={balance}
/>
<UserPreferencedCurrencyDisplay
type={SECONDARY}
value={balance}
/>
</div>
<Tooltip
position="left"
title={this.context.t('balanceOutdated')}
disabled={!balanceIsCached}
style={{
left: '-20px !important',
}}
>
<div className={classnames('account-list-item__account-balances', {
'account-list-item__cached-balances': balanceIsCached,
})}>
<div className="account-list-item__primary-cached-container">
<UserPreferencedCurrencyDisplay
type={PRIMARY}
value={balance}
hideTitle={true}
/>
{
balanceIsCached ? <span className="account-list-item__cached-star">*</span> : null
}
</div>
<UserPreferencedCurrencyDisplay
type={SECONDARY}
value={balance}
hideTitle={true}
/>
</div>
</Tooltip>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
getCurrentCurrency,
getNativeCurrency,
} from '../send.selectors.js'
import {
isBalanceCached,
} from '../../../selectors'
import AccountListItem from './account-list-item.component'

export default connect(mapStateToProps)(AccountListItem)
Expand All @@ -13,5 +16,6 @@ function mapStateToProps (state) {
conversionRate: getConversionRate(state),
currentCurrency: getCurrentCurrency(state),
nativeCurrency: getNativeCurrency(state),
balanceIsCached: isBalanceCached(state),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('AccountListItem Component', function () {
{
type: 'PRIMARY',
value: 'mockBalance',
hideTitle: true,
}
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ proxyquire('../account-list-item.container.js', {
getCurrentCurrency: (s) => `mockCurrentCurrency:${s}`,
getNativeCurrency: (s) => `mockNativeCurrency:${s}`,
},
'../../../selectors.js': {
isBalanceCached: (s) => `mockBalanceIsCached:${s}`,
},
})

describe('account-list-item container', () => {
Expand All @@ -26,6 +29,7 @@ describe('account-list-item container', () => {
conversionRate: 'mockConversionRate:mockState',
currentCurrency: 'mockCurrentCurrency:mockState',
nativeCurrency: 'mockNativeCurrency:mockState',
balanceIsCached: 'mockBalanceIsCached:mockState',
})
})

Expand Down
1 change: 1 addition & 0 deletions ui/app/components/send/tests/send-selectors-test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
'name': 'Send Account 4',
},
},
'cachedBalances': {},
'currentBlockGasLimit': '0x4c1878',
'currentCurrency': 'USD',
'conversionRate': 1200.88200327,
Expand Down
6 changes: 5 additions & 1 deletion ui/app/components/tooltip-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class Tooltip extends PureComponent {
arrow: PropTypes.bool,
children: PropTypes.node,
containerClassName: PropTypes.string,
disabled: PropTypes.bool,
onHidden: PropTypes.func,
position: PropTypes.oneOf([
'top',
Expand All @@ -33,10 +34,11 @@ export default class Tooltip extends PureComponent {
title: PropTypes.string,
trigger: PropTypes.any,
wrapperClassName: PropTypes.string,
style: PropTypes.object,
}

render () {
const {arrow, children, containerClassName, position, size, title, trigger, onHidden, wrapperClassName } = this.props
const {arrow, children, containerClassName, disabled, position, size, title, trigger, onHidden, wrapperClassName, style } = this.props

if (!title) {
return (
Expand All @@ -50,13 +52,15 @@ export default class Tooltip extends PureComponent {
<div className={wrapperClassName}>
<ReactTippy
className={containerClassName}
disabled={disabled}
title={title}
position={position}
trigger={trigger}
hideOnClick={false}
size={size}
arrow={arrow}
onHidden={onHidden}
style={style}
>
{children}
</ReactTippy>
Expand Down
18 changes: 18 additions & 0 deletions ui/app/components/transaction-view-balance/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
display: flex;
flex-direction: column;
min-width: 0;
position: relative;

@media screen and (max-width: $break-small) {
align-items: center;
Expand All @@ -26,6 +27,10 @@
}
}

&__primary-container {
display: flex;
}

&__primary-balance {
font-size: 1.5rem;

Expand All @@ -35,6 +40,19 @@
}
}

&__cached-star {
margin-left: 4px;
}

&__cached-balance, &__cached-star {
color: $web-orange;
}

&__cached-secondary-balance {
color: rgba(220, 153, 18, 0.6901960784313725);
font-size: 1.15rem;
}

&__secondary-balance {
font-size: 1.15rem;
color: #a0a0a0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import Button from '../button'
import Identicon from '../identicon'
import TokenBalance from '../token-balance'
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
import { SEND_ROUTE } from '../../routes'
import { PRIMARY, SECONDARY } from '../../constants/common'
import Tooltip from '../tooltip-v2'

export default class TransactionViewBalance extends PureComponent {
static contextTypes = {
Expand All @@ -19,10 +21,11 @@ export default class TransactionViewBalance extends PureComponent {
network: PropTypes.string,
balance: PropTypes.string,
assetImage: PropTypes.string,
balanceIsCached: PropTypes.bool,
}

renderBalance () {
const { selectedToken, balance } = this.props
const { selectedToken, balance, balanceIsCached } = this.props

return selectedToken
? (
Expand All @@ -34,20 +37,34 @@ export default class TransactionViewBalance extends PureComponent {
/>
</div>
) : (
<div className="transaction-view-balance__balance">
<UserPreferencedCurrencyDisplay
className="transaction-view-balance__primary-balance"
value={balance}
type={PRIMARY}
ethNumberOfDecimals={4}
/>
<UserPreferencedCurrencyDisplay
className="transaction-view-balance__secondary-balance"
value={balance}
type={SECONDARY}
ethNumberOfDecimals={4}
/>
</div>
<Tooltip position="top" title={this.context.t('balanceOutdated')} disabled={!balanceIsCached}>
<div className="transaction-view-balance__balance">
<div className="transaction-view-balance__primary-container">
<UserPreferencedCurrencyDisplay
className={classnames('transaction-view-balance__primary-balance', {
'transaction-view-balance__cached-balance': balanceIsCached,
})}
value={balance}
type={PRIMARY}
ethNumberOfDecimals={4}
hideTitle={true}
/>
{
balanceIsCached ? <span className="transaction-view-balance__cached-star">*</span> : null
}
</div>
<UserPreferencedCurrencyDisplay
className={classnames({
'transaction-view-balance__cached-secondary-balance': balanceIsCached,
'transaction-view-balance__secondary-balance': !balanceIsCached,
})}
value={balance}
type={SECONDARY}
ethNumberOfDecimals={4}
hideTitle={true}
/>
</div>
</Tooltip>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getNativeCurrency,
getSelectedTokenAssetImage,
getMetaMaskAccounts,
isBalanceCached,
} from '../../selectors'
import { showModal } from '../../actions'

Expand All @@ -24,6 +25,7 @@ const mapStateToProps = state => {
balance,
nativeCurrency: getNativeCurrency(state),
assetImage: getSelectedTokenAssetImage(state),
balanceIsCached: isBalanceCached(state),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class UserPreferencedCurrencyDisplay extends PureComponent {
value: PropTypes.string,
numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
hideLabel: PropTypes.bool,
hideTitle: PropTypes.bool,
style: PropTypes.object,
showEthLogo: PropTypes.bool,
ethLogoHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
Expand Down
Loading