2018-09-12 02:32:37 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-03-22 00:03:30 +01:00
|
|
|
import infuraCurrencies from '../../../helpers/constants/infura-conversion.json'
|
|
|
|
import SimpleDropdown from '../../../components/app/dropdowns/simple-dropdown'
|
2019-07-08 19:58:35 +02:00
|
|
|
import ToggleButton from '../../../components/ui/toggle-button'
|
2019-03-22 00:03:30 +01:00
|
|
|
import locales from '../../../../../app/_locales/index.json'
|
2018-09-12 02:32:37 +02:00
|
|
|
|
|
|
|
const sortedCurrencies = infuraCurrencies.objects.sort((a, b) => {
|
|
|
|
return a.quote.name.toLocaleLowerCase().localeCompare(b.quote.name.toLocaleLowerCase())
|
|
|
|
})
|
|
|
|
|
|
|
|
const infuraCurrencyOptions = sortedCurrencies.map(({ quote: { code, name } }) => {
|
|
|
|
return {
|
|
|
|
displayValue: `${code.toUpperCase()} - ${name}`,
|
|
|
|
key: code,
|
|
|
|
value: code,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const localeOptions = locales.map(locale => {
|
|
|
|
return {
|
|
|
|
displayValue: `${locale.name}`,
|
|
|
|
key: locale.code,
|
|
|
|
value: locale.code,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default class SettingsTab extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
setUseBlockie: PropTypes.func,
|
|
|
|
setCurrentCurrency: PropTypes.func,
|
|
|
|
displayWarning: PropTypes.func,
|
|
|
|
warning: PropTypes.string,
|
|
|
|
history: PropTypes.object,
|
|
|
|
updateCurrentLocale: PropTypes.func,
|
|
|
|
currentLocale: PropTypes.string,
|
|
|
|
useBlockie: PropTypes.bool,
|
|
|
|
currentCurrency: PropTypes.string,
|
|
|
|
conversionDate: PropTypes.number,
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: PropTypes.string,
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: PropTypes.bool,
|
|
|
|
setUseNativeCurrencyAsPrimaryCurrencyPreference: PropTypes.func,
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
renderCurrentConversion () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { currentCurrency, conversionDate, setCurrentCurrency } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
2019-01-17 16:07:38 +01:00
|
|
|
<span>{ t('currencyConversion') }</span>
|
2018-09-12 02:32:37 +02:00
|
|
|
<span className="settings-page__content-description">
|
2018-09-20 01:55:58 +02:00
|
|
|
{ t('updatedWithDate', [Date(conversionDate)]) }
|
2018-09-12 02:32:37 +02:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<SimpleDropdown
|
|
|
|
placeholder={t('selectCurrency')}
|
|
|
|
options={infuraCurrencyOptions}
|
|
|
|
selectedOption={currentCurrency}
|
|
|
|
onSelect={newCurrency => setCurrentCurrency(newCurrency)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderCurrentLocale () {
|
|
|
|
const { t } = this.context
|
|
|
|
const { updateCurrentLocale, currentLocale } = this.props
|
|
|
|
const currentLocaleMeta = locales.find(locale => locale.code === currentLocale)
|
|
|
|
const currentLocaleName = currentLocaleMeta ? currentLocaleMeta.name : ''
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span className="settings-page__content-label">
|
|
|
|
{ t('currentLanguage') }
|
|
|
|
</span>
|
|
|
|
<span className="settings-page__content-description">
|
|
|
|
{ currentLocaleName }
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<SimpleDropdown
|
|
|
|
placeholder={t('selectLocale')}
|
|
|
|
options={localeOptions}
|
|
|
|
selectedOption={currentLocale}
|
|
|
|
onSelect={async newLocale => updateCurrentLocale(newLocale)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderBlockieOptIn () {
|
2019-07-08 19:58:35 +02:00
|
|
|
const { t } = this.context
|
2018-09-12 02:32:37 +02:00
|
|
|
const { useBlockie, setUseBlockie } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ this.context.t('blockiesIdenticon') }</span>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={useBlockie}
|
|
|
|
onToggle={value => setUseBlockie(!value)}
|
2019-07-08 19:58:35 +02:00
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
2018-09-12 02:32:37 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-10-26 10:26:43 +02:00
|
|
|
renderUsePrimaryCurrencyOptions () {
|
2018-10-17 01:03:29 +02:00
|
|
|
const { t } = this.context
|
2018-10-26 10:26:43 +02:00
|
|
|
const {
|
|
|
|
nativeCurrency,
|
|
|
|
setUseNativeCurrencyAsPrimaryCurrencyPreference,
|
|
|
|
useNativeCurrencyAsPrimaryCurrency,
|
|
|
|
} = this.props
|
2018-10-17 01:03:29 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{ t('primaryCurrencySetting') }</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{ t('primaryCurrencySettingDescription') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<div className="settings-tab__radio-buttons">
|
|
|
|
<div className="settings-tab__radio-button">
|
|
|
|
<input
|
|
|
|
type="radio"
|
2018-10-26 10:26:43 +02:00
|
|
|
id="native-primary-currency"
|
|
|
|
onChange={() => setUseNativeCurrencyAsPrimaryCurrencyPreference(true)}
|
|
|
|
checked={Boolean(useNativeCurrencyAsPrimaryCurrency)}
|
2018-10-17 01:03:29 +02:00
|
|
|
/>
|
|
|
|
<label
|
2018-10-26 10:26:43 +02:00
|
|
|
htmlFor="native-primary-currency"
|
2018-10-17 01:03:29 +02:00
|
|
|
className="settings-tab__radio-label"
|
|
|
|
>
|
2018-10-26 10:26:43 +02:00
|
|
|
{ nativeCurrency }
|
2018-10-17 01:03:29 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div className="settings-tab__radio-button">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
id="fiat-primary-currency"
|
2018-10-26 10:26:43 +02:00
|
|
|
onChange={() => setUseNativeCurrencyAsPrimaryCurrencyPreference(false)}
|
|
|
|
checked={!useNativeCurrencyAsPrimaryCurrency}
|
2018-10-17 01:03:29 +02:00
|
|
|
/>
|
|
|
|
<label
|
|
|
|
htmlFor="fiat-primary-currency"
|
|
|
|
className="settings-tab__radio-label"
|
|
|
|
>
|
|
|
|
{ t('fiat') }
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-03-25 17:13:23 +01:00
|
|
|
renderContent () {
|
2019-01-30 14:56:33 +01:00
|
|
|
const { warning } = this.props
|
2018-09-12 02:32:37 +02:00
|
|
|
|
|
|
|
return (
|
2019-03-25 17:13:23 +01:00
|
|
|
<div className="settings-page__body">
|
2018-09-12 02:32:37 +02:00
|
|
|
{ warning && <div className="settings-tab__error">{ warning }</div> }
|
|
|
|
{ this.renderCurrentConversion() }
|
2018-10-26 10:26:43 +02:00
|
|
|
{ this.renderUsePrimaryCurrencyOptions() }
|
2018-09-12 02:32:37 +02:00
|
|
|
{ this.renderCurrentLocale() }
|
2018-10-10 20:52:26 +02:00
|
|
|
{ this.renderBlockieOptIn() }
|
2018-09-12 02:32:37 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2019-03-25 17:13:23 +01:00
|
|
|
|
|
|
|
render () {
|
|
|
|
return this.renderContent()
|
|
|
|
}
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|