mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
removed old files
This commit is contained in:
parent
9e8a2ffd4f
commit
d6349356c8
@ -1,248 +0,0 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import ColorHash from 'color-hash';
|
||||
import ScaleText from 'react-scale-text';
|
||||
import Blockies from 'react-blockies';
|
||||
import { Async } from 'react-select';
|
||||
import { resolveAfter } from '../../../utils/promiseUtils';
|
||||
import AbstractAccount from '../account/AbstractAccount';
|
||||
import { Notification } from '../Notification';
|
||||
|
||||
|
||||
export default class Summary extends AbstractAccount {
|
||||
|
||||
componentDidMount() {
|
||||
super.componentDidMount();
|
||||
//this.props.summaryActions.init();
|
||||
}
|
||||
|
||||
componentWillUpdate(newProps: any) {
|
||||
super.componentWillUpdate(newProps);
|
||||
//if (newProps.location.pathname !== this.props.location.pathname || (!newProps.summary.loaded && !this.props.summary.loaded)) {
|
||||
//if (newProps.router.pathname !== this.props.router.pathname || (!newProps.summary.loaded && !this.props.summary.loaded)) {
|
||||
// this.props.summaryActions.init();
|
||||
//}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
super.componentWillUnmount();
|
||||
//this.props.summaryActions.dispose();
|
||||
}
|
||||
|
||||
render() {
|
||||
return _render(this.props);
|
||||
}
|
||||
}
|
||||
|
||||
const _render = (props: any): any => {
|
||||
|
||||
const currentAccount = props.account;
|
||||
const fiatRate = props.fiatRate || '1030';
|
||||
|
||||
const {
|
||||
loaded,
|
||||
address,
|
||||
summary,
|
||||
addForm,
|
||||
search,
|
||||
customAddress,
|
||||
customName,
|
||||
customShortcut,
|
||||
customDecimal,
|
||||
|
||||
selectedToken
|
||||
} = props.summary;
|
||||
|
||||
if (currentAccount.deviceStateError) {
|
||||
return (
|
||||
<section>
|
||||
<Notification className="error" title="Account could not be loaded" message="Incorrect passphrase" />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// if (!loaded) return null;
|
||||
|
||||
const {
|
||||
onSummaryToggle,
|
||||
onTokenSearch,
|
||||
onCustomTokenToggle,
|
||||
onCustomTokenAddressChange,
|
||||
onCustomTokenNameChange,
|
||||
onCustomTokenShortcutChange,
|
||||
onCustomTokenDecimalChange,
|
||||
onCustomTokenAdd
|
||||
} = props.summaryActions;
|
||||
|
||||
const tokens = props.tokens.filter(t => t.ethAddress === address);
|
||||
|
||||
|
||||
let summaryClassName: string = "summary closed";
|
||||
let summaryContent = null;
|
||||
if (summary) {
|
||||
summaryClassName = "summary";
|
||||
if (currentAccount && currentAccount.balance) {
|
||||
|
||||
const balance = new BigNumber(currentAccount.balance);
|
||||
const fiat = balance.times(fiatRate).toFixed(2);
|
||||
|
||||
summaryContent = (
|
||||
<div className="content">
|
||||
<div className="column">
|
||||
<div className="label">Balance</div>
|
||||
<div className="fiat-value">${ fiat }</div>
|
||||
<div className="value">{ currentAccount.balance } ETH</div>
|
||||
</div>
|
||||
<div className="column">
|
||||
<div className="label">Rate</div>
|
||||
<div className="fiat-value">${ fiatRate }</div>
|
||||
<div className="value">1.00 ETH</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
summaryContent = (
|
||||
<div className="content">
|
||||
<div className="column">
|
||||
<div className="label">Balance</div>
|
||||
<div className="fiat-value">Loading...</div>
|
||||
<div className="value">Loading...</div>
|
||||
</div>
|
||||
<div className="column">
|
||||
<div className="label">Rate</div>
|
||||
<div className="fiat-value">${ fiatRate }</div>
|
||||
<div className="value">1.00 ETH</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let addFormClassName = "add-token-form closed";
|
||||
let addFormContent = null;
|
||||
if (addForm) {
|
||||
addFormClassName = "add-token-form";
|
||||
addFormContent = (
|
||||
<div className="content">
|
||||
<div className="column">
|
||||
<label>Address</label>
|
||||
<input type="text" className="token-address" placeholder="0x0000000" value={ customAddress } onChange={ event => onCustomTokenAddressChange(event.target.value) } />
|
||||
</div>
|
||||
<div className="column">
|
||||
<label>Name</label>
|
||||
<input type="text" className="token-symbol" placeholder="GNO" value={ customName } onChange={ event => onCustomTokenNameChange(event.target.value) } />
|
||||
</div>
|
||||
<div className="column">
|
||||
<label>Shortcut</label>
|
||||
<input type="text" className="token-shortcut" placeholder="0" value={ customShortcut } onChange={ event => onCustomTokenShortcutChange(event.target.value) } />
|
||||
</div>
|
||||
<div className="column">
|
||||
<label>Decimal</label>
|
||||
<input type="text" className="token-decimal" placeholder="0" value={ customDecimal } onChange={ event => onCustomTokenDecimalChange(event.target.value) } />
|
||||
</div>
|
||||
<div className="column">
|
||||
<button>Add custom token</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const bg = new ColorHash({lightness: 0.7});
|
||||
//const colorHash2 = new ColorHash({lightness: 0.5});
|
||||
const colorHash2 = new ColorHash();
|
||||
|
||||
console.log("SUM", tokens, address, props.tokens)
|
||||
//let tokensContent = null;
|
||||
let tokensContent = tokens.map((t, i) => {
|
||||
|
||||
// if (search.length > 0) {
|
||||
// if (t.name.toLowerCase().indexOf(search) < 0 && t.shortcut.toLowerCase().indexOf(search) < 0) return null;
|
||||
// }
|
||||
let iconColor = {
|
||||
color: colorHash2.hex(t.name),
|
||||
background: bg.hex(t.name),
|
||||
borderColor: bg.hex(t.name)
|
||||
}
|
||||
return (
|
||||
<div key={i} className="token">
|
||||
<div className="icon" style={ iconColor }>
|
||||
<div className="icon-inner">
|
||||
<ScaleText widthOnly><p>{ t.symbol }</p></ScaleText>
|
||||
</div>
|
||||
</div>
|
||||
<div className="name">{ t.name }</div>
|
||||
<div className="balance">{ t.balance }</div>
|
||||
</div>
|
||||
)
|
||||
});
|
||||
|
||||
let ethIcon = null;
|
||||
if (currentAccount) {
|
||||
ethIcon = (
|
||||
<Blockies
|
||||
seed={ currentAccount.address } />
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
<section className="tokens">
|
||||
<h2>{ ethIcon } Address #{ parseInt(props.match.params.address) + 1 }</h2>
|
||||
|
||||
<div className={ summaryClassName }>
|
||||
{ summaryContent }
|
||||
<div className="toggle" onClick={ onSummaryToggle }></div>
|
||||
</div>
|
||||
|
||||
<div className="filter">
|
||||
{/* <input type="text" placeholder="Search for token" value={ search } onChange={ event => onTokenSearch(event.target.value) } /> */}
|
||||
0x58cda554935e4a1f2acbe15f8757400af275e084
|
||||
<Async
|
||||
className="token-select"
|
||||
multi={ false }
|
||||
autoload={ false }
|
||||
|
||||
ignoreCase={ true }
|
||||
filterOptions= {
|
||||
(opt, str, values) => {
|
||||
console.log("FILTERRR", opt, str, values);
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
value={ selectedToken }
|
||||
onChange={ props.summaryActions.selectToken }
|
||||
valueKey="symbol"
|
||||
labelKey="symbol"
|
||||
placeholder="Search for token"
|
||||
loadOptions={ props.summaryActions.loadTokens }
|
||||
backspaceRemoves={true} />
|
||||
|
||||
</div>
|
||||
|
||||
<div className={ addFormClassName }>
|
||||
<div className="toggle" onClick={ onCustomTokenToggle }>
|
||||
Add token
|
||||
</div>
|
||||
{ addFormContent }
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{ tokensContent }
|
||||
</div>
|
||||
</section>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
const onChange = () => {
|
||||
}
|
||||
|
||||
const gotoUser = () => {
|
||||
}
|
@ -1,199 +0,0 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
|
||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
||||
import * as SEND from '../actions/constants/SendForm';
|
||||
import * as WEB3 from '../actions/constants/Web3';
|
||||
import * as ADDRESS from '../actions/constants/Address';
|
||||
import EthereumjsUnits from 'ethereumjs-units';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { getFeeLevels } from '../actions/SendFormActions';
|
||||
|
||||
export type State = {
|
||||
+senderAddress: ?string;
|
||||
+coin: string;
|
||||
token: string;
|
||||
balance: string;
|
||||
tokenBalance: string;
|
||||
balanceNeedUpdate: boolean;
|
||||
|
||||
|
||||
// form fields
|
||||
advanced: boolean;
|
||||
untouched: boolean; // set to true when user made some changes in form
|
||||
touched: {[k: string]: boolean};
|
||||
address: string;
|
||||
amount: string;
|
||||
setMax: boolean;
|
||||
feeLevels: Array<FeeLevel>;
|
||||
selectedFeeLevel: ?FeeLevel;
|
||||
recommendedGasPrice: string;
|
||||
gasPriceNeedsUpdate: boolean;
|
||||
gasLimit: string;
|
||||
gasPrice: string;
|
||||
data: string;
|
||||
nonce: string;
|
||||
total: string;
|
||||
sending: boolean;
|
||||
sendingStatus: ?SendStatus;
|
||||
errors: {[k: string]: string};
|
||||
warnings: {[k: string]: string};
|
||||
infos: {[k: string]: string};
|
||||
}
|
||||
|
||||
export type FeeLevel = {
|
||||
label: string;
|
||||
gasPrice: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
type SendStatus = {
|
||||
success: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
senderAddress: null,
|
||||
coin: '',
|
||||
token: '',
|
||||
advanced: false,
|
||||
untouched: true,
|
||||
touched: {},
|
||||
balance: '0',
|
||||
tokenBalance: '0',
|
||||
balanceNeedUpdate: false,
|
||||
//address: '',
|
||||
address: '0x574BbB36871bA6b78E27f4B4dCFb76eA0091880B',
|
||||
amount: '',
|
||||
setMax: false,
|
||||
feeLevels: [],
|
||||
selectedFeeLevel: null,
|
||||
recommendedGasPrice: '0',
|
||||
gasPriceNeedsUpdate: false,
|
||||
gasLimit: '0',
|
||||
gasPrice: '0',
|
||||
data: '',
|
||||
nonce: '0',
|
||||
total: '0',
|
||||
sending: false,
|
||||
sendingStatus: null,
|
||||
errors: {},
|
||||
warnings: {},
|
||||
infos: {},
|
||||
}
|
||||
|
||||
|
||||
const onGasPriceUpdated = (state: State, action: any): State => {
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
const newPrice = getRandomInt(10, 50).toString();
|
||||
//const newPrice = EthereumjsUnits.convert(action.gasPrice, 'wei', 'gwei');
|
||||
if (action.coin === state.coin && newPrice !== state.recommendedGasPrice) {
|
||||
const newState: State = { ...state };
|
||||
if (!state.untouched) {
|
||||
newState.gasPriceNeedsUpdate = true;
|
||||
newState.recommendedGasPrice = newPrice;
|
||||
} else {
|
||||
const newFeeLevels = getFeeLevels(state.coin, newPrice, state.gasLimit);
|
||||
const selectedFeeLevel = newFeeLevels.find(f => f.value === 'Normal');
|
||||
newState.recommendedGasPrice = newPrice;
|
||||
newState.feeLevels = newFeeLevels;
|
||||
newState.selectedFeeLevel = selectedFeeLevel;
|
||||
newState.gasPrice = selectedFeeLevel.gasPrice;
|
||||
}
|
||||
return newState;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
const onBalanceUpdated = (state: State, action: any): State => {
|
||||
// balanceNeedUpdate
|
||||
if (state.senderAddress === action.address) {
|
||||
return {
|
||||
...state,
|
||||
balance: '1'
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
export default (state: State = initialState, action: any): State => {
|
||||
|
||||
switch (action.type) {
|
||||
|
||||
case SEND.INIT :
|
||||
return action.state;
|
||||
|
||||
case SEND.DISPOSE :
|
||||
return initialState;
|
||||
|
||||
// this will be called right after Web3 instance initialization before any view is shown
|
||||
// and async during app live time
|
||||
case WEB3.GAS_PRICE_UPDATED :
|
||||
return onGasPriceUpdated(state, action);
|
||||
|
||||
case ADDRESS.SET_BALANCE :
|
||||
return onBalanceUpdated(state, action);
|
||||
|
||||
case SEND.TOGGLE_ADVANCED :
|
||||
return {
|
||||
...state,
|
||||
advanced: !state.advanced
|
||||
}
|
||||
|
||||
|
||||
// user actions
|
||||
case SEND.ADDRESS_CHANGE :
|
||||
case SEND.AMOUNT_CHANGE :
|
||||
case SEND.SET_MAX :
|
||||
case SEND.CURRENCY_CHANGE :
|
||||
case SEND.FEE_LEVEL_CHANGE :
|
||||
case SEND.UPDATE_FEE_LEVELS :
|
||||
case SEND.GAS_PRICE_CHANGE :
|
||||
case SEND.GAS_LIMIT_CHANGE :
|
||||
case SEND.DATA_CHANGE :
|
||||
return action.state;
|
||||
|
||||
case SEND.SEND :
|
||||
return {
|
||||
...state,
|
||||
sending: true,
|
||||
sendingStatus: null,
|
||||
}
|
||||
|
||||
case SEND.TX_COMPLETE :
|
||||
return {
|
||||
...state,
|
||||
sending: false,
|
||||
sendingStatus: {
|
||||
success: true,
|
||||
message: action.txid
|
||||
}
|
||||
}
|
||||
case SEND.TX_ERROR :
|
||||
return {
|
||||
...state,
|
||||
sending: false,
|
||||
sendingStatus: {
|
||||
success: false,
|
||||
message: action.response
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case SEND.VALIDATION :
|
||||
return {
|
||||
...state,
|
||||
errors: action.errors,
|
||||
warnings: action.warnings,
|
||||
infos: action.infos,
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user