<commit_before>// @flow
import React from 'react'
import classNames from 'classnames'
import { NavLink } from 'react-router-dom'

import TextInput from '../../Inputs/TextInput'
import CopyToClipboard from '../../CopyToClipboard'
import Panel from '../../Panel'
import styles from './TokenBalancesPanel.scss'
import {
  toFixedDecimals,
  formatToRoundedShortNumber
} from '../../../core/formatters'
import { toBigNumber } from '../../../core/math'
import Nothing from '../../../assets/icons/nothing.svg'
import { CURRENCIES, ROUTES, PRICE_UNAVAILABLE } from '../../../core/constants'

type Props = {
  className: ?string,
  balances: Array<TokenBalanceType>,
  prices: Object,
  currencyCode: string,
  address: string
}

export default class TokenBalancesPanel extends React.Component<Props> {
  static defaultProps = {
    loading: false
  }

  render = () => {
    const { className, balances } = this.props
    return (
      <Panel
        className={classNames(styles.tokenBalancesPanel, className)}
        contentClassName={classNames(styles.tokenBalancesPanelContent, {
          [styles.emptyBalanceContent]: !balances.length
        })}
        headerClassName={styles.headerStyle}
        renderHeader={this.renderHeader}
      >
        {balances.length
          ? this.renderTokenBalances()
          : this.renderEmptyBalanceInfo()}
      </Panel>
    )
  }

  renderEmptyBalanceInfo = () => {
    const { address } = this.props
    return (
      <div className={styles.emptyBalanceContainer}>
        <div className={styles.headerContainer}>
          <Nothing /> <h1> Nothing to see here! </h1>
        </div>
        <p>
          You’ll need to <b>transfer compatible NEP-5 assets</b> to this wallet
          using{' '}
          <NavLink id="wallet-manager" exact to={ROUTES.RECEIVE}>
            <span> receive </span>
          </NavLink>{' '}
          or your public address:
        </p>
        <div className={styles.address}>
          <TextInput value={address} disabled />
          {/* <Address className={styles.link} address={address} /> */}
          <CopyToClipboard
            className={styles.copy}
            text={address}
            tooltip="Copy Public Address"
          />
        </div>
      </div>
    )
  }

  formatPrice = (ticker: string): string => {
    const { prices, currencyCode } = this.props
    const { symbol } = CURRENCIES[currencyCode]
    let currPriceOfToken
    if (prices) currPriceOfToken = prices[ticker]
    if (!currPriceOfToken) return PRICE_UNAVAILABLE
    if (currPriceOfToken < 1.0) {
      return `${symbol}${toFixedDecimals(currPriceOfToken, 4)}`
    }
    return `${symbol}${toFixedDecimals(currPriceOfToken, 2)}`
  }

  sortByValueInPortfolio = (
    a: TokenBalanceType,
    b: TokenBalanceType
  ): number => {
    const { prices } = this.props
    if (prices) {
      let aValue = 0
      if (prices[a.symbol]) {
        aValue = prices[a.symbol] * Number(a.balance)
      }
      let bValue = 0
      if (prices[b.symbol]) {
        bValue = prices[b.symbol] * Number(b.balance)
      }

      if (aValue > bValue) return -1
      if (aValue < bValue) return 1
      return 0
    }
    return 0
  }

  renderHeader = () => {
    const { balances } = this.props
    return (
      <div>
        <div className={styles.header}>
          <span>Token Balances</span>
        </div>
      </div>
    )
  }

  renderTokenBalances = () => {
    const { balances } = this.props<commit_msg>refactor: remove unused code from TokenBalancesPanel.jsx<commit_after>// @flow
import React from 'react'
import classNames from 'classnames'
import { NavLink } from 'react-router-dom'

import TextInput from '../../Inputs/TextInput'
import CopyToClipboard from '../../CopyToClipboard'
import Panel from '../../Panel'
import styles from './TokenBalancesPanel.scss'
import { toFixedDecimals } from '../../../core/formatters'
import { toBigNumber } from '../../../core/math'
import Nothing from '../../../assets/icons/nothing.svg'
import { CURRENCIES, ROUTES, PRICE_UNAVAILABLE } from '../../../core/constants'

type Props = {
  className: ?string,
  balances: Array<TokenBalanceType>,
  prices: Object,
  currencyCode: string,
  address: string
}

export default class TokenBalancesPanel extends React.Component<Props> {
  static defaultProps = {
    loading: false
  }

  render = () => {
    const { className, balances } = this.props
    return (
      <Panel
        className={classNames(styles.tokenBalancesPanel, className)}
        contentClassName={classNames(styles.tokenBalancesPanelContent, {
          [styles.emptyBalanceContent]: !balances.length
        })}
        headerClassName={styles.headerStyle}
        renderHeader={this.renderHeader}
      >
        {balances.length
          ? this.renderTokenBalances()
          : this.renderEmptyBalanceInfo()}
      </Panel>
    )
  }

  renderEmptyBalanceInfo = () => {
    const { address } = this.props
    return (
      <div className={styles.emptyBalanceContainer}>
        <div className={styles.headerContainer}>
          <Nothing /> <h1> Nothing to see here! </h1>
        </div>
        <p>
          You’ll need to <b>transfer compatible NEP-5 assets</b> to this wallet
          using{' '}
          <NavLink id="wallet-manager" exact to={ROUTES.RECEIVE}>
            <span> receive </span>
          </NavLink>{' '}
          or your public address:
        </p>
        <div className={styles.address}>
          <TextInput value={address} disabled />
          <CopyToClipboard
            className={styles.copy}
            text={address}
            tooltip="Copy Public Address"
          />
        </div>
      </div>
    )
  }

  formatPrice = (ticker: string): string => {
    const { prices, currencyCode } = this.props
    const { symbol } = CURRENCIES[currencyCode]
    let currPriceOfToken
    if (prices) currPriceOfToken = prices[ticker]
    if (!currPriceOfToken) return PRICE_UNAVAILABLE
    if (currPriceOfToken < 1.0) {
      return `${symbol}${toFixedDecimals(currPriceOfToken, 4)}`
    }
    return `${symbol}${toFixedDecimals(currPriceOfToken, 2)}`
  }

  sortByValueInPortfolio = (
    a: TokenBalanceType,
    b: TokenBalanceType
  ): number => {
    const { prices } = this.props
    if (prices) {
      let aValue = 0
      if (prices[a.symbol]) {
        aValue = prices[a.symbol] * Number(a.balance)
      }
      let bValue = 0
      if (prices[b.symbol]) {
        bValue = prices[b.symbol] * Number(b.balance)
      }

      if (aValue > bValue) return -1
      if (aValue < bValue) return 1
      return 0
    }
    return 0
  }

  renderHeader = () => {
    return (
      <div>
        <div className={styles.header}>
          <span>Token Balances</span>
        </div>
      </div>
    )
  }

  renderTokenBalances = () => {
    const { balances } = this.props
{'fraction_non_alphanumeric': 0.1334210141750694, 'fraction_numerical': 0.003799503141896829, 'mean_word_length': 2.389796929172858, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7589928', 'n_tokens_mistral': 2074, 'n_tokens_neox': 2072, 'n_words': 465}