mirror of
https://github.com/trezor/trezor-wallet
synced 2025-01-08 07:01:04 +00:00
react intl suppor for account balance
This commit is contained in:
parent
a44a0b608a
commit
f35492ae6c
@ -1,12 +1,13 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage, FormattedNumber } from 'react-intl';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import colors from 'config/colors';
|
import colors from 'config/colors';
|
||||||
import ICONS from 'config/icons';
|
import ICONS from 'config/icons';
|
||||||
import Tooltip from 'components/Tooltip';
|
import Tooltip from 'components/Tooltip';
|
||||||
|
import { toFiatCurrency } from 'utils/fiatConverter';
|
||||||
import { FONT_SIZE, FONT_WEIGHT } from 'config/variables';
|
import { FONT_SIZE, FONT_WEIGHT } from 'config/variables';
|
||||||
import type { Network, State as ReducersState } from 'flowtype';
|
import type { Network, State as ReducersState } from 'flowtype';
|
||||||
import l10nMessages from './index.messages';
|
import l10nMessages from './index.messages';
|
||||||
@ -121,13 +122,11 @@ class AccountBalance extends PureComponent<Props, State> {
|
|||||||
render() {
|
render() {
|
||||||
const { network, localCurrency } = this.props;
|
const { network, localCurrency } = this.props;
|
||||||
const fiatRate = this.props.fiat.find(f => f.network === network.shortcut);
|
const fiatRate = this.props.fiat.find(f => f.network === network.shortcut);
|
||||||
let accountBalance = '';
|
|
||||||
let fiatRateValue = '';
|
let fiatRateValue = '';
|
||||||
let fiat = '';
|
let fiat = '';
|
||||||
if (fiatRate) {
|
if (fiatRate) {
|
||||||
accountBalance = new BigNumber(this.props.balance);
|
|
||||||
fiatRateValue = new BigNumber(fiatRate.rates[localCurrency]).toFixed(2);
|
fiatRateValue = new BigNumber(fiatRate.rates[localCurrency]).toFixed(2);
|
||||||
fiat = accountBalance.times(fiatRateValue).toFixed(2);
|
fiat = toFiatCurrency(this.props.balance, localCurrency, fiatRate.rates);
|
||||||
}
|
}
|
||||||
|
|
||||||
const NoRatesTooltip = (
|
const NoRatesTooltip = (
|
||||||
@ -159,7 +158,17 @@ class AccountBalance extends PureComponent<Props, State> {
|
|||||||
</Label>
|
</Label>
|
||||||
<TooltipWrapper>
|
<TooltipWrapper>
|
||||||
<FiatValue>
|
<FiatValue>
|
||||||
{fiatRate ? `${fiat} ${localCurrency}` : 'N/A'}
|
{fiatRate ? (
|
||||||
|
<FormattedNumber
|
||||||
|
currency={localCurrency}
|
||||||
|
value={fiat}
|
||||||
|
minimumFractionDigits={2}
|
||||||
|
// eslint-disable-next-line react/style-prop-object
|
||||||
|
style="currency"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
'N/A'
|
||||||
|
)}
|
||||||
</FiatValue>
|
</FiatValue>
|
||||||
{!fiatRate && NoRatesTooltip}
|
{!fiatRate && NoRatesTooltip}
|
||||||
</TooltipWrapper>
|
</TooltipWrapper>
|
||||||
@ -173,7 +182,17 @@ class AccountBalance extends PureComponent<Props, State> {
|
|||||||
</Label>
|
</Label>
|
||||||
<TooltipWrapper>
|
<TooltipWrapper>
|
||||||
<FiatValueRate>
|
<FiatValueRate>
|
||||||
{fiatRate ? `${fiatRateValue} ${localCurrency}` : 'N/A'}
|
{fiatRate ? (
|
||||||
|
<FormattedNumber
|
||||||
|
currency={localCurrency}
|
||||||
|
value={fiatRateValue}
|
||||||
|
minimumFractionDigits={2}
|
||||||
|
// eslint-disable-next-line react/style-prop-object
|
||||||
|
style="currency"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
'N/A'
|
||||||
|
)}
|
||||||
</FiatValueRate>
|
</FiatValueRate>
|
||||||
{!fiatRate && NoRatesTooltip}
|
{!fiatRate && NoRatesTooltip}
|
||||||
</TooltipWrapper>
|
</TooltipWrapper>
|
||||||
|
Loading…
Reference in New Issue
Block a user