/* @flow */ import React from 'react'; import styled from 'styled-components'; import colors from 'config/colors'; import Input from 'components/inputs/Input'; import Textarea from 'components/Textarea'; import Tooltip from 'components/Tooltip'; import Icon from 'components/Icon'; import ICONS from 'config/icons'; import type { Props } from '../../Container'; // TODO: Decide on a small screen width for the whole app // and put it inside config/variables.js // same variable also in "AccountSend/index.js" const SmallScreenWidth = '850px'; const InputRow = styled.div` margin-bottom: 20px; `; const InputLabelWrapper = styled.div` display: flex; align-items: center; `; const GreenSpan = styled.span` color: ${colors.GREEN_PRIMARY}; `; const AdvancedSettingsWrapper = styled.div` padding: 20px 0; display: flex; flex-direction: column; justify-content: space-between; border-top: 1px solid ${colors.DIVIDER}; `; const GasInputRow = styled(InputRow)` width: 100%; display: flex; @media screen and (max-width: ${SmallScreenWidth}) { flex-direction: column; } `; const GasInput = styled(Input)` min-height: 85px; &:first-child { padding-right: 20px; } @media screen and (max-width: ${SmallScreenWidth}) { &:first-child { padding-right: 0; margin-bottom: 2px; } } `; const StyledTextarea = styled(Textarea)` margin-bottom: 20px; min-height: 80px; `; const AdvancedSettingsSendButtonWrapper = styled.div` width: 100%; display: flex; justify-content: flex-end; `; const getGasLimitInputState = (gasLimitErrors: string, gasLimitWarnings: string): string => { let state = ''; if (gasLimitWarnings && !gasLimitErrors) { state = 'warning'; } if (gasLimitErrors) { state = 'error'; } return state; }; const getGasPriceInputState = (gasPriceErrors: string, gasPriceWarnings: string): string => { let state = ''; if (gasPriceWarnings && !gasPriceErrors) { state = 'warning'; } if (gasPriceErrors) { state = 'error'; } return state; }; const getDataTextareaState = (dataError: string, dataWarning: string): string => { let state = ''; if (dataWarning) { state = 'warning'; } if (dataError) { state = 'error'; } return state; }; // stateless component const AdvancedForm = (props: Props) => { const { network, } = props.selectedAccount; if (!network) return null; const { networkSymbol, currency, recommendedGasPrice, calculatingGasLimit, errors, warnings, infos, data, gasLimit, gasPrice, } = props.sendForm; const { onGasLimitChange, onGasPriceChange, onDataChange, } = props.sendFormActions; let gasLimitTooltipCurrency: string; let gasLimitTooltipValue: string; if (networkSymbol !== currency) { gasLimitTooltipCurrency = 'tokens'; gasLimitTooltipValue = network.defaultGasLimitTokens.toString(10); } else { gasLimitTooltipCurrency = networkSymbol; gasLimitTooltipValue = network.defaultGasLimit.toString(10); } return ( Gas limit Gas limit refers to the maximum amount of gas user is willing to spendon a particular transaction.{' '} Transaction fee = gas limit * gas price.{' '}Increasing the gas limit will not get the transaction confirmed sooner. Default value for sending {gasLimitTooltipCurrency} is {gasLimitTooltipValue}. )} maxWidth={410} readMoreLink="https://wiki.trezor.io/Ethereum_Wallet#Gas_limit" placement="top" > )} bottomText={errors.gasLimit || warnings.gasLimit || infos.gasLimit || (calculatingGasLimit ? 'Calculating...' : '')} value={gasLimit} isDisabled={networkSymbol === currency && data.length > 0} onChange={event => onGasLimitChange(event.target.value)} /> Gas price Gas price refers to the amount of ether you are willing to pay for every unit of gas, and is usually measured in “Gwei”. Transaction fee = gas limit * gas price. Increasing the gas price will get the transaction confirmed sooner but makes it more expensive. The recommended gas price is {recommendedGasPrice} GWEI. )} maxWidth={400} readMoreLink="https://wiki.trezor.io/Ethereum_Wallet#Gas_price" placement="top" > )} bottomText={errors.gasPrice || warnings.gasPrice || infos.gasPrice} value={gasPrice} onChange={event => onGasPriceChange(event.target.value)} /> Data Data is usually used when you send transactions to contracts. )} placement="top" > )} state={getDataTextareaState(errors.data, warnings.data)} bottomText={errors.data || warnings.data || infos.data} isDisabled={networkSymbol !== currency} value={networkSymbol !== currency ? '' : data} onChange={event => onDataChange(event.target.value)} /> { props.children } ); }; export default AdvancedForm;