mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Move THEME_TYPE to new preferences.ts file (#17515)
This commit is contained in:
parent
7a29d896ad
commit
6e7f5c3e21
@ -3,7 +3,7 @@ import { normalize as normalizeAddress } from 'eth-sig-util';
|
|||||||
import { IPFS_DEFAULT_GATEWAY_URL } from '../../../shared/constants/network';
|
import { IPFS_DEFAULT_GATEWAY_URL } from '../../../shared/constants/network';
|
||||||
import { isPrefixedFormattedHexString } from '../../../shared/modules/network.utils';
|
import { isPrefixedFormattedHexString } from '../../../shared/modules/network.utils';
|
||||||
import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets';
|
import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets';
|
||||||
import { THEME_TYPE } from '../../../ui/pages/settings/settings-tab/settings-tab.constant';
|
import { ThemeType } from '../../../shared/constants/preferences';
|
||||||
import { NETWORK_EVENTS } from './network';
|
import { NETWORK_EVENTS } from './network';
|
||||||
|
|
||||||
export default class PreferencesController {
|
export default class PreferencesController {
|
||||||
@ -66,7 +66,7 @@ export default class PreferencesController {
|
|||||||
? LedgerTransportTypes.webhid
|
? LedgerTransportTypes.webhid
|
||||||
: LedgerTransportTypes.u2f,
|
: LedgerTransportTypes.u2f,
|
||||||
transactionSecurityCheckEnabled: false,
|
transactionSecurityCheckEnabled: false,
|
||||||
theme: THEME_TYPE.OS,
|
theme: ThemeType.os,
|
||||||
...opts.initState,
|
...opts.initState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
5
shared/constants/preferences.ts
Normal file
5
shared/constants/preferences.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export enum ThemeType {
|
||||||
|
light = 'light',
|
||||||
|
dark = 'dark',
|
||||||
|
os = 'os',
|
||||||
|
}
|
@ -77,9 +77,9 @@ import ConfirmationPage from '../confirmation';
|
|||||||
import OnboardingFlow from '../onboarding-flow/onboarding-flow';
|
import OnboardingFlow from '../onboarding-flow/onboarding-flow';
|
||||||
import QRHardwarePopover from '../../components/app/qr-hardware-popover';
|
import QRHardwarePopover from '../../components/app/qr-hardware-popover';
|
||||||
import { SEND_STAGES } from '../../ducks/send';
|
import { SEND_STAGES } from '../../ducks/send';
|
||||||
import { THEME_TYPE } from '../settings/settings-tab/settings-tab.constant';
|
|
||||||
import DeprecatedTestNetworks from '../../components/ui/deprecated-test-networks/deprecated-test-networks';
|
import DeprecatedTestNetworks from '../../components/ui/deprecated-test-networks/deprecated-test-networks';
|
||||||
import NewNetworkInfo from '../../components/ui/new-network-info/new-network-info';
|
import NewNetworkInfo from '../../components/ui/new-network-info/new-network-info';
|
||||||
|
import { ThemeType } from '../../../shared/constants/preferences';
|
||||||
|
|
||||||
export default class Routes extends Component {
|
export default class Routes extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -125,8 +125,8 @@ export default class Routes extends Component {
|
|||||||
|
|
||||||
handleOsTheme() {
|
handleOsTheme() {
|
||||||
const osTheme = window?.matchMedia('(prefers-color-scheme: dark)')?.matches
|
const osTheme = window?.matchMedia('(prefers-color-scheme: dark)')?.matches
|
||||||
? THEME_TYPE.DARK
|
? ThemeType.dark
|
||||||
: THEME_TYPE.LIGHT;
|
: ThemeType.light;
|
||||||
|
|
||||||
document.documentElement.setAttribute('data-theme', osTheme);
|
document.documentElement.setAttribute('data-theme', osTheme);
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ export default class Routes extends Component {
|
|||||||
const { theme } = this.props;
|
const { theme } = this.props;
|
||||||
|
|
||||||
if (theme !== prevProps.theme) {
|
if (theme !== prevProps.theme) {
|
||||||
if (theme === THEME_TYPE.OS) {
|
if (theme === ThemeType.OS) {
|
||||||
this.handleOsTheme();
|
this.handleOsTheme();
|
||||||
} else {
|
} else {
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
@ -160,7 +160,7 @@ export default class Routes extends Component {
|
|||||||
pageChanged(locationObj.pathname);
|
pageChanged(locationObj.pathname);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (theme === THEME_TYPE.OS) {
|
if (theme === ThemeType.os) {
|
||||||
this.handleOsTheme();
|
this.handleOsTheme();
|
||||||
} else {
|
} else {
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
getNumberOfSettingsInSection,
|
getNumberOfSettingsInSection,
|
||||||
handleSettingsRefs,
|
handleSettingsRefs,
|
||||||
} from '../../../helpers/utils/settings-search';
|
} from '../../../helpers/utils/settings-search';
|
||||||
import { THEME_TYPE } from './settings-tab.constant';
|
import { ThemeType } from '../../../../shared/constants/preferences';
|
||||||
|
|
||||||
const sortedCurrencies = availableCurrencies.sort((a, b) => {
|
const sortedCurrencies = availableCurrencies.sort((a, b) => {
|
||||||
return a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase());
|
return a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase());
|
||||||
@ -336,15 +336,15 @@ export default class SettingsTab extends PureComponent {
|
|||||||
const themesOptions = [
|
const themesOptions = [
|
||||||
{
|
{
|
||||||
name: t('lightTheme'),
|
name: t('lightTheme'),
|
||||||
value: THEME_TYPE.LIGHT,
|
value: ThemeType.light,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: t('darkTheme'),
|
name: t('darkTheme'),
|
||||||
value: THEME_TYPE.DARK,
|
value: ThemeType.dark,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: t('osTheme'),
|
name: t('osTheme'),
|
||||||
value: THEME_TYPE.OS,
|
value: ThemeType.os,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
export const THEME_TYPE = {
|
|
||||||
LIGHT: 'light',
|
|
||||||
DARK: 'dark',
|
|
||||||
OS: 'os',
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user