mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
6535e34943
* replace all fa-icon-circle with INFO icon * updated classnames * updated classnames * updated snapshots * updated colors * resolved errors * fixed relative import * fixed lint errors * added story for alerts tab * update snapshot * updated info-circle * updated enum for iconName * removed classnames * updated iconName in settings * fixed lint errors and snapshots
88 lines
2.5 KiB
JavaScript
88 lines
2.5 KiB
JavaScript
import React, { useEffect, useRef } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { AlertTypes } 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';
|
|
import { Icon, IconName } from '../../../components/component-library';
|
|
|
|
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"
|
|
>
|
|
<Icon
|
|
name={IconName.Info}
|
|
className="alerts-tab__description__icon"
|
|
/>
|
|
</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 = {
|
|
[AlertTypes.unconnectedAccount]: {
|
|
title: t('alertSettingsUnconnectedAccount'),
|
|
description: t('alertSettingsUnconnectedAccountDescription'),
|
|
},
|
|
[AlertTypes.web3ShimUsage]: {
|
|
title: t('alertSettingsWeb3ShimUsage'),
|
|
description: t('alertSettingsWeb3ShimUsageDescription'),
|
|
},
|
|
};
|
|
|
|
return (
|
|
<div className="alerts-tab__body">
|
|
{Object.entries(alertConfig).map(
|
|
([alertId, { title, description }], _) => (
|
|
<AlertSettingsEntry
|
|
alertId={alertId}
|
|
description={description}
|
|
key={alertId}
|
|
title={title}
|
|
/>
|
|
),
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default AlertsTab;
|