AccountsList.js 2.36 KiB
Newer Older
// 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
Axel Chalon's avatar
Axel Chalon committed
import React, { Component } from "react";
import { AccountCard, Header } from "fether-ui";
import { accountsInfo$ } from "@parity/light.js";
import { inject, observer } from "mobx-react";
import light from "light-hoc";
Axel Chalon's avatar
Axel Chalon committed
import Health from "../../Health";
Axel Chalon's avatar
Axel Chalon committed
  accountsInfo: accountsInfo$
Axel Chalon's avatar
Axel Chalon committed
@inject("createAccountStore", "parityStore")
@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 } = this.props;

    return (
      <div>
        <Header
          title={<h1>Accounts</h1>}
          right={
Axel Chalon's avatar
Axel Chalon committed
            <a className="icon -new" onClick={this.handleCreateAccount}>
              New account
            </a>
Axel Chalon's avatar
Axel Chalon committed
        <div className="window_content">
          <div className="box -scroller">
            <ul className="list">
              {accountsInfo ? (
                Object.keys(accountsInfo).map(address => (
                  <li
                    key={address}
                    data-address={address} // Using data- to avoid creating a new item Component
                    onClick={this.handleClick}
                  >
Amaury Martiny's avatar
Amaury Martiny committed
                    <AccountCard
                      address={address}
Axel Chalon's avatar
Axel Chalon committed
                      className="-clickable"
Amaury Martiny's avatar
Amaury Martiny committed
                      name={
                        accountsInfo &&
                        accountsInfo[address] &&
                        (accountsInfo[address].name
                          ? accountsInfo[address].name
Axel Chalon's avatar
Axel Chalon committed
                          : "(No name)")
Amaury Martiny's avatar
Amaury Martiny committed
                      }
                      shortAddress
Amaury Martiny's avatar
Amaury Martiny committed
                    />
                  </li>
                ))
              ) : (
                <li>
                  <AccountCard />
                </li>
              )}
            </ul>
          </div>
        </div>

Axel Chalon's avatar
Axel Chalon committed
        <nav className="footer-nav">
          <div className="footer-nav_status">
            <Health />
          </div>
        </nav>
      </div>
    );
  }
}

export default AccountsList;