2021-02-04 19:15:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import Popover from '../../components/ui/popover';
|
|
|
|
import ConnectedAccountsList from '../../components/app/connected-accounts-list';
|
|
|
|
import ConnectedAccountsPermissions from '../../components/app/connected-accounts-permissions';
|
2021-08-25 00:28:16 +02:00
|
|
|
import { getURLHost } from '../../helpers/utils/util';
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
export default class ConnectedAccounts extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
accountToConnect: null,
|
|
|
|
permissions: undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accountToConnect: PropTypes.object,
|
|
|
|
activeTabOrigin: PropTypes.string.isRequired,
|
2020-06-15 21:08:53 +02:00
|
|
|
connectAccount: PropTypes.func.isRequired,
|
2020-05-15 20:53:52 +02:00
|
|
|
connectedAccounts: PropTypes.array.isRequired,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2020-05-15 20:53:52 +02:00
|
|
|
permissions: PropTypes.array,
|
2020-05-29 19:12:14 +02:00
|
|
|
isActiveTabExtension: PropTypes.bool.isRequired,
|
2020-05-15 20:53:52 +02:00
|
|
|
selectedAddress: PropTypes.string.isRequired,
|
|
|
|
removePermittedAccount: PropTypes.func.isRequired,
|
|
|
|
setSelectedAddress: PropTypes.func.isRequired,
|
|
|
|
history: PropTypes.object.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2020-05-15 20:53:52 +02:00
|
|
|
const {
|
|
|
|
accountToConnect,
|
|
|
|
activeTabOrigin,
|
2020-05-29 19:12:14 +02:00
|
|
|
isActiveTabExtension,
|
2020-06-15 21:08:53 +02:00
|
|
|
connectAccount,
|
2020-05-15 20:53:52 +02:00
|
|
|
connectedAccounts,
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2020-05-15 20:53:52 +02:00
|
|
|
permissions,
|
|
|
|
selectedAddress,
|
|
|
|
removePermittedAccount,
|
|
|
|
setSelectedAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { t } = this.context;
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const connectedAccountsDescription =
|
|
|
|
connectedAccounts.length > 1
|
|
|
|
? t('connectedAccountsDescriptionPlural', [connectedAccounts.length])
|
2021-02-04 19:15:23 +01:00
|
|
|
: t('connectedAccountsDescriptionSingular');
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Popover
|
2020-11-03 00:41:28 +01:00
|
|
|
title={
|
|
|
|
isActiveTabExtension
|
|
|
|
? t('currentExtension')
|
2021-08-25 00:28:16 +02:00
|
|
|
: getURLHost(activeTabOrigin)
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
|
|
|
subtitle={
|
|
|
|
connectedAccounts.length
|
|
|
|
? connectedAccountsDescription
|
|
|
|
: t('connectedAccountsEmptyDescription')
|
|
|
|
}
|
2020-06-01 19:54:32 +02:00
|
|
|
onClose={() => history.push(mostRecentOverviewPage)}
|
2020-05-15 20:53:52 +02:00
|
|
|
footerClassName="connected-accounts__footer"
|
2023-07-17 20:12:45 +02:00
|
|
|
footer={
|
2023-08-25 12:40:28 +02:00
|
|
|
permissions?.length > 0 && (
|
2023-07-17 20:12:45 +02:00
|
|
|
<ConnectedAccountsPermissions permissions={permissions} />
|
2023-08-25 12:40:28 +02:00
|
|
|
)
|
2023-07-17 20:12:45 +02:00
|
|
|
}
|
2020-05-15 20:53:52 +02:00
|
|
|
>
|
|
|
|
<ConnectedAccountsList
|
|
|
|
accountToConnect={accountToConnect}
|
2020-06-15 21:08:53 +02:00
|
|
|
connectAccount={connectAccount}
|
2020-05-15 20:53:52 +02:00
|
|
|
connectedAccounts={connectedAccounts}
|
|
|
|
selectedAddress={selectedAddress}
|
|
|
|
removePermittedAccount={removePermittedAccount}
|
|
|
|
setSelectedAddress={setSelectedAddress}
|
2020-06-15 21:08:53 +02:00
|
|
|
shouldRenderListOptions
|
2020-05-15 20:53:52 +02:00
|
|
|
/>
|
|
|
|
</Popover>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-05-15 20:53:52 +02:00
|
|
|
}
|
|
|
|
}
|