You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-wallet/src/js/components/wallet/summary/Summary.js

90 lines
3.1 KiB

6 years ago
/* @flow */
'use strict';
import React, { Component } from 'react';
import BigNumber from 'bignumber.js';
import { Async } from 'react-select';
import { resolveAfter } from '../../../utils/promiseUtils';
import AbstractAccount from '../account/AbstractAccount';
import { Notification } from '../../common/Notification';
import SummaryDetails from './SummaryDetails.js';
import SummaryTokens from './SummaryTokens.js';
import { findDevice } from '../../../utils/reducerUtils';
6 years ago
import type { Props } from './index';
import type { AccountState } from '../account/AbstractAccount';
6 years ago
import type { TrezorDevice } from '../../../flowtype';
import type { NetworkToken } from '../../../reducers/LocalStorageReducer';
import type { Account } from '../../../reducers/AccountsReducer';
import type { Discovery } from '../../../reducers/DiscoveryReducer';
export default class Summary extends AbstractAccount<Props> {
6 years ago
render() {
return super.render() || _render(this.props, this.state);
6 years ago
}
}
const _render = (props: Props, state: AccountState): React$Element<string> => {
const {
device,
account,
deviceStatusNotification
} = state;
if (!device || !account) return <section></section>;
6 years ago
const abstractAccount = props.abstractAccount;
6 years ago
const tokens = props.tokens.filter(t => t.ethAddress === account.address);
return (
<section className="summary">
{ deviceStatusNotification }
6 years ago
<h2 className={ `summary-header ${abstractAccount.network}` }>Address #{ parseInt(abstractAccount.index) + 1 }</h2>
6 years ago
<SummaryDetails
summary={ props.summary }
balance={ account.balance }
network={ abstractAccount.network }
6 years ago
fiat={ props.fiat }
localStorage={ props.localStorage }
onToggle={ props.onDetailsToggle } />
6 years ago
<h2>Tokens</h2>
{/* 0x58cda554935e4a1f2acbe15f8757400af275e084 */}
6 years ago
<div className="filter">
<Async
className="token-select"
multi={ false }
autoload={ false }
ignoreCase={ true }
backspaceRemoves={ true }
value={ null }
onChange={ token => props.addToken(token, account) }
loadOptions={ input => props.loadTokens(input, account.network) }
6 years ago
filterOptions= {
(options: Array<NetworkToken>, search: string, values) => {
6 years ago
return options.filter(o => {
return !tokens.find(t => t.symbol === o.symbol);
});
6 years ago
}
}
valueKey="symbol"
labelKey="symbol"
placeholder="Search for token"
6 years ago
searchPromptText="Type token name or address"
noResultsText="Token not found"
/>
6 years ago
</div>
<SummaryTokens tokens={ tokens } removeToken={ props.removeToken } />
6 years ago
</section>
);
}