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/account/summary/Summary.js

126 lines
4.6 KiB

6 years ago
/* @flow */
'use strict';
import React, { Component } from 'react';
import BigNumber from 'bignumber.js';
import { Async } from 'react-select';
import Tooltip from 'rc-tooltip';
import { resolveAfter } from '~/js/utils/promiseUtils';
import AbstractAccount from '../AbstractAccount';
import { Notification } from '~/js/components/common/Notification';
6 years ago
import SummaryDetails from './SummaryDetails.js';
import SummaryTokens from './SummaryTokens.js';
import type { Props } from './index';
import type { AccountState } from '../AbstractAccount';
6 years ago
import type { TrezorDevice } from '~/flowtype';
import type { NetworkToken } from '~/js/reducers/LocalStorageReducer';
import type { Account } from '~/js/reducers/AccountsReducer';
import type { Discovery } from '~/js/reducers/DiscoveryReducer';
import { findAccountTokens } from '~/js/reducers/TokensReducer';
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;
const abstractAccount = props.abstractAccount;
if (!device || !account || !abstractAccount) return <section></section>;
6 years ago
const tokens = findAccountTokens(props.tokens, account);
const explorerLink: string = `${abstractAccount.coin.explorer.address}${account.address}`;
6 years ago
const tokensTooltip = (
<div className="tooltip-wrapper">
Insert token name, symbol or address to be able to send it.
</div>
);
6 years ago
return (
<section className="summary">
{ deviceStatusNotification }
6 years ago
<h2 className={ `summary-header ${abstractAccount.network}` }>
Account #{ parseInt(abstractAccount.index) + 1 }
<a href={ explorerLink } className="gray" target="_blank" rel="noreferrer noopener">See full transaction history</a>
</h2>
6 years ago
<SummaryDetails
6 years ago
coin={ abstractAccount.coin }
6 years ago
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
<Tooltip
arrowContent={<div className="rc-tooltip-arrow-inner"></div>}
overlay={ tokensTooltip }
placement="top">
<span className="what-is-it"></span>
</Tooltip>
</h2>
6 years ago
{/* 0x58cda554935e4a1f2acbe15f8757400af275e084 Lahod */}
{/* 0x58cda554935e4a1f2acbe15f8757400af275e084 T01 */}
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: Array<NetworkToken>) => {
return options.map(o => {
const added = tokens.find(t => t.symbol === o.symbol);
if (added) {
return {
...o,
name: `${o.name} (Already added)`,
disabled: true
};
} else {
return o;
}
6 years ago
});
// return options.filter(o => {
// return !tokens.find(t => t.symbol === o.symbol);
// });
6 years ago
}
}
valueKey="symbol"
labelKey="name"
6 years ago
placeholder="Search for token"
6 years ago
searchPromptText="Type token name or address"
noResultsText="Token not found"
/>
6 years ago
</div>
6 years ago
<SummaryTokens tokens={ tokens } removeToken={ props.removeToken } />
6 years ago
</section>
);
}