2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2022-02-16 18:03:17 +01:00
|
|
|
import classnames from 'classnames';
|
2021-02-04 19:15:23 +01:00
|
|
|
import availableCurrencies from '../../../helpers/constants/available-conversions.json';
|
2022-02-16 18:03:17 +01:00
|
|
|
import { TYPOGRAPHY, COLORS } from '../../../helpers/constants/design-system';
|
2021-02-19 20:03:44 +01:00
|
|
|
import Dropdown from '../../../components/ui/dropdown';
|
2021-02-04 19:15:23 +01:00
|
|
|
import ToggleButton from '../../../components/ui/toggle-button';
|
2021-04-28 21:53:59 +02:00
|
|
|
import locales from '../../../../app/_locales/index.json';
|
2022-02-16 18:03:17 +01:00
|
|
|
import Jazzicon from '../../../components/ui/jazzicon';
|
|
|
|
import BlockieIdenticon from '../../../components/ui/identicon/blockieIdenticon';
|
|
|
|
import Typography from '../../../components/ui/typography';
|
2018-09-12 02:32:37 +02:00
|
|
|
|
2022-02-22 21:58:21 +01:00
|
|
|
import {
|
|
|
|
getSettingsSectionNumber,
|
|
|
|
handleSettingsRefs,
|
|
|
|
} from '../../../helpers/utils/settings-search';
|
|
|
|
|
2019-12-09 17:39:46 +01:00
|
|
|
const sortedCurrencies = availableCurrencies.sort((a, b) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
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 {
|
2021-02-19 20:03:44 +01:00
|
|
|
name: `${code.toUpperCase()} - ${name}`,
|
2018-09-12 02:32:37 +02:00
|
|
|
value: code,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
});
|
2018-09-12 02:32:37 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const localeOptions = locales.map((locale) => {
|
2018-09-12 02:32:37 +02:00
|
|
|
return {
|
2021-02-19 20:03:44 +01:00
|
|
|
name: `${locale.name}`,
|
2018-09-12 02:32:37 +02:00
|
|
|
value: locale.code,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
});
|
2018-09-12 02:32:37 +02:00
|
|
|
|
|
|
|
export default class SettingsTab extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
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,
|
2018-10-26 10:26:43 +02:00
|
|
|
nativeCurrency: PropTypes.string,
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: PropTypes.bool,
|
|
|
|
setUseNativeCurrencyAsPrimaryCurrencyPreference: PropTypes.func,
|
2021-03-09 20:35:55 +01:00
|
|
|
hideZeroBalanceTokens: PropTypes.bool,
|
|
|
|
setHideZeroBalanceTokens: PropTypes.func,
|
2021-12-02 13:18:09 +01:00
|
|
|
lastFetchedConversionDate: PropTypes.number,
|
2022-02-16 18:03:17 +01:00
|
|
|
selectedAddress: PropTypes.string,
|
|
|
|
useTokenDetection: PropTypes.bool,
|
|
|
|
tokenList: PropTypes.object,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-12 02:32:37 +02:00
|
|
|
|
2022-02-22 21:58:21 +01:00
|
|
|
settingsRefs = Array(
|
|
|
|
getSettingsSectionNumber(this.context.t, this.context.t('general')),
|
|
|
|
)
|
|
|
|
.fill(undefined)
|
|
|
|
.map(() => {
|
|
|
|
return React.createRef();
|
|
|
|
});
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const { t } = this.context;
|
|
|
|
handleSettingsRefs(t, t('general'), this.settingsRefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { t } = this.context;
|
|
|
|
handleSettingsRefs(t, t('general'), this.settingsRefs);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderCurrentConversion() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2021-12-02 13:18:09 +01:00
|
|
|
const {
|
|
|
|
currentCurrency,
|
|
|
|
setCurrentCurrency,
|
|
|
|
lastFetchedConversionDate,
|
|
|
|
} = this.props;
|
2018-09-12 02:32:37 +02:00
|
|
|
|
|
|
|
return (
|
2022-02-22 21:58:21 +01:00
|
|
|
<div ref={this.settingsRefs[0]} className="settings-page__content-row">
|
2018-09-12 02:32:37 +02:00
|
|
|
<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">
|
2021-12-02 13:18:09 +01:00
|
|
|
{lastFetchedConversionDate
|
|
|
|
? t('updatedWithDate', [
|
|
|
|
new Date(lastFetchedConversionDate * 1000).toString(),
|
|
|
|
])
|
|
|
|
: t('noConversionDateAvailable')}
|
2018-09-12 02:32:37 +02:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
2021-02-19 20:03:44 +01:00
|
|
|
<Dropdown
|
|
|
|
id="select-currency"
|
2019-12-09 17:39:46 +01:00
|
|
|
options={currencyOptions}
|
2018-09-12 02:32:37 +02:00
|
|
|
selectedOption={currentCurrency}
|
2021-02-19 20:03:44 +01:00
|
|
|
onChange={(newCurrency) => setCurrentCurrency(newCurrency)}
|
2018-09-12 02:32:37 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderCurrentLocale() {
|
2021-02-04 19:15:23 +01: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,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const currentLocaleName = currentLocaleMeta ? currentLocaleMeta.name : '';
|
2018-09-12 02:32:37 +02:00
|
|
|
|
|
|
|
return (
|
2022-02-22 21:58:21 +01:00
|
|
|
<div ref={this.settingsRefs[2]} className="settings-page__content-row">
|
2018-09-12 02:32:37 +02:00
|
|
|
<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">
|
2021-02-19 20:03:44 +01:00
|
|
|
<Dropdown
|
|
|
|
id="select-locale"
|
2018-09-12 02:32:37 +02:00
|
|
|
options={localeOptions}
|
|
|
|
selectedOption={currentLocale}
|
2021-02-19 20:03:44 +01:00
|
|
|
onChange={async (newLocale) => updateCurrentLocale(newLocale)}
|
2018-09-12 02:32:37 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
|
|
|
|
2021-03-09 20:35:55 +01:00
|
|
|
renderHideZeroBalanceTokensOptIn() {
|
|
|
|
const { t } = this.context;
|
|
|
|
const { hideZeroBalanceTokens, setHideZeroBalanceTokens } = this.props;
|
|
|
|
|
|
|
|
return (
|
2022-02-22 21:58:21 +01:00
|
|
|
<div
|
|
|
|
ref={this.settingsRefs[4]}
|
|
|
|
className="settings-page__content-row"
|
|
|
|
id="toggle-zero-balance"
|
|
|
|
>
|
2021-03-09 20:35:55 +01:00
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{t('hideZeroBalanceTokens')}</span>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={hideZeroBalanceTokens}
|
|
|
|
onToggle={(value) => setHideZeroBalanceTokens(!value)}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderBlockieOptIn() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2022-02-16 18:03:17 +01:00
|
|
|
const {
|
|
|
|
useBlockie,
|
|
|
|
setUseBlockie,
|
|
|
|
selectedAddress,
|
|
|
|
useTokenDetection,
|
|
|
|
tokenList,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const getIconStyles = () => ({
|
|
|
|
display: 'block',
|
|
|
|
borderRadius: '16px',
|
|
|
|
width: '32px',
|
|
|
|
height: '32px',
|
|
|
|
});
|
2018-09-12 02:32:37 +02:00
|
|
|
|
|
|
|
return (
|
2022-02-22 21:58:21 +01:00
|
|
|
<div
|
|
|
|
ref={this.settingsRefs[3]}
|
|
|
|
className="settings-page__content-row"
|
|
|
|
id="blockie-optin"
|
|
|
|
>
|
2018-09-12 02:32:37 +02:00
|
|
|
<div className="settings-page__content-item">
|
2022-03-09 16:24:53 +01:00
|
|
|
<Typography variant={TYPOGRAPHY.H5} color={COLORS.TEXT_DEFAULT}>
|
2022-02-16 18:03:17 +01:00
|
|
|
{t('accountIdenticon')}
|
|
|
|
</Typography>
|
|
|
|
<span className="settings-page__content-item__description">
|
|
|
|
{t('jazzAndBlockies')}
|
|
|
|
</span>
|
|
|
|
<div className="settings-page__content-item__identicon">
|
|
|
|
<div className="settings-page__content-item__identicon__item">
|
|
|
|
<div
|
|
|
|
data-test-id="jazz_icon"
|
|
|
|
className={classnames(
|
|
|
|
'settings-page__content-item__identicon__item__icon',
|
|
|
|
{
|
|
|
|
'settings-page__content-item__identicon__item__icon--active': !useBlockie,
|
|
|
|
},
|
|
|
|
)}
|
|
|
|
onClick={() => setUseBlockie(false)}
|
|
|
|
>
|
|
|
|
<Jazzicon
|
|
|
|
id="jazzicon"
|
|
|
|
address={selectedAddress}
|
|
|
|
diameter={32}
|
|
|
|
useTokenDetection={useTokenDetection}
|
|
|
|
tokenList={tokenList}
|
|
|
|
style={getIconStyles()}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Typography
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_DEFAULT}
|
2022-02-16 18:03:17 +01:00
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
margin={[0, 12, 0, 3]}
|
|
|
|
>
|
|
|
|
{t('jazzicons')}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item__identicon__item">
|
|
|
|
<div
|
|
|
|
data-test-id="blockie_icon"
|
|
|
|
className={classnames(
|
|
|
|
'settings-page__content-item__identicon__item__icon',
|
|
|
|
{
|
|
|
|
'settings-page__content-item__identicon__item__icon--active': useBlockie,
|
|
|
|
},
|
|
|
|
)}
|
|
|
|
onClick={() => setUseBlockie(true)}
|
|
|
|
>
|
|
|
|
<BlockieIdenticon
|
|
|
|
id="blockies"
|
|
|
|
address={selectedAddress}
|
|
|
|
diameter={32}
|
|
|
|
borderRadius="50%"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<Typography
|
2022-03-09 16:24:53 +01:00
|
|
|
color={COLORS.TEXT_DEFAULT}
|
2022-02-16 18:03:17 +01:00
|
|
|
variant={TYPOGRAPHY.H7}
|
|
|
|
margin={[0, 0, 0, 3]}
|
|
|
|
>
|
|
|
|
{t('blockies')}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
2018-09-12 02:32:37 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderUsePrimaryCurrencyOptions() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2018-10-26 10:26:43 +02:00
|
|
|
const {
|
|
|
|
nativeCurrency,
|
|
|
|
setUseNativeCurrencyAsPrimaryCurrencyPreference,
|
|
|
|
useNativeCurrencyAsPrimaryCurrency,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2018-10-17 01:03:29 +02:00
|
|
|
|
|
|
|
return (
|
2022-02-22 21:58:21 +01:00
|
|
|
<div ref={this.settingsRefs[1]} className="settings-page__content-row">
|
2018-10-17 01:03:29 +02:00
|
|
|
<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>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +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">
|
2021-10-21 18:11:31 +02:00
|
|
|
{warning ? <div className="settings-tab__error">{warning}</div> : null}
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderCurrentConversion()}
|
|
|
|
{this.renderUsePrimaryCurrencyOptions()}
|
|
|
|
{this.renderCurrentLocale()}
|
|
|
|
{this.renderBlockieOptIn()}
|
2021-03-09 20:35:55 +01:00
|
|
|
{this.renderHideZeroBalanceTokensOptIn()}
|
2018-09-12 02:32:37 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-12 02:32:37 +02:00
|
|
|
}
|
|
|
|
}
|