Browse Source

locale for number formatting and language derived from the system

master
NastiaS 7 years ago
parent
commit
0a64c95e84
  1. 8
      src/components/AccountPage/index.js
  2. 7
      src/components/DashboardPage/index.js
  3. 2
      src/components/base/FormattedVal/index.js
  4. 5
      src/reducers/settings.js

8
src/components/AccountPage/index.js

@ -16,7 +16,7 @@ import type { Account } from '@ledgerhq/live-common/lib/types'
import { MODAL_SEND, MODAL_RECEIVE, MODAL_SETTINGS_ACCOUNT } from 'config/constants' import { MODAL_SEND, MODAL_RECEIVE, MODAL_SETTINGS_ACCOUNT } from 'config/constants'
import type { T } from 'types/common' import type { T, Settings } from 'types/common'
import { darken } from 'styles/helpers' import { darken } from 'styles/helpers'
@ -57,6 +57,7 @@ const ButtonSettings = styled(Button).attrs({
const mapStateToProps = (state, props) => ({ const mapStateToProps = (state, props) => ({
account: getAccountById(state, props.match.params.id), account: getAccountById(state, props.match.params.id),
counterValue: getCounterValueCode(state), counterValue: getCounterValueCode(state),
settings: state.settings,
}) })
const mapDispatchToProps = { const mapDispatchToProps = {
@ -68,6 +69,7 @@ type Props = {
t: T, t: T,
account?: Account, account?: Account,
openModal: Function, openModal: Function,
settings: Settings,
} }
type State = { type State = {
@ -82,7 +84,7 @@ class AccountPage extends PureComponent<Props, State> {
} }
handleCalculateBalance = data => { handleCalculateBalance = data => {
const { counterValue, account } = this.props const { counterValue, account, settings } = this.props
if (!account) { if (!account) {
return return
@ -97,12 +99,14 @@ class AccountPage extends PureComponent<Props, State> {
balance: { balance: {
currency: formatCurrencyUnit(account.unit, account.balance, { currency: formatCurrencyUnit(account.unit, account.balance, {
showCode: true, showCode: true,
locale: settings.language,
}), }),
counterValue: formatCurrencyUnit( counterValue: formatCurrencyUnit(
getFiatCurrencyByTicker(counterValue).units[0], getFiatCurrencyByTicker(counterValue).units[0],
data.totalBalance, data.totalBalance,
{ {
showCode: true, showCode: true,
locale: settings.language,
}, },
), ),
}, },

7
src/components/DashboardPage/index.js

@ -15,7 +15,7 @@ import type { Account } from '@ledgerhq/live-common/lib/types'
import chunk from 'lodash/chunk' import chunk from 'lodash/chunk'
import type { T } from 'types/common' import type { T, Settings } from 'types/common'
import { colors } from 'styles/theme' import { colors } from 'styles/theme'
@ -39,6 +39,7 @@ const mapStateToProps = state => ({
username: state.settings.username, username: state.settings.username,
accounts: getVisibleAccounts(state), accounts: getVisibleAccounts(state),
counterValue: getCounterValueCode(state), counterValue: getCounterValueCode(state),
settings: state.settings,
}) })
const mapDispatchToProps = { const mapDispatchToProps = {
@ -53,6 +54,7 @@ type Props = {
push: Function, push: Function,
counterValue: string, counterValue: string,
username: string, username: string,
settings: Settings,
} }
type State = { type State = {
@ -88,7 +90,7 @@ class DashboardPage extends PureComponent<Props, State> {
} }
handleCalculateBalance = data => { handleCalculateBalance = data => {
const { counterValue } = this.props const { counterValue, settings } = this.props
if (process.platform === 'darwin' && this._cacheBalance !== data.totalBalance) { if (process.platform === 'darwin' && this._cacheBalance !== data.totalBalance) {
this._cacheBalance = data.totalBalance this._cacheBalance = data.totalBalance
@ -102,6 +104,7 @@ class DashboardPage extends PureComponent<Props, State> {
data.totalBalance, data.totalBalance,
{ {
showCode: true, showCode: true,
locale: settings.language,
}, },
), ),
}, },

2
src/components/base/FormattedVal/index.js

@ -98,11 +98,13 @@ export function FormattedVal(props: Props) {
if (withIcon && isNegative) { if (withIcon && isNegative) {
val *= -1 val *= -1
} }
const locale = settings ? settings.language : ''
text = formatCurrencyUnit(unit, val, { text = formatCurrencyUnit(unit, val, {
alwaysShowSign, alwaysShowSign,
disableRounding, disableRounding,
showCode, showCode,
locale,
}) })
} }

5
src/reducers/settings.js

@ -24,11 +24,14 @@ export type SettingsState = {
region: string, region: string,
} }
/* have to check if available for all OS */
const language = window.navigator.language.split('-')[0]
const defaultState: SettingsState = { const defaultState: SettingsState = {
hasCompletedOnboarding: false, hasCompletedOnboarding: false,
username: 'Anonymous', username: 'Anonymous',
counterValue: 'USD', counterValue: 'USD',
language: 'en', language,
orderAccounts: 'balance|asc', orderAccounts: 'balance|asc',
password: { password: {
isEnabled: false, isEnabled: false,

Loading…
Cancel
Save