From 89a7b54419f6a93ccae1368dde1aefe5356414d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Sun, 6 May 2018 19:54:13 +0200 Subject: [PATCH] using list from https://github.com/LedgerHQ/ledger-wallet-chrome/blob/master/app/src/i18n/regions.yml --- src/components/AccountPage/index.js | 14 +- src/components/DashboardPage/index.js | 14 +- .../SettingsPage/sections/Display.js | 25 +- src/components/base/Chart/Tooltip.js | 2 +- src/components/base/FormattedVal/index.js | 36 +- src/components/base/InputCurrency/index.js | 1 + src/components/base/Select/index.js | 2 +- src/helpers/countries.json | 245 ----------- src/helpers/regions.json | 397 ++++++++++++++++++ src/reducers/settings.js | 9 +- src/renderer/init.js | 4 + 11 files changed, 459 insertions(+), 290 deletions(-) delete mode 100644 src/helpers/countries.json create mode 100644 src/helpers/regions.json diff --git a/src/components/AccountPage/index.js b/src/components/AccountPage/index.js index 8ad8b4a1..cdda36cb 100644 --- a/src/components/AccountPage/index.js +++ b/src/components/AccountPage/index.js @@ -16,12 +16,12 @@ import type { Account } from '@ledgerhq/live-common/lib/types' import { MODAL_SEND, MODAL_RECEIVE, MODAL_SETTINGS_ACCOUNT } from 'config/constants' -import type { T, Settings } from 'types/common' +import type { T } from 'types/common' import { darken } from 'styles/helpers' import { getAccountById } from 'reducers/accounts' -import { getCounterValueCode } from 'reducers/settings' +import { getCounterValueCode, localeSelector } from 'reducers/settings' import { openModal } from 'reducers/modals' import IconControls from 'icons/Controls' @@ -57,7 +57,7 @@ const ButtonSettings = styled(Button).attrs({ const mapStateToProps = (state, props) => ({ account: getAccountById(state, props.match.params.id), counterValue: getCounterValueCode(state), - settings: state.settings, + settings: localeSelector(state), }) const mapDispatchToProps = { @@ -69,7 +69,7 @@ type Props = { t: T, account?: Account, openModal: Function, - settings: Settings, + locale: string, } type State = { @@ -84,7 +84,7 @@ class AccountPage extends PureComponent { } handleCalculateBalance = data => { - const { counterValue, account, settings } = this.props + const { counterValue, account, locale } = this.props if (!account) { return @@ -99,14 +99,14 @@ class AccountPage extends PureComponent { balance: { currency: formatCurrencyUnit(account.unit, account.balance, { showCode: true, - locale: settings.language, + locale, }), counterValue: formatCurrencyUnit( getFiatCurrencyByTicker(counterValue).units[0], data.totalBalance, { showCode: true, - locale: settings.language, + locale, }, ), }, diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index a84a20b7..090ac7dd 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -15,12 +15,12 @@ import type { Account } from '@ledgerhq/live-common/lib/types' import chunk from 'lodash/chunk' -import type { T, Settings } from 'types/common' +import type { T } from 'types/common' import { colors } from 'styles/theme' import { getVisibleAccounts } from 'reducers/accounts' -import { getCounterValueCode } from 'reducers/settings' +import { getCounterValueCode, localeSelector } from 'reducers/settings' import { updateOrderAccounts } from 'actions/accounts' import { saveSettings } from 'actions/settings' @@ -38,7 +38,7 @@ import AccountsOrder from './AccountsOrder' const mapStateToProps = state => ({ accounts: getVisibleAccounts(state), counterValue: getCounterValueCode(state), - settings: state.settings, + locale: localeSelector(state), }) const mapDispatchToProps = { @@ -52,11 +52,11 @@ type Props = { accounts: Account[], push: Function, counterValue: string, - settings: Settings, + locale: string, } type State = { - accountsChunk: Array>, + accountsChunk: Array>, selectedTime: string, daysCount: number, } @@ -88,7 +88,7 @@ class DashboardPage extends PureComponent { } handleCalculateBalance = data => { - const { counterValue, settings } = this.props + const { counterValue, locale } = this.props if (process.platform === 'darwin' && this._cacheBalance !== data.totalBalance) { this._cacheBalance = data.totalBalance @@ -102,7 +102,7 @@ class DashboardPage extends PureComponent { data.totalBalance, { showCode: true, - locale: settings.language, + locale, }, ), }, diff --git a/src/components/SettingsPage/sections/Display.js b/src/components/SettingsPage/sections/Display.js index b5695399..e14430f0 100644 --- a/src/components/SettingsPage/sections/Display.js +++ b/src/components/SettingsPage/sections/Display.js @@ -10,7 +10,7 @@ import Select from 'components/base/Select' import RadioGroup from 'components/base/RadioGroup' import IconDisplay from 'icons/Display' -import COUNTRIES from 'helpers/countries.json' +import regionsByKey from 'helpers/regions.json' import { SettingsSection as Section, @@ -19,6 +19,11 @@ import { SettingsSectionRow as Row, } from '../SettingsSection' +const regions = Object.keys(regionsByKey).map(key => { + const [language, region] = key.split('-') + return { key, language, region, name: regionsByKey[key] } +}) + const fiats = listFiatCurrencies() .map(f => f.units[0]) // For now we take first unit, in the future we'll need to figure out something else @@ -89,7 +94,7 @@ class TabProfile extends PureComponent { }) } - handleChangeRegion = (region: string) => { + handleChangeRegion = ({ region }: *) => { const { saveSettings } = this.props this.setState({ cachedRegion: region }) window.requestIdleCallback(() => { @@ -118,7 +123,9 @@ class TabProfile extends PureComponent { } = this.state const { languages } = this.getDatas() const currentLanguage = languages.find(l => l.key === cachedLanguageKey) - const currentRegion = COUNTRIES.find(r => r.key === cachedRegion) + const regionsFiltered = regions.filter(({ language }) => cachedLanguageKey === language) + const currentRegion = + regionsFiltered.find(({ region }) => cachedRegion === region) || regionsFiltered[0] return (
@@ -133,8 +140,6 @@ class TabProfile extends PureComponent { desc={t('settings:display.counterValueDesc')} > this.handleChangeLanguage(item.key)} renderSelected={item => item && item.name} @@ -156,13 +161,11 @@ class TabProfile extends PureComponent {