2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
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';
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
const AlertSettingsEntry = ({ alertId, description, title }) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
|
|
|
const isEnabled = useSelector((state) => getAlertEnabledness(state)[alertId]);
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-11-03 00:41:28 +01:00
|
|
|
<span>{title}</span>
|
2020-05-08 21:45:52 +02:00
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={description}
|
|
|
|
wrapperClassName="alerts-tab__description"
|
|
|
|
>
|
|
|
|
<i className="fa fa-info-circle" />
|
|
|
|
</Tooltip>
|
|
|
|
<ToggleButton
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
2020-12-11 00:40:29 +01:00
|
|
|
onToggle={() => setAlertEnabledness(alertId, !isEnabled)}
|
2020-05-08 21:45:52 +02:00
|
|
|
value={isEnabled}
|
|
|
|
/>
|
|
|
|
</>
|
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">
|
2020-11-03 00:41:28 +01:00
|
|
|
{Object.entries(alertConfig).map(([alertId, { title, description }]) => (
|
|
|
|
<AlertSettingsEntry
|
|
|
|
alertId={alertId}
|
|
|
|
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;
|