AccountsList.js 3.42 KiB
Newer Older
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
Amaury Martiny's avatar
Amaury Martiny committed
// SPDX-License-Identifier: BSD-3-Clause
Axel Chalon's avatar
Axel Chalon committed
import React, { Component } from 'react';
Amaury Martiny's avatar
Amaury Martiny committed
import { AccountCard, Clickable, Header } from 'fether-ui';
import { chainId$ } from '@parity/light.js';
Axel Chalon's avatar
Axel Chalon committed
import { inject, observer } from 'mobx-react';
import light from '@parity/light.js-react';
import i18n, { packageNS } from '../../i18n';
import RequireHealthOverlay from '../../RequireHealthOverlay';
Axel Chalon's avatar
Axel Chalon committed
import Health from '../../Health';
import withAccountsInfo from '../../utils/withAccountsInfo';
import Feedback from './Feedback';
@withAccountsInfo
Axel Chalon's avatar
Axel Chalon committed
@inject('createAccountStore', 'parityStore')
  chainId: () => chainId$()
@observer
class AccountsList extends Component {
  handleClick = ({
    currentTarget: {
      dataset: { address }
    }
  }) => {
Axel Chalon's avatar
Axel Chalon committed
    const { history } = this.props;
Axel Chalon's avatar
Axel Chalon committed
    history.push(`/tokens/${address}`);
  };

  handleCreateAccount = () => {
Amaury Martiny's avatar
Amaury Martiny committed
    this.props.createAccountStore.setIsImport(false);
Axel Chalon's avatar
Axel Chalon committed
    this.props.history.push('/accounts/new');
Axel Chalon's avatar
Axel Chalon committed
  render () {
    const { accountsInfo, chainId } = this.props;
Axel Chalon's avatar
Axel Chalon committed
    const accountsList = Object.keys(accountsInfo).filter(
      key =>
        !accountsInfo[key].chainId ||
        accountsInfo[key].chainId === parseInt(chainId, 10)
    const accountsListLength = accountsList && accountsList.length;
    return (
      <RequireHealthOverlay require='node'>
        <div className='accounts-list'>
          <Header
            right={
              <Clickable
                className='icon -new'
                onClick={this.handleCreateAccount}
              />
            }
            title={<h1>{i18n.t(`${packageNS}:accounts_list.header`)}</h1>}
          <div className='window_content'>
            <div className='box -scroller'>
              {accountsListLength ? (
                <ul className='list'>
                  {accountsList.map(address => (
                    <li
                      key={address}
                      data-address={address} // Using data- to avoid creating a new item Component
                      onClick={this.handleClick}
                    >
                      <AccountCard
                        address={address}
                        className='-clickable'
                        i18n={i18n}
                        name={
                          accountsInfo[address].name ||
                          i18n.t(`${packageNS}:account.existing.no_name`)
                        }
                        packageNS={packageNS}
                        type={accountsInfo[address].type}
                  {i18n.t(`${packageNS}:accounts_list.hint.none`)}
                  {i18n.t(`${packageNS}:accounts_list.hint.exist`)}
          </div>
Thibaut Sardan's avatar
Thibaut Sardan committed
          <nav className='footer-nav'>
            <div className='footer-nav_status'>
              <Health />
            </div>
            <div className='footer-feedback'>
              <Feedback accountsListLength={accountsListLength} />
            </div>
          </nav>
    );
  }
}

export default AccountsList;