TokensList.js 1.82 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
Amaury Martiny's avatar
Amaury Martiny committed
import React, { Component } from 'react';
import { Modal } from 'fether-ui';
import RequireHealthOverlay from '../../RequireHealthOverlay';
Amaury Martiny's avatar
Amaury Martiny committed
import TokenBalance from './TokenBalance';
import withTokens from '../../utils/withTokens';
import loading from '../../assets/img/icons/loading.svg';
Axel Chalon's avatar
Axel Chalon committed

Amaury Martiny's avatar
Amaury Martiny committed
@withTokens
Axel Chalon's avatar
Axel Chalon committed
class TokensList extends Component {
  state = {
    isLoadingAccountTokens: true
  };

  hideLoadingAccountTokensModal = () => {
    this.setState({ isLoadingAccountTokens: false });
  };

Amaury Martiny's avatar
Amaury Martiny committed
  render () {
Axel Chalon's avatar
Axel Chalon committed
    const { tokensArray } = this.props;
    const { isLoadingAccountTokens } = this.state;
    // Show empty token placeholder if tokens have not been loaded yet
    const shownArray = tokensArray.length ? tokensArray : [{}];
    return (
        <Modal
          description='Please wait...'
          fullscreen={false}
          icon={loading}
          title='Loading account tokens...'
          visible={isLoadingAccountTokens}
        />
Thibaut Sardan's avatar
Thibaut Sardan committed
        <div className='window_content'>
          <div className='box -scroller'>
            <ul className='list -padded'>
              {shownArray.map((
                token,
                index // With empty tokens, the token.address is not defined, so we prefix with index
              ) => (
                <li key={`${index}-${token.address}`}>
                  <TokenBalance
                    hideLoadingAccountTokensModal={
                      this.hideLoadingAccountTokensModal
                    }
                    token={token}
                  />
Thibaut Sardan's avatar
Thibaut Sardan committed
                </li>
              ))}
            </ul>
          </div>
        </div>
Axel Chalon's avatar
Axel Chalon committed
export default TokensList;