/* @flow */ import React, { Component } from 'react'; import styled from 'styled-components'; import Select from 'react-select'; import { H2 } from 'components/common/Heading'; import AdvancedForm from './AdvancedForm'; import PendingTransactions from './PendingTransactions'; import { FeeSelectValue, FeeSelectOption } from './FeeSelect'; import SelectedAccount from '../SelectedAccount'; import { findAccountTokens } from 'reducers/TokensReducer'; import { calculate, validation } from 'actions/SendFormActions'; import { findToken } from 'reducers/TokensReducer'; import type { Props } from './index'; import type { Token } from 'flowtype'; export default class SendContainer extends Component { componentWillReceiveProps(newProps: Props) { calculate(this.props, newProps); validation(newProps); this.props.saveSessionStorage(); } render() { return ( ); } } const StyledH2 = styled(H2)` padding: 20px 48px; `; const Send = (props: Props) => { const device = props.wallet.selectedDevice; const { account, network, discovery, tokens, } = props.selectedAccount; if (!device || !account || !discovery || !network) return null; const { address, amount, setMax, networkSymbol, currency, feeLevels, selectedFeeLevel, gasPriceNeedsUpdate, total, errors, warnings, infos, advanced, data, sending, } = props.sendForm; const { onAddressChange, onAmountChange, onSetMax, onCurrencyChange, onFeeLevelChange, updateFeeLevels, onSend, } = props.sendFormActions; const fiatRate = props.fiat.find(f => f.network === network); const tokensSelectData = tokens.map(t => ({ value: t.symbol, label: t.symbol })); tokensSelectData.unshift({ value: network.symbol, label: network.symbol }); const setMaxClassName: string = setMax ? 'set-max enabled' : 'set-max'; let updateFeeLevelsButton = null; if (gasPriceNeedsUpdate) { updateFeeLevelsButton = ( Recommended fees updated. Click here to use them ); } let addressClassName: ?string; if (errors.address) { addressClassName = 'not-valid'; } else if (warnings.address) { addressClassName = 'warning'; } else if (address.length > 0) { addressClassName = 'valid'; } let buttonDisabled: boolean = Object.keys(errors).length > 0 || total === '0' || amount.length === 0 || address.length === 0 || sending; let buttonLabel: string = 'Send'; if (networkSymbol !== currency && amount.length > 0 && !errors.amount) { buttonLabel += ` ${amount} ${currency.toUpperCase()}`; } else if (networkSymbol === currency && total !== '0') { buttonLabel += ` ${total} ${network.symbol}`; } if (!device.connected) { buttonLabel = 'Device is not connected'; buttonDisabled = true; } else if (!device.available) { buttonLabel = 'Device is unavailable'; buttonDisabled = true; } else if (!discovery.completed) { buttonLabel = 'Loading accounts'; buttonDisabled = true; } return (
Send Ethereum or tokens
onAddressChange(event.target.value)} /> { errors.address ? ({ errors.address }) : null } { warnings.address ? ({ warnings.address }) : null } { infos.address ? ({ infos.address }) : null }
onAmountChange(event.target.value)} /> Set max 0} optionClassName="fee-option" options={feeLevels} />
); };