2019-07-31 21:56:44 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import ContactList from '../../../components/app/contact-list'
|
|
|
|
import {
|
|
|
|
CONTACT_ADD_ROUTE,
|
|
|
|
CONTACT_VIEW_ROUTE,
|
|
|
|
CONTACT_MY_ACCOUNTS_ROUTE,
|
|
|
|
} from '../../../helpers/constants/routes'
|
2020-08-18 21:18:25 +02:00
|
|
|
import EditContact from './edit-contact'
|
|
|
|
import AddContact from './add-contact'
|
|
|
|
import ViewContact from './view-contact'
|
|
|
|
import MyAccounts from './my-accounts'
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
export default class ContactListTab extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
addressBook: PropTypes.array,
|
|
|
|
history: PropTypes.object,
|
|
|
|
selectedAddress: PropTypes.string,
|
|
|
|
viewingContact: PropTypes.bool,
|
|
|
|
editingContact: PropTypes.bool,
|
|
|
|
addingContact: PropTypes.bool,
|
|
|
|
showContactContent: PropTypes.bool,
|
|
|
|
hideAddressBook: PropTypes.bool,
|
|
|
|
showingMyAccounts: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAddresses() {
|
2019-07-31 21:56:44 +02:00
|
|
|
const { addressBook, history, selectedAddress } = this.props
|
2020-08-19 18:27:05 +02:00
|
|
|
const contacts = addressBook.filter(({ name }) => Boolean(name))
|
2019-07-31 21:56:44 +02:00
|
|
|
const nonContacts = addressBook.filter(({ name }) => !name)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ContactList
|
|
|
|
searchForContacts={() => contacts}
|
|
|
|
searchForRecents={() => nonContacts}
|
|
|
|
selectRecipient={(address) => {
|
|
|
|
history.push(`${CONTACT_VIEW_ROUTE}/${address}`)
|
|
|
|
}}
|
|
|
|
selectedAddress={selectedAddress}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAddButton() {
|
2019-07-31 21:56:44 +02:00
|
|
|
const { history } = this.props
|
2019-12-03 17:35:44 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="address-book-add-button__button"
|
|
|
|
onClick={() => {
|
|
|
|
history.push(CONTACT_ADD_ROUTE)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
className="account-menu__item-icon"
|
|
|
|
src="images/plus-btn-white.svg"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderMyAccountsButton() {
|
2019-07-31 21:56:44 +02:00
|
|
|
const { history } = this.props
|
|
|
|
const { t } = this.context
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="address-book__my-accounts-button"
|
|
|
|
onClick={() => {
|
|
|
|
history.push(CONTACT_MY_ACCOUNTS_ROUTE)
|
|
|
|
}}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="address-book__my-accounts-button__header">
|
|
|
|
{t('myWalletAccounts')}
|
|
|
|
</div>
|
2019-07-31 21:56:44 +02:00
|
|
|
<div className="address-book__my-accounts-button__content">
|
|
|
|
<div className="address-book__my-accounts-button__text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('myWalletAccountsDescription')}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
|
|
|
<div className="address-book__my-accounts-button__caret" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderContactContent() {
|
|
|
|
const {
|
|
|
|
viewingContact,
|
|
|
|
editingContact,
|
|
|
|
addingContact,
|
|
|
|
showContactContent,
|
|
|
|
} = this.props
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
if (!showContactContent) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
let ContactContentComponent = null
|
|
|
|
if (viewingContact) {
|
|
|
|
ContactContentComponent = ViewContact
|
|
|
|
} else if (editingContact) {
|
|
|
|
ContactContentComponent = EditContact
|
|
|
|
} else if (addingContact) {
|
|
|
|
ContactContentComponent = AddContact
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
ContactContentComponent && (
|
|
|
|
<div className="address-book-contact-content">
|
|
|
|
<ContactContentComponent />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderAddressBookContent() {
|
2019-07-31 21:56:44 +02:00
|
|
|
const { hideAddressBook, showingMyAccounts } = this.props
|
|
|
|
|
|
|
|
if (!hideAddressBook && !showingMyAccounts) {
|
2019-12-03 17:35:44 +01:00
|
|
|
return (
|
|
|
|
<div className="address-book">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderMyAccountsButton()}
|
|
|
|
{this.renderAddresses()}
|
2019-12-03 17:35:44 +01:00
|
|
|
</div>
|
|
|
|
)
|
2019-07-31 21:56:44 +02:00
|
|
|
} else if (!hideAddressBook && showingMyAccounts) {
|
2020-11-03 00:41:28 +01:00
|
|
|
return <MyAccounts />
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
2020-08-12 21:06:57 +02:00
|
|
|
return null
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2019-07-31 21:56:44 +02:00
|
|
|
const { addingContact } = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="address-book-wrapper">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAddressBookContent()}
|
|
|
|
{this.renderContactContent()}
|
2019-12-03 17:35:44 +01:00
|
|
|
{!addingContact && (
|
|
|
|
<div className="address-book-add-button">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAddButton()}
|
2019-12-03 17:35:44 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|