2018-09-12 02:32:37 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-08-14 13:46:45 +02:00
|
|
|
import availableCurrencies from '../../../helpers/constants/available-conversions.json'
|
2019-03-22 00:03:30 +01:00
|
|
|
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
|
|
|
|
2019-12-09 17:39:46 +01:00
|
|
|
const sortedCurrencies = availableCurrencies.sort((a, b) => {
|
|
|
|
return a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase())
|
2018-09-12 02:32:37 +02:00
|
|
|
})
|
|
|
|
|
2019-12-09 17:39:46 +01:00
|
|
|
const currencyOptions = sortedCurrencies.map(({ code, name }) => {
|
2018-09-12 02:32:37 +02:00
|
|
|
return {
|
|
|
|
displayValue: `${code.toUpperCase()} - ${name}`,
|
|
|
|
key: code,
|
|
|
|
value: code,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const localeOptions = locales.map((locale) => {
|
2018-09-12 02:32:37 +02:00
|
|
|
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,
|
|
|
|
warning: PropTypes.string,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderCurrentConversion() {
|
2018-09-12 02:32:37 +02:00
|
|
|
const { t } = this.context
|
|
|
|
const { currentCurrency, conversionDate, setCurrentCurrency } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
2020-11-03 00:41:28 +01:00
|
|
|
<span>{t('currencyConversion')}</span>
|
2018-09-12 02:32:37 +02:00
|
|
|
<span className="settings-page__content-description">
|
2020-11-03 00:41:28 +01: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')}
|
2019-12-09 17:39:46 +01:00
|
|
|
options={currencyOptions}
|
2018-09-12 02:32:37 +02:00
|
|
|
selectedOption={currentCurrency}
|
2020-02-15 21:34:12 +01:00
|
|
|
onSelect={(newCurrency) => setCurrentCurrency(newCurrency)}
|
2018-09-12 02:32:37 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderCurrentLocale() {
|
2018-09-12 02:32:37 +02:00
|
|
|
const { t } = this.context
|
|
|
|
const { updateCurrentLocale, currentLocale } = this.props
|
2020-11-03 00:41:28 +01:00
|
|
|
const currentLocaleMeta = locales.find(
|
|
|
|
(locale) => locale.code === currentLocale,
|
|
|
|
)
|
2018-09-12 02:32:37 +02:00
|
|
|
const currentLocaleName = currentLocaleMeta ? currentLocaleMeta.name : ''
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span className="settings-page__content-label">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('currentLanguage')}
|
2018-09-12 02:32:37 +02:00
|
|
|
</span>
|
|
|
|
<span className="settings-page__content-description">
|
2020-11-03 00:41:28 +01:00
|
|
|
{currentLocaleName}
|
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('selectLocale')}
|
|
|
|
options={localeOptions}
|
|
|
|
selectedOption={currentLocale}
|
2020-02-15 21:34:12 +01:00
|
|
|
onSelect={async (newLocale) => updateCurrentLocale(newLocale)}
|
2018-09-12 02:32:37 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
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">
|
2020-11-03 00:41:28 +01:00
|
|
|
<span>{this.context.t('blockiesIdenticon')}</span>
|
2018-09-12 02:32:37 +02:00
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={useBlockie}
|
2020-02-15 21:34:12 +01:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01: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">
|
2020-11-03 00:41:28 +01:00
|
|
|
<span>{t('primaryCurrencySetting')}</span>
|
2018-10-17 01:03:29 +02:00
|
|
|
<div className="settings-page__content-description">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('primaryCurrencySettingDescription')}
|
2018-10-17 01:03:29 +02:00
|
|
|
</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"
|
2020-11-03 00:41:28 +01:00
|
|
|
onChange={() =>
|
|
|
|
setUseNativeCurrencyAsPrimaryCurrencyPreference(true)
|
|
|
|
}
|
2018-10-26 10:26:43 +02:00
|
|
|
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"
|
|
|
|
>
|
2020-11-03 00:41:28 +01: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"
|
2020-11-03 00:41:28 +01:00
|
|
|
onChange={() =>
|
|
|
|
setUseNativeCurrencyAsPrimaryCurrencyPreference(false)
|
|
|
|
}
|
2018-10-26 10:26:43 +02:00
|
|
|
checked={!useNativeCurrencyAsPrimaryCurrency}
|
2018-10-17 01:03:29 +02:00
|
|
|
/>
|
|
|
|
<label
|
|
|
|
htmlFor="fiat-primary-currency"
|
|
|
|
className="settings-tab__radio-label"
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('fiat')}
|
2018-10-17 01:03:29 +02:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
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">
|
2020-11-03 00:41:28 +01:00
|
|
|
{warning && <div className="settings-tab__error">{warning}</div>}
|
|
|
|
{this.renderCurrentConversion()}
|
|
|
|
{this.renderUsePrimaryCurrencyOptions()}
|
|
|
|
{this.renderCurrentLocale()}
|
|
|
|
{this.renderBlockieOptIn()}
|
2018-09-12 02:32:37 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|