1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 21:00:13 +01:00
metamask-extension/ui/app/pages/settings/settings-tab/settings-tab.component.js
Dan J Miller 32a3f5ad7b
Address various UI styling issues (#6744)
* Add loading spinner to pending tx status label.

* Add border around account icon in top right

* Change style of settings toggle buttons; wrap with local components

* Eliminate large space after settings labels when no description

* Remove network form from advanced tab of settings

* Keep new account container height to contents when in full screen
2019-07-08 15:28:35 -02:30

202 lines
6.4 KiB
JavaScript

import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import infuraCurrencies from '../../../helpers/constants/infura-conversion.json'
import SimpleDropdown from '../../../components/app/dropdowns/simple-dropdown'
import ToggleButton from '../../../components/ui/toggle-button'
import locales from '../../../../../app/_locales/index.json'
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,
metricsEvent: PropTypes.func,
}
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,
nativeCurrency: PropTypes.string,
useNativeCurrencyAsPrimaryCurrency: PropTypes.bool,
setUseNativeCurrencyAsPrimaryCurrencyPreference: PropTypes.func,
}
renderCurrentConversion () {
const { t } = this.context
const { currentCurrency, conversionDate, setCurrentCurrency } = this.props
return (
<div className="settings-page__content-row">
<div className="settings-page__content-item">
<span>{ t('currencyConversion') }</span>
<span className="settings-page__content-description">
{ t('updatedWithDate', [Date(conversionDate)]) }
</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 () {
const { t } = this.context
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)}
offLabel={t('off')}
onLabel={t('on')}
/>
</div>
</div>
</div>
)
}
renderUsePrimaryCurrencyOptions () {
const { t } = this.context
const {
nativeCurrency,
setUseNativeCurrencyAsPrimaryCurrencyPreference,
useNativeCurrencyAsPrimaryCurrency,
} = this.props
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"
id="native-primary-currency"
onChange={() => setUseNativeCurrencyAsPrimaryCurrencyPreference(true)}
checked={Boolean(useNativeCurrencyAsPrimaryCurrency)}
/>
<label
htmlFor="native-primary-currency"
className="settings-tab__radio-label"
>
{ nativeCurrency }
</label>
</div>
<div className="settings-tab__radio-button">
<input
type="radio"
id="fiat-primary-currency"
onChange={() => setUseNativeCurrencyAsPrimaryCurrencyPreference(false)}
checked={!useNativeCurrencyAsPrimaryCurrency}
/>
<label
htmlFor="fiat-primary-currency"
className="settings-tab__radio-label"
>
{ t('fiat') }
</label>
</div>
</div>
</div>
</div>
</div>
)
}
renderContent () {
const { warning } = this.props
return (
<div className="settings-page__body">
{ warning && <div className="settings-tab__error">{ warning }</div> }
{ this.renderCurrentConversion() }
{ this.renderUsePrimaryCurrencyOptions() }
{ this.renderCurrentLocale() }
{ this.renderBlockieOptIn() }
</div>
)
}
render () {
return this.renderContent()
}
}