2022-02-22 21:58:21 +01:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
2021-02-04 19:15:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useSelector } from 'react-redux';
|
2020-05-08 21:45:52 +02:00
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
import { ALERT_TYPES } from '../../../../shared/constants/alerts';
|
2021-02-04 19:15:23 +01:00
|
|
|
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';
|
2022-04-06 22:27:08 +02:00
|
|
|
import { handleSettingsRefs } from '../../../helpers/utils/settings-search';
|
2020-05-08 21:45:52 +02:00
|
|
|
|
2022-04-06 22:27:08 +02:00
|
|
|
const AlertSettingsEntry = ({ alertId, description, title }) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
2022-04-06 22:27:08 +02:00
|
|
|
const settingsRefs = useRef();
|
2022-02-22 21:58:21 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-04-06 22:27:08 +02:00
|
|
|
handleSettingsRefs(t, t('alerts'), settingsRefs);
|
|
|
|
}, [settingsRefs, t]);
|
2022-02-22 21:58:21 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const isEnabled = useSelector((state) => getAlertEnabledness(state)[alertId]);
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-22 21:58:21 +01:00
|
|
|
<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>
|
2020-05-08 21:45:52 +02:00
|
|
|
</>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
AlertSettingsEntry.propTypes = {
|
|
|
|
alertId: PropTypes.string.isRequired,
|
|
|
|
description: PropTypes.string.isRequired,
|
|
|
|
title: PropTypes.string.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
const AlertsTab = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
const alertConfig = {
|
|
|
|
[ALERT_TYPES.unconnectedAccount]: {
|
|
|
|
title: t('alertSettingsUnconnectedAccount'),
|
|
|
|
description: t('alertSettingsUnconnectedAccountDescription'),
|
|
|
|
},
|
2020-12-11 00:40:29 +01:00
|
|
|
[ALERT_TYPES.web3ShimUsage]: {
|
|
|
|
title: t('alertSettingsWeb3ShimUsage'),
|
|
|
|
description: t('alertSettingsWeb3ShimUsageDescription'),
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="alerts-tab__body">
|
2022-02-22 21:58:21 +01:00
|
|
|
{Object.entries(alertConfig).map(
|
2022-04-06 22:27:08 +02:00
|
|
|
([alertId, { title, description }], _) => (
|
2022-02-22 21:58:21 +01:00
|
|
|
<AlertSettingsEntry
|
|
|
|
description={description}
|
|
|
|
key={alertId}
|
|
|
|
title={title}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
)}
|
2020-05-08 21:45:52 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-05-08 21:45:52 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default AlertsTab;
|