Browse Source

Connect the countervalue & language settings

master
meriadec 7 years ago
committed by Loëck Vézien
parent
commit
5648ae12ac
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 31
      src/components/SettingsPage/sections/Display.js
  2. 16
      src/components/SettingsPage/sections/Profile.js
  3. 27
      src/components/base/Input/index.js
  4. 3
      src/components/base/Select/index.js
  5. 10
      static/i18n/en/settings.yml
  6. 3
      yarn.lock

31
src/components/SettingsPage/sections/Display.js

@ -2,6 +2,7 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import moment from 'moment' import moment from 'moment'
import { listFiats } from '@ledgerhq/currencies'
import type { Settings, T } from 'types/common' import type { Settings, T } from 'types/common'
@ -15,6 +16,12 @@ import {
SettingsSectionRow as Row, SettingsSectionRow as Row,
} from '../SettingsSection' } from '../SettingsSection'
const fiats = listFiats().map(fiat => ({
key: fiat.code,
fiat,
name: `${fiat.name} - ${fiat.code}${fiat.symbol ? ` (${fiat.symbol})` : ''}`,
}))
type Props = { type Props = {
t: T, t: T,
settings: Settings, settings: Settings,
@ -24,11 +31,13 @@ type Props = {
type State = { type State = {
cachedLanguageKey: string, cachedLanguageKey: string,
cachedCounterValue: ?string,
} }
class TabProfile extends PureComponent<Props, State> { class TabProfile extends PureComponent<Props, State> {
state = { state = {
cachedLanguageKey: this.props.settings.language, cachedLanguageKey: this.props.settings.language,
cachedCounterValue: fiats.find(fiat => fiat.fiat.code === this.props.settings.counterValue),
} }
getDatas() { getDatas() {
@ -38,6 +47,14 @@ class TabProfile extends PureComponent<Props, State> {
} }
} }
handleChangeCounterValue = item => {
const { saveSettings } = this.props
this.setState({ cachedCounterValue: item.fiat })
window.requestIdleCallback(() => {
saveSettings({ counterValue: item.fiat.code })
})
}
handleChangeLanguage = (languageKey: string) => { handleChangeLanguage = (languageKey: string) => {
const { i18n, saveSettings } = this.props const { i18n, saveSettings } = this.props
this.setState({ cachedLanguageKey: languageKey }) this.setState({ cachedLanguageKey: languageKey })
@ -50,7 +67,7 @@ class TabProfile extends PureComponent<Props, State> {
render() { render() {
const { t } = this.props const { t } = this.props
const { cachedLanguageKey } = this.state const { cachedLanguageKey, cachedCounterValue } = this.state
const { languages } = this.getDatas() const { languages } = this.getDatas()
const currentLanguage = languages.find(l => l.key === cachedLanguageKey) const currentLanguage = languages.find(l => l.key === cachedLanguageKey)
@ -66,7 +83,17 @@ class TabProfile extends PureComponent<Props, State> {
title={t('settings:display.counterValue')} title={t('settings:display.counterValue')}
desc={t('settings:display.counterValueDesc')} desc={t('settings:display.counterValueDesc')}
> >
{'-'} <Select
searchable
fuseOptions={{ keys: ['name'] }}
style={{ minWidth: 250 }}
small
onChange={item => this.handleChangeCounterValue(item)}
itemToString={item => (item ? item.name : '')}
renderSelected={item => item && item.name}
items={fiats}
value={cachedCounterValue}
/>
</Row> </Row>
<Row title={t('settings:display.language')} desc={t('settings:display.languageDesc')}> <Row title={t('settings:display.language')} desc={t('settings:display.languageDesc')}>
<Select <Select

16
src/components/SettingsPage/sections/Profile.js

@ -44,8 +44,20 @@ class TabProfile extends PureComponent<Props, State> {
desc="Lorem ipsum dolor sit amet" desc="Lorem ipsum dolor sit amet"
/> />
<Body> <Body>
<Row title={t('settings:display.language')} desc={t('settings:display.languageDesc')}> <Row title={t('settings:profile.username')} desc={t('settings:profile.usernameDesc')}>
noetuhnoeth {'-'}
</Row>
<Row title={t('settings:profile.password')} desc={t('settings:profile.passwordDesc')}>
{'-'}
</Row>
<Row title={t('settings:profile.sync')} desc={t('settings:profile.syncDesc')}>
{'-'}
</Row>
<Row title={t('settings:profile.export')} desc={t('settings:profile.exportDesc')}>
{'-'}
</Row>
<Row title={t('settings:profile.reset')} desc={t('settings:profile.resetDesc')}>
{'-'}
</Row> </Row>
</Body> </Body>
</Section> </Section>

27
src/components/base/Input/index.js

@ -16,17 +16,17 @@ const Container = styled(Box).attrs({
border-radius: ${p => p.theme.radii[1]}px; border-radius: ${p => p.theme.radii[1]}px;
border: 1px solid ${p => (p.isFocus ? p.theme.colors.wallet : p.theme.colors.fog)}; border: 1px solid ${p => (p.isFocus ? p.theme.colors.wallet : p.theme.colors.fog)};
box-shadow: ${p => (p.isFocus ? `rgba(0, 0, 0, 0.05) 0 2px 2px` : 'none')}; box-shadow: ${p => (p.isFocus ? `rgba(0, 0, 0, 0.05) 0 2px 2px` : 'none')};
height: 40px; height: ${p => (p.small ? '34' : '40')}px;
` `
const Base = styled.input.attrs({ const Base = styled.input.attrs({
ff: p => p.ff || 'Open Sans|SemiBold', ff: p => (p.ff || p.small ? 'Open Sans' : 'Open Sans|SemiBold'),
fontSize: 4, fontSize: 4,
})` })`
${fontFamily}; ${fontFamily};
${fontSize}; ${fontSize};
border: 0; border: 0;
color: ${p => p.theme.colors.dark}; color: ${p => p.theme.colors.graphite};
height: 100%; height: 100%;
outline: none; outline: none;
padding: 0; padding: 0;
@ -65,6 +65,7 @@ type Props = {
renderLeft?: any, renderLeft?: any,
renderRight?: any, renderRight?: any,
containerProps?: Object, containerProps?: Object,
small?: boolean,
} }
type State = { type State = {
@ -77,6 +78,7 @@ class Input extends PureComponent<Props, State> {
onFocus: noop, onFocus: noop,
renderLeft: null, renderLeft: null,
renderRight: null, renderRight: null,
small: false,
} }
state = { state = {
@ -93,34 +95,41 @@ class Input extends PureComponent<Props, State> {
handleClick = () => this._input && this._input.focus() handleClick = () => this._input && this._input.focus()
handleFocus = () => { handleFocus = e => {
const { onFocus } = this.props const { onFocus } = this.props
this.setState({ this.setState({
isFocus: true, isFocus: true,
}) })
onFocus() onFocus(e)
} }
handleBlur = () => { handleBlur = e => {
const { onBlur } = this.props const { onBlur } = this.props
this.setState({ this.setState({
isFocus: false, isFocus: false,
}) })
onBlur() onBlur(e)
} }
_input = null _input = null
render() { render() {
const { isFocus } = this.state const { isFocus } = this.state
const { renderLeft, renderRight, containerProps } = this.props const { renderLeft, renderRight, containerProps, small } = this.props
return ( return (
<Container onClick={this.handleClick} isFocus={isFocus} shrink {...containerProps}> <Container
onClick={this.handleClick}
isFocus={isFocus}
shrink
{...containerProps}
small={small}
>
{renderLeft} {renderLeft}
<Box px={3} grow shrink> <Box px={3} grow shrink>
<Base <Base
{...this.props} {...this.props}
small={small}
innerRef={n => (this._input = n)} innerRef={n => (this._input = n)}
onFocus={this.handleFocus} onFocus={this.handleFocus}
onBlur={this.handleBlur} onBlur={this.handleBlur}

3
src/components/base/Select/index.js

@ -297,10 +297,11 @@ class Select extends PureComponent<Props> {
{searchable ? ( {searchable ? (
<Box grow> <Box grow>
<Input <Input
small
keepEvent keepEvent
{...getInputProps({ placeholder })}
onClick={openMenu} onClick={openMenu}
renderRight={<AngleDown mr={2} />} renderRight={<AngleDown mr={2} />}
{...getInputProps({ placeholder })}
/> />
</Box> </Box>
) : ( ) : (

10
static/i18n/en/settings.yml

@ -23,8 +23,16 @@ currencies:
explorer: Blockchain explorer explorer: Blockchain explorer
explorerDesc: Lorem ipsum dolor sit amet explorerDesc: Lorem ipsum dolor sit amet
profile: profile:
protectWithPassword: Protect local data with a password username: Username
usernameDesc: Lorem ipsum dolor sit amet
password: Password password: Password
passwordDesc: Lorem ipsum dolor sit amet
sync: Sync accounts
syncDesc: Lorem ipsum dolor sit amet
export: Export logs
exportDesc: Lorem ipsum dolor sit amet
reset: Reset application
resetDesc: Lorem ipsum dolor sit amet
about: about:
faq: FAQ faq: FAQ
faqDesc: Lorem ipsum dolor sit amet faqDesc: Lorem ipsum dolor sit amet

3
yarn.lock

@ -8013,9 +8013,6 @@ ledger-test-library@KhalilBellakrid/ledger-test-library-nodejs#7d37482:
dependencies: dependencies:
axios "^0.17.1" axios "^0.17.1"
bindings "^1.3.0" bindings "^1.3.0"
electron "^1.8.2"
electron-builder "^20.0.4"
electron-rebuild "^1.7.3"
nan "^2.6.2" nan "^2.6.2"
prebuild-install "^2.2.2" prebuild-install "^2.2.2"

Loading…
Cancel
Save