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 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<Props, State> {
}
handleCalculateBalance = data => {
const { counterValue, account } = this.props
const { counterValue, account, settings } = this.props
if (!account) {
return
@ -97,12 +99,14 @@ class AccountPage extends PureComponent<Props, State> {
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,
},
),
},

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 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<Props, State> {
}
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<Props, State> {
data.totalBalance,
{
showCode: true,
locale: settings.language,
},
),
},

2
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,
})
}

5
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,

Loading…
Cancel
Save