import React from 'react';
import { translate } from '../../translate/translate';
import { secondsToString } from '../../util/time';
import { sendNativeTx, getKMDOPID } from '../../actions/actionCreators';
import Store from '../../store';
class WalletsNativeSend extends React.Component {
constructor(props) {
super(props);
this.state = {
addressType: null,
sendFrom: null,
sendFromAmount: 0,
sendTo: null,
amount: 0,
fee: 0.0001,
addressSelectorOpen: false,
};
this.updateInput = this.updateInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.openDropMenu = this.openDropMenu.bind(this);
}
renderAddressByType(type) {
if (this.props.ActiveCoin.addresses[type] && this.props.ActiveCoin.addresses[type].length) {
return this.props.ActiveCoin.addresses[type].map((address) =>
this.updateAddressSelection(address.address, type, address.amount)}> [ {address.amount} {this.props.ActiveCoin.coin} ] {address.address}
);
} else {
return null;
}
}
renderSelectorCurrentLabel() {
if (this.state.sendFrom) {
return (
[ {this.state.sendFromAmount} {this.props.ActiveCoin.coin} ] {this.state.sendFrom}
);
} else {
return (
- Select Transparent or Private Address -
);
}
}
renderAddressList() {
return (
);
}
renderOPIDLabel(opid) {
if (opid.status === 'queued') {
return (
{translate('KMD_NATIVE.QUEUED')}
);
}
if (opid.status === 'executing') {
return (
{translate('KMD_NATIVE.EXECUTING')}
);
}
if (opid.status === 'failed') {
return (
{translate('KMD_NATIVE.FAILED')}
);
}
if (opid.status === 'success') {
return (
{translate('KMD_NATIVE.SUCCESS')}
);
}
}
renderOPIDResult(opid) {
var isWaitingStatus = true;
if (opid.status === 'queued') {
isWaitingStatus = false;
return (
{translate('KMD_NATIVE.PLEASE_REFRESH')}...
);
}
if (opid.status === 'executing') {
isWaitingStatus = false;
return (
{translate('KMD_NATIVE.PLEASE_REFRESH')}...
);
}
if (opid.status === 'failed') {
isWaitingStatus = false;
return (
Error Code: {opid.error.code}
{translate('KMD_NATIVE.MESSAGE')}: {opid.error.message}
);
}
if (opid.status === 'success') {
isWaitingStatus = false;
return (
txid: {opid.result.txid}
{translate('KMD_NATIVE.EXECUTION_SECONDS')}: {opid.execution_secs}
);
}
if (isWaitingStatus) {
return (
Waiting...
);
}
}
renderOPIDList() {
if (this.props.ActiveCoin.opids && this.props.ActiveCoin.opids.length) {
return this.props.ActiveCoin.opids.map((opid) =>
{this.renderOPIDLabel(opid)} |
{opid.id} |
{secondsToString(opid.creation_time)} |
{this.renderOPIDResult(opid)} |
);
} else {
return null;
}
}
openDropMenu() {
this.setState(Object.assign({}, this.state, {
addressSelectorOpen: !this.state.addressSelectorOpen,
}));
}
updateAddressSelection(address, type, amount) {
this.setState(Object.assign({}, this.state, {
sendFrom: address,
addressType: type,
sendFromAmount: amount,
addressSelectorOpen: !this.state.addressSelectorOpen,
}));
}
updateInput(e) {
this.setState({
[e.target.name]: e.target.value,
});
}
handleSubmit() {
console.log(this.state);
Store.dispatch(sendNativeTx(this.props.ActiveCoin.coin, this.state));
setTimeout(function() {
Store.dispatch(getKMDOPID(null, this.props.ActiveCoin.coin));
}, 1000);
}
render() {
if (this.props && this.props.ActiveCoin && this.props.ActiveCoin.nativeActiveSection === 'send') {
return (
{translate('INDEX.SEND')}
{translate('INDEX.STATUS')} |
ID |
{translate('INDEX.TIME')} |
{translate('INDEX.RESULT')} |
{this.renderOPIDList()}
{translate('INDEX.STATUS')} |
ID |
{translate('INDEX.TIME')} |
{translate('INDEX.RESULT')} |
);
} else {
return null;
}
}
}
export default WalletsNativeSend;