2020-05-15 20:53:52 +02:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import React, { PureComponent } from 'react'
|
2020-06-01 19:54:32 +02:00
|
|
|
import { CONNECTED_ROUTE } from '../../helpers/constants/routes'
|
2020-05-15 20:53:52 +02:00
|
|
|
import Popover from '../../components/ui/popover'
|
|
|
|
import ConnectedAccountsList from '../../components/app/connected-accounts-list'
|
|
|
|
|
|
|
|
export default class ConnectedAccounts extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
accountToConnect: null,
|
|
|
|
permissions: undefined,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accountToConnect: PropTypes.object,
|
|
|
|
activeTabOrigin: PropTypes.string.isRequired,
|
|
|
|
addPermittedAccount: PropTypes.func.isRequired,
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
viewConnectedSites = () => {
|
|
|
|
this.props.history.push(CONNECTED_ROUTE)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
accountToConnect,
|
|
|
|
activeTabOrigin,
|
2020-05-29 19:12:14 +02:00
|
|
|
isActiveTabExtension,
|
2020-05-15 20:53:52 +02:00
|
|
|
addPermittedAccount,
|
|
|
|
connectedAccounts,
|
|
|
|
history,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2020-05-15 20:53:52 +02:00
|
|
|
permissions,
|
|
|
|
selectedAddress,
|
|
|
|
removePermittedAccount,
|
|
|
|
setSelectedAddress,
|
|
|
|
} = this.props
|
|
|
|
const { t } = this.context
|
|
|
|
|
|
|
|
const connectedAccountsDescription = connectedAccounts.length > 1
|
|
|
|
? t('connectedAccountsDescriptionPlural', [connectedAccounts.length])
|
|
|
|
: t('connectedAccountsDescriptionSingular')
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Popover
|
2020-06-09 22:56:24 +02:00
|
|
|
title={isActiveTabExtension ? t('currentExtension') : new URL(activeTabOrigin).host}
|
2020-05-15 20:53:52 +02: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"
|
|
|
|
>
|
|
|
|
<ConnectedAccountsList
|
|
|
|
accountToConnect={accountToConnect}
|
|
|
|
addPermittedAccount={addPermittedAccount}
|
|
|
|
connectedAccounts={connectedAccounts}
|
|
|
|
permissions={permissions}
|
|
|
|
selectedAddress={selectedAddress}
|
|
|
|
removePermittedAccount={removePermittedAccount}
|
|
|
|
setSelectedAddress={setSelectedAddress}
|
|
|
|
/>
|
|
|
|
</Popover>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|