2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Identicon from '../../../ui/identicon';
|
|
|
|
import { ellipsify } from '../../../../pages/send/send.utils';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function addressesEqual(address1, address2) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return String(address1).toLowerCase() === String(address2).toLowerCase();
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function RecipientGroup({
|
|
|
|
label,
|
|
|
|
items,
|
|
|
|
onSelect,
|
|
|
|
selectedAddress,
|
|
|
|
}) {
|
2019-07-31 21:56:44 +02:00
|
|
|
if (!items || !items.length) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return null;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-09-03 21:31:12 +02:00
|
|
|
<div
|
|
|
|
className="send__select-recipient-wrapper__group"
|
|
|
|
data-testid="recipient-group"
|
|
|
|
>
|
2019-12-03 17:35:44 +01:00
|
|
|
{label && (
|
|
|
|
<div className="send__select-recipient-wrapper__group-label">
|
|
|
|
{label}
|
|
|
|
</div>
|
|
|
|
)}
|
2020-11-03 00:41:28 +01:00
|
|
|
{items.map(({ address, name }) => (
|
|
|
|
<div
|
|
|
|
key={address}
|
|
|
|
onClick={() => onSelect(address, name)}
|
|
|
|
className={classnames({
|
|
|
|
'send__select-recipient-wrapper__group-item': !addressesEqual(
|
|
|
|
address,
|
|
|
|
selectedAddress,
|
|
|
|
),
|
2022-07-31 20:26:40 +02:00
|
|
|
'send__select-recipient-wrapper__group-item--selected':
|
|
|
|
addressesEqual(address, selectedAddress),
|
2020-11-03 00:41:28 +01:00
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Identicon address={address} diameter={28} />
|
2021-09-03 21:31:12 +02:00
|
|
|
<div
|
|
|
|
className="send__select-recipient-wrapper__group-item__content"
|
|
|
|
data-testid="recipient"
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="send__select-recipient-wrapper__group-item__title">
|
|
|
|
{name || ellipsify(address)}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
{name && (
|
|
|
|
<div className="send__select-recipient-wrapper__group-item__subtitle">
|
|
|
|
{ellipsify(address)}
|
|
|
|
</div>
|
|
|
|
)}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
</div>
|
|
|
|
))}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
RecipientGroup.propTypes = {
|
|
|
|
label: PropTypes.string,
|
2020-11-03 00:41:28 +01:00
|
|
|
items: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string,
|
|
|
|
}),
|
|
|
|
),
|
2019-07-31 21:56:44 +02:00
|
|
|
onSelect: PropTypes.func.isRequired,
|
|
|
|
selectedAddress: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|