Skip to content
AccountCard.js 1.78 KiB
Newer Older
Amaury Martiny's avatar
Amaury Martiny committed
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
Amaury Martiny's avatar
Amaury Martiny committed
// SPDX-License-Identifier: BSD-3-Clause
Amaury Martiny's avatar
Amaury Martiny committed

import React from 'react';
import PropTypes from 'prop-types';
import { Clickable, ClickToCopy } from 'fether-ui';
Amaury Martiny's avatar
Amaury Martiny committed

Amaury Martiny's avatar
Amaury Martiny committed
import { Address } from './Address';
import { Avatar } from './Avatar';
import { Card } from '../Card';
Amaury Martiny's avatar
Amaury Martiny committed
import { Information } from './Information';
import { Name } from './Name';
Amaury Martiny's avatar
Amaury Martiny committed

const CopyContainer = ({ address, children, ...otherProps }) => (
  <ClickToCopy label='Copy address' textToCopy={address} {...otherProps}>
    <Clickable>{children}</Clickable>
  </ClickToCopy>
);

const CardContents = ({ address, name, screen, shortAddress, type }) => (
  <div className='account'>
    <Avatar address={address} type={type} />
    <Information>
      <Name name={name} screen={screen} />
      <Address address={address} screen={screen} short={shortAddress} />
    </Information>
  </div>
);

export const AccountCard = ({
  address,
  shortAddress,
  ...otherProps
}) => (
Amaury Martiny's avatar
Amaury Martiny committed
  <Card {...otherProps}>
    {copyAddress ? (
      <CopyContainer address={address}>
        <CardContents
          address={address}
          name={name}
          screen={screen}
          shortAddress={shortAddress}
          type={type}
        />
      </CopyContainer>
    ) : (
      <CardContents
        address={address}
        name={name}
        screen={screen}
        shortAddress={shortAddress}
        type={type}
      />
    )}
Amaury Martiny's avatar
Amaury Martiny committed
  </Card>
);

AccountCard.Address = Address;
AccountCard.Avatar = Avatar;
AccountCard.Information = Information;
AccountCard.Name = Name;

Amaury Martiny's avatar
Amaury Martiny committed
AccountCard.propTypes = {
  address: PropTypes.string,
  name: PropTypes.string,
  shortAddress: PropTypes.bool
Amaury Martiny's avatar
Amaury Martiny committed
};