check users balance before creating channel/publishing

This commit is contained in:
Sean Yesmunt 2017-11-28 23:26:07 -05:00
parent 867803e7c4
commit c3eaa8c34d
3 changed files with 27 additions and 2 deletions

View file

@ -1,5 +1,10 @@
import React from "react";
import { connect } from "react-redux";
import PublishForm from "./view";
import { selectBalance } from "redux/selectors/wallet";
export default connect(null, null)(PublishForm);
const select = state => ({
balance: selectBalance(state),
});
export default connect(select, null)(PublishForm);

View file

@ -48,11 +48,22 @@ class ChannelSection extends React.PureComponent {
handleNewChannelBidChange(event) {
this.setState({
newChannelBid: event.target.value,
newChannelBid: parseFloat(event.target.value),
});
}
handleCreateChannelClick(event) {
const { balance } = this.props;
const { newChannelBid } = this.state;
if (newChannelBid > balance) {
this.refs.newChannelName.showError(
__("Unable to create channel due to insufficient funds.")
);
return;
}
this.setState({
creatingChannel: true,
});

View file

@ -61,6 +61,15 @@ class PublishForm extends React.PureComponent {
}
handleSubmit() {
const { balance } = this.props;
const { bid } = this.state;
if (bid > balance) {
this.handlePublishError({ message: "insufficient funds" });
return;
}
this.setState({
submitting: true,
});