import { PageTitle } from 'features/shared/components' import React from 'react' import { connect } from 'react-redux' import styles from './New.scss' import actions from 'actions' import componentClassNames from 'utility/componentClassNames' import Tutorial from 'features/tutorial/components/Tutorial' import NormalTxForm from './NormalTransactionForm' import AdvancedTxForm from './AdvancedTransactionForm' import Vote from './Vote' import { withRouter } from 'react-router' import {getValues} from 'redux-form' import {withNamespaces} from 'react-i18next' import { replace } from 'react-router-redux' class Form extends React.Component { constructor(props) { super(props) this.handleFormEmpty = this.handleFormEmpty.bind(this) } componentDidMount() { if (!this.props.autocompleteIsBalanceLoaded) { this.props.fetchBalanceAll().then(() => { this.props.didLoadBalanceAutocomplete() }) } if (!this.props.autocompleteIsAssetLoaded) { this.props.fetchAssetAll().then(() => { this.props.didLoadAssetAutocomplete() }) } this.props.router.setRouteLeaveHook(this.props.route, (nextLocation) => { if (!(this.handleFormEmpty() || nextLocation.state || nextLocation.pathname.startsWith('/transactions/generated/'))) return this.props.t('transaction.new.unsaveWarning') }) } handleKeyDown(e, cb, disable) { if (e.key === 'Enter' && e.shiftKey === false && !disable) { e.preventDefault() cb() } } handleFormEmpty() { if(this.props.normalSelected){ const array = [ 'accountAlias', 'accountId', 'assetAlias', 'assetId', 'password'] for (let k in array){ if(this.props.normalform[array[k]]){ return false } } return !(this.props.normalform['receivers'].length > 1) }else if(this.props.advancedSelected){ return !(this.props.advform['actions'].length > 0 || this.props.advform['signTransaction'] || this.props.advform['password']) }else if(this.props.voteSelected){ const array = [ 'accountAlias', 'accountId', 'amount', 'nodePubkey' ] for (let k in array){ if(this.props.voteform[array[k]]){ return false } } return true } } showForm(e, type){ e.preventDefault() if (( !this.handleFormEmpty() && !window.confirm(this.props.t('transaction.new.unsaveWarning')) )){ return } this.props.createForm(type) } render() { const t = this.props.t return (