1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/pages/settings/alerts-tab/alerts-tab.js
Hassan Malik e0e466490e
Settings search refactor (#14350)
* removed unnecessary eslint disable and removed key prop from SettingsSearchList

* removed unnecessary function, refactored settings pages to use only handleSettingsRefs

* simplified utils, removed unnecessary test

* updated usage of util functions

* fixed type error, allow for ampersand in search input

* removed unnecessary var

* fixed test

* fixes per comments

* fixed var name

* fixed property name

* changed some properties in SETTINGS_CONSTANTS to accept t param

* redid util functions

* changed from multiline comment to single line

* replace empty descriptions

* updated util logic

* fix undefined issue
2022-04-06 16:27:08 -04:00

83 lines
2.4 KiB
JavaScript

import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { ALERT_TYPES } from '../../../../shared/constants/alerts';
import Tooltip from '../../../components/ui/tooltip';
import ToggleButton from '../../../components/ui/toggle-button';
import { setAlertEnabledness } from '../../../store/actions';
import { getAlertEnabledness } from '../../../ducks/metamask/metamask';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { handleSettingsRefs } from '../../../helpers/utils/settings-search';
const AlertSettingsEntry = ({ alertId, description, title }) => {
const t = useI18nContext();
const settingsRefs = useRef();
useEffect(() => {
handleSettingsRefs(t, t('alerts'), settingsRefs);
}, [settingsRefs, t]);
const isEnabled = useSelector((state) => getAlertEnabledness(state)[alertId]);
return (
<>
<div ref={settingsRefs} className="alerts-tab__item">
<span>{title}</span>
<div className="alerts-tab__description-container">
<Tooltip
position="top"
title={description}
wrapperClassName="alerts-tab__description"
>
<i className="fa fa-info-circle" />
</Tooltip>
<ToggleButton
offLabel={t('off')}
onLabel={t('on')}
onToggle={() => setAlertEnabledness(alertId, !isEnabled)}
value={isEnabled}
/>
</div>
</div>
</>
);
};
AlertSettingsEntry.propTypes = {
alertId: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
};
const AlertsTab = () => {
const t = useI18nContext();
const alertConfig = {
[ALERT_TYPES.unconnectedAccount]: {
title: t('alertSettingsUnconnectedAccount'),
description: t('alertSettingsUnconnectedAccountDescription'),
},
[ALERT_TYPES.web3ShimUsage]: {
title: t('alertSettingsWeb3ShimUsage'),
description: t('alertSettingsWeb3ShimUsageDescription'),
},
};
return (
<div className="alerts-tab__body">
{Object.entries(alertConfig).map(
([alertId, { title, description }], _) => (
<AlertSettingsEntry
description={description}
key={alertId}
title={title}
/>
),
)}
</div>
);
};
export default AlertsTab;