2018-01-02 18:04:50 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { AmountFieldFactory } from 'components/AmountFieldFactory';
|
|
|
|
import { AddressFieldFactory } from 'components/AddressFieldFactory';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { AppState } from 'reducers';
|
2018-03-23 16:41:47 +00:00
|
|
|
import { SendButton, TXMetaDataPanel } from 'components';
|
2018-01-02 18:04:50 +00:00
|
|
|
import { resetWallet, TResetWallet } from 'actions/wallet';
|
|
|
|
import translate from 'translations';
|
|
|
|
import { getUnit } from 'selectors/transaction';
|
2018-01-15 06:51:35 +00:00
|
|
|
import { getCurrentBalance } from 'selectors/wallet';
|
|
|
|
import Spinner from 'components/ui/Spinner';
|
|
|
|
import { Wei, TokenValue } from 'libs/units';
|
2018-03-01 17:53:29 +00:00
|
|
|
import { Input } from 'components/ui';
|
2018-01-02 18:04:50 +00:00
|
|
|
|
|
|
|
interface StateProps {
|
|
|
|
unit: string;
|
|
|
|
resetWallet: TResetWallet;
|
2018-01-15 06:51:35 +00:00
|
|
|
currentBalance: Wei | TokenValue | null;
|
2018-01-02 18:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Props = StateProps;
|
|
|
|
class FieldsClass extends Component<Props> {
|
|
|
|
public render() {
|
2018-01-15 06:51:35 +00:00
|
|
|
const { currentBalance } = this.props;
|
2018-01-02 18:04:50 +00:00
|
|
|
return (
|
|
|
|
<div className="Tab-content-pane">
|
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-xs-12">
|
|
|
|
<button
|
|
|
|
className="Deploy-field-reset btn btn-default btn-sm"
|
|
|
|
onClick={this.changeWallet}
|
|
|
|
>
|
|
|
|
<i className="fa fa-refresh" />
|
2018-03-22 03:50:25 +00:00
|
|
|
{translate('CHANGE_WALLET')}
|
2018-01-02 18:04:50 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="col-xs-12">
|
|
|
|
<AddressFieldFactory
|
|
|
|
withProps={({ currentTo }) => (
|
2018-03-01 17:53:29 +00:00
|
|
|
<Input type="text" value={currentTo.raw} readOnly={true} />
|
2018-01-02 18:04:50 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col-xs-1" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-xs-12">
|
2018-03-22 03:50:25 +00:00
|
|
|
<label>{translate('SEND_AMOUNT')}</label>
|
2018-01-15 06:51:35 +00:00
|
|
|
{currentBalance === null ? (
|
|
|
|
<div className="row text-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<AmountFieldFactory
|
|
|
|
withProps={({ currentValue, isValid }) => (
|
|
|
|
<React.Fragment>
|
|
|
|
{!isValid && (
|
2018-03-22 03:50:25 +00:00
|
|
|
<h5 style={{ color: 'red' }}>{translate('INSUFFICIENT_FUNDS')}</h5>
|
2018-01-15 06:51:35 +00:00
|
|
|
)}
|
|
|
|
{isValid && (
|
2018-03-01 17:53:29 +00:00
|
|
|
<Input
|
2018-01-15 06:51:35 +00:00
|
|
|
type="text"
|
|
|
|
value={`${currentValue.raw} ${this.props.unit}`}
|
|
|
|
readOnly={true}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
2018-01-02 18:04:50 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-xs-12">
|
2018-01-25 03:43:27 +00:00
|
|
|
<TXMetaDataPanel initialState={'simple'} disableToggle={true} />
|
2018-01-02 18:04:50 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="row form-group">
|
|
|
|
<div className="col-xs-12 clearfix">
|
2018-01-15 06:51:35 +00:00
|
|
|
{currentBalance === null ? (
|
|
|
|
<div className="row text-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
) : (
|
2018-03-23 16:41:47 +00:00
|
|
|
<SendButton signing={true} />
|
2018-01-15 06:51:35 +00:00
|
|
|
)}
|
2018-01-02 18:04:50 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
private changeWallet = () => {
|
|
|
|
this.props.resetWallet();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-15 06:51:35 +00:00
|
|
|
export const Fields = connect(
|
|
|
|
(state: AppState) => ({ unit: getUnit(state), currentBalance: getCurrentBalance(state) }),
|
|
|
|
{ resetWallet }
|
|
|
|
)(FieldsClass);
|