1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/pages/connected-accounts/connected-accounts.component.js

82 lines
2.5 KiB
JavaScript
Raw Normal View History

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';
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,
};
2020-05-15 20:53:52 +02:00
static defaultProps = {
accountToConnect: null,
permissions: undefined,
};
2020-05-15 20:53:52 +02:00
static propTypes = {
accountToConnect: PropTypes.object,
activeTabOrigin: PropTypes.string.isRequired,
connectAccount: PropTypes.func.isRequired,
2020-05-15 20:53:52 +02:00
connectedAccounts: PropTypes.array.isRequired,
mostRecentOverviewPage: PropTypes.string.isRequired,
2020-05-15 20:53:52 +02:00
permissions: PropTypes.array,
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,
};
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,
isActiveTabExtension,
connectAccount,
2020-05-15 20:53:52 +02:00
connectedAccounts,
history,
mostRecentOverviewPage,
2020-05-15 20:53:52 +02:00
permissions,
selectedAddress,
removePermittedAccount,
setSelectedAddress,
} = 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])
: t('connectedAccountsDescriptionSingular');
2020-05-15 20:53:52 +02:00
return (
<Popover
2020-11-03 00:41:28 +01:00
title={
isActiveTabExtension
? t('currentExtension')
: getURLHost(activeTabOrigin)
2020-11-03 00:41:28 +01:00
}
subtitle={
connectedAccounts.length
? connectedAccountsDescription
: t('connectedAccountsEmptyDescription')
}
onClose={() => history.push(mostRecentOverviewPage)}
2020-05-15 20:53:52 +02:00
footerClassName="connected-accounts__footer"
footer={<ConnectedAccountsPermissions permissions={permissions} />}
2020-05-15 20:53:52 +02:00
>
<ConnectedAccountsList
accountToConnect={accountToConnect}
connectAccount={connectAccount}
2020-05-15 20:53:52 +02:00
connectedAccounts={connectedAccounts}
selectedAddress={selectedAddress}
removePermittedAccount={removePermittedAccount}
setSelectedAddress={setSelectedAddress}
shouldRenderListOptions
2020-05-15 20:53:52 +02:00
/>
</Popover>
);
2020-05-15 20:53:52 +02:00
}
}