You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.6 KiB
113 lines
3.6 KiB
4 years ago
|
import React, { useState } from 'react';
|
||
|
import { useDispatch, useSelector } from 'react-redux';
|
||
5 years ago
|
|
||
4 years ago
|
import { ALERT_STATE } from '../../../../ducks/alerts';
|
||
5 years ago
|
import {
|
||
|
connectAccount,
|
||
|
dismissAlert,
|
||
5 years ago
|
dismissAndDisableAlert,
|
||
5 years ago
|
getAlertState,
|
||
5 years ago
|
switchToAccount,
|
||
4 years ago
|
} from '../../../../ducks/alerts/unconnected-account';
|
||
5 years ago
|
import {
|
||
|
getOriginOfCurrentTab,
|
||
5 years ago
|
getOrderedConnectedAccountsForActiveTab,
|
||
5 years ago
|
getSelectedAddress,
|
||
|
getSelectedIdentity,
|
||
4 years ago
|
} from '../../../../selectors';
|
||
|
import { isExtensionUrl } from '../../../../helpers/utils/util';
|
||
|
import Popover from '../../../ui/popover';
|
||
|
import Button from '../../../ui/button';
|
||
|
import Checkbox from '../../../ui/check-box';
|
||
|
import Tooltip from '../../../ui/tooltip';
|
||
|
import ConnectedAccountsList from '../../connected-accounts-list';
|
||
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
||
5 years ago
|
|
||
4 years ago
|
const { ERROR, LOADING } = ALERT_STATE;
|
||
5 years ago
|
|
||
5 years ago
|
const UnconnectedAccountAlert = () => {
|
||
4 years ago
|
const t = useI18nContext();
|
||
|
const dispatch = useDispatch();
|
||
|
const alertState = useSelector(getAlertState);
|
||
|
const connectedAccounts = useSelector(
|
||
|
getOrderedConnectedAccountsForActiveTab,
|
||
|
);
|
||
|
const origin = useSelector(getOriginOfCurrentTab);
|
||
|
const selectedIdentity = useSelector(getSelectedIdentity);
|
||
|
const selectedAddress = useSelector(getSelectedAddress);
|
||
|
const [dontShowThisAgain, setDontShowThisAgain] = useState(false);
|
||
5 years ago
|
|
||
|
const onClose = async () => {
|
||
|
return dontShowThisAgain
|
||
|
? await dispatch(dismissAndDisableAlert())
|
||
4 years ago
|
: dispatch(dismissAlert());
|
||
|
};
|
||
5 years ago
|
|
||
5 years ago
|
const footer = (
|
||
|
<>
|
||
4 years ago
|
{alertState === ERROR ? (
|
||
|
<div className="unconnected-account-alert__error">
|
||
|
{t('failureMessage')}
|
||
|
</div>
|
||
|
) : null}
|
||
5 years ago
|
<div className="unconnected-account-alert__footer-row">
|
||
|
<div className="unconnected-account-alert__checkbox-wrapper">
|
||
|
<Checkbox
|
||
|
id="unconnectedAccount_dontShowThisAgain"
|
||
|
checked={dontShowThisAgain}
|
||
|
className="unconnected-account-alert__checkbox"
|
||
|
onClick={() => setDontShowThisAgain((checked) => !checked)}
|
||
|
/>
|
||
|
<label
|
||
|
className="unconnected-account-alert__checkbox-label"
|
||
|
htmlFor="unconnectedAccount_dontShowThisAgain"
|
||
|
>
|
||
4 years ago
|
{t('dontShowThisAgain')}
|
||
5 years ago
|
<Tooltip
|
||
|
position="top"
|
||
|
title={t('alertDisableTooltip')}
|
||
|
wrapperClassName="unconnected-account-alert__checkbox-label-tooltip"
|
||
|
>
|
||
|
<i className="fa fa-info-circle" />
|
||
|
</Tooltip>
|
||
|
</label>
|
||
|
</div>
|
||
|
<Button
|
||
|
disabled={alertState === LOADING}
|
||
|
onClick={onClose}
|
||
4 years ago
|
type="primary"
|
||
|
rounded
|
||
5 years ago
|
className="unconnected-account-alert__dismiss-button"
|
||
|
>
|
||
4 years ago
|
{t('dismiss')}
|
||
5 years ago
|
</Button>
|
||
|
</div>
|
||
|
</>
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
5 years ago
|
return (
|
||
|
<Popover
|
||
4 years ago
|
title={
|
||
|
isExtensionUrl(origin) ? t('currentExtension') : new URL(origin).host
|
||
|
}
|
||
5 years ago
|
subtitle={t('currentAccountNotConnected')}
|
||
5 years ago
|
onClose={onClose}
|
||
4 years ago
|
className="unconnected-account-alert"
|
||
5 years ago
|
contentClassName="unconnected-account-alert__content"
|
||
5 years ago
|
footerClassName="unconnected-account-alert__footer"
|
||
5 years ago
|
footer={footer}
|
||
5 years ago
|
>
|
||
5 years ago
|
<ConnectedAccountsList
|
||
|
accountToConnect={selectedIdentity}
|
||
|
connectAccount={() => dispatch(connectAccount(selectedAddress))}
|
||
|
connectedAccounts={connectedAccounts}
|
||
|
selectedAddress={selectedAddress}
|
||
|
setSelectedAddress={(address) => dispatch(switchToAccount(address))}
|
||
|
shouldRenderListOptions={false}
|
||
5 years ago
|
/>
|
||
|
</Popover>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
4 years ago
|
export default UnconnectedAccountAlert;
|