2020-05-21 17:26:49 +02:00
|
|
|
import React from 'react'
|
2020-05-08 21:45:52 +02:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
|
|
|
|
|
|
import { ALERT_TYPES } from '../../../../../app/scripts/controllers/alert'
|
|
|
|
import Tooltip from '../../../components/ui/tooltip-v2'
|
|
|
|
import ToggleButton from '../../../components/ui/toggle-button'
|
|
|
|
import { setAlertEnabledness } from '../../../store/actions'
|
|
|
|
import { getAlertEnabledness } from '../../../ducks/metamask/metamask'
|
2020-05-21 17:26:49 +02:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext'
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
const AlertSettingsEntry = ({ alertId, description, title }) => {
|
2020-05-21 17:26:49 +02:00
|
|
|
const t = useI18nContext()
|
2020-05-08 21:45:52 +02:00
|
|
|
const dispatch = useDispatch()
|
|
|
|
const isEnabled = useSelector((state) => getAlertEnabledness(state)[alertId])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<span>
|
|
|
|
{ title }
|
|
|
|
</span>
|
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={description}
|
|
|
|
wrapperClassName="alerts-tab__description"
|
|
|
|
>
|
|
|
|
<i className="fa fa-info-circle" />
|
|
|
|
</Tooltip>
|
|
|
|
<ToggleButton
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
onToggle={() => dispatch(setAlertEnabledness(alertId, !isEnabled))}
|
|
|
|
value={isEnabled}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertSettingsEntry.propTypes = {
|
|
|
|
alertId: PropTypes.string.isRequired,
|
|
|
|
description: PropTypes.string.isRequired,
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
const AlertsTab = () => {
|
2020-05-21 17:26:49 +02:00
|
|
|
const t = useI18nContext()
|
2020-05-08 21:45:52 +02:00
|
|
|
|
|
|
|
const alertConfig = {
|
2020-05-12 15:01:52 +02:00
|
|
|
[ALERT_TYPES.switchToConnected]: {
|
|
|
|
title: t('alertSettingsSwitchToConnected'),
|
|
|
|
description: t('alertSettingsSwitchToConnectedDescription'),
|
|
|
|
},
|
2020-05-08 21:45:52 +02:00
|
|
|
[ALERT_TYPES.unconnectedAccount]: {
|
|
|
|
title: t('alertSettingsUnconnectedAccount'),
|
|
|
|
description: t('alertSettingsUnconnectedAccountDescription'),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|