From 0a64c95e845f0ec33cdaab2d4924ebf55fa06cbe Mon Sep 17 00:00:00 2001 From: NastiaS Date: Wed, 2 May 2018 14:36:52 +0200 Subject: [PATCH] locale for number formatting and language derived from the system --- src/components/AccountPage/index.js | 8 ++++++-- src/components/DashboardPage/index.js | 7 +++++-- src/components/base/FormattedVal/index.js | 2 ++ src/reducers/settings.js | 5 ++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/AccountPage/index.js b/src/components/AccountPage/index.js index 64d96128..8ad8b4a1 100644 --- a/src/components/AccountPage/index.js +++ b/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 type { T } from 'types/common' +import type { T, Settings } from 'types/common' import { darken } from 'styles/helpers' @@ -57,6 +57,7 @@ const ButtonSettings = styled(Button).attrs({ const mapStateToProps = (state, props) => ({ account: getAccountById(state, props.match.params.id), counterValue: getCounterValueCode(state), + settings: state.settings, }) const mapDispatchToProps = { @@ -68,6 +69,7 @@ type Props = { t: T, account?: Account, openModal: Function, + settings: Settings, } type State = { @@ -82,7 +84,7 @@ class AccountPage extends PureComponent { } handleCalculateBalance = data => { - const { counterValue, account } = this.props + const { counterValue, account, settings } = this.props if (!account) { return @@ -97,12 +99,14 @@ class AccountPage extends PureComponent { balance: { currency: formatCurrencyUnit(account.unit, account.balance, { showCode: true, + locale: settings.language, }), counterValue: formatCurrencyUnit( getFiatCurrencyByTicker(counterValue).units[0], data.totalBalance, { showCode: true, + locale: settings.language, }, ), }, diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index a115b29d..2bf6fa32 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -15,7 +15,7 @@ import type { Account } from '@ledgerhq/live-common/lib/types' import chunk from 'lodash/chunk' -import type { T } from 'types/common' +import type { T, Settings } from 'types/common' import { colors } from 'styles/theme' @@ -39,6 +39,7 @@ const mapStateToProps = state => ({ username: state.settings.username, accounts: getVisibleAccounts(state), counterValue: getCounterValueCode(state), + settings: state.settings, }) const mapDispatchToProps = { @@ -53,6 +54,7 @@ type Props = { push: Function, counterValue: string, username: string, + settings: Settings, } type State = { @@ -88,7 +90,7 @@ class DashboardPage extends PureComponent { } handleCalculateBalance = data => { - const { counterValue } = this.props + const { counterValue, settings } = this.props if (process.platform === 'darwin' && this._cacheBalance !== data.totalBalance) { this._cacheBalance = data.totalBalance @@ -102,6 +104,7 @@ class DashboardPage extends PureComponent { data.totalBalance, { showCode: true, + locale: settings.language, }, ), }, diff --git a/src/components/base/FormattedVal/index.js b/src/components/base/FormattedVal/index.js index 66ef8c82..78051244 100644 --- a/src/components/base/FormattedVal/index.js +++ b/src/components/base/FormattedVal/index.js @@ -98,11 +98,13 @@ export function FormattedVal(props: Props) { if (withIcon && isNegative) { val *= -1 } + const locale = settings ? settings.language : '' text = formatCurrencyUnit(unit, val, { alwaysShowSign, disableRounding, showCode, + locale, }) } diff --git a/src/reducers/settings.js b/src/reducers/settings.js index 8bd73282..464c32b3 100644 --- a/src/reducers/settings.js +++ b/src/reducers/settings.js @@ -24,11 +24,14 @@ export type SettingsState = { region: string, } +/* have to check if available for all OS */ +const language = window.navigator.language.split('-')[0] + const defaultState: SettingsState = { hasCompletedOnboarding: false, username: 'Anonymous', counterValue: 'USD', - language: 'en', + language, orderAccounts: 'balance|asc', password: { isEnabled: false,