lbry-desktop/js/page/wallet.js

110 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-07-19 00:40:15 +02:00
var NewAddressSection = React.createClass({
generateAddress: function() {
lbry.getNewAddress((results) => {
this.setState({
address: results,
})
});
},
getInitialState: function() {
return {
address: "",
}
},
render: function() {
return (
<div>
2016-07-22 17:52:50 +02:00
<h1>Generate New Address:</h1>
<input type="text" size="60" value={this.state.address}></input><br /><br />
<Link button="primary" label="Generate" onClick={this.generateAddress} />
2016-07-19 00:40:15 +02:00
</div>
);
}
});
var SendToAddressSection = React.createClass({
sendToAddress: function() {
if ((this.state.balance - this.state.amount) < 1)
{
alert("Insufficient balance: after this transaction you would have less than 1 LBC in your wallet.")
return;
}
2016-07-19 00:40:15 +02:00
this.setState({
results: "",
});
2016-07-19 01:18:16 +02:00
lbry.sendToAddress(this.state.amount, this.state.address, (results) => {
2016-07-19 00:40:15 +02:00
if(results === true)
{
this.setState({
2016-07-22 17:59:20 +02:00
results: "Your transaction was successfully placed in the queue.",
2016-07-19 00:40:15 +02:00
});
}
else
{
this.setState({
results: "Something went wrong: " + results
});
}
2016-07-22 17:33:05 +02:00
}, (error) => {
this.setState({
results: "Something went wrong: " + error.faultString + " " + error.faultCode
})
2016-07-19 00:40:15 +02:00
});
},
getInitialState: function() {
return {
address: "",
amount: 0.0,
balance: "Checking balance...",
results: "",
}
},
componentWillMount: function() {
lbry.getBalance((results) => {
this.setState({
balance: results,
});
});
},
setAmount: function(event) {
this.setState({
2016-07-22 17:33:05 +02:00
amount: parseFloat(event.target.value),
2016-07-19 00:40:15 +02:00
})
},
setAddress: function(event) {
this.setState({
address: event.target.value,
})
},
render: function() {
return (
<div>
2016-07-22 17:52:50 +02:00
<h1>Send Amount To Address:</h1>
<label for="balance">Balance: {this.state.balance}</label><br /><br />
<label for="amount">Amount:</label> <input id="amount" type="text" size="10" onChange={this.setAmount}></input><br /><br />
<label for="address">Address:</label> <input id="address" type="text" size="60" onChange={this.setAddress}></input><br /><br />
<Link button="primary" label="Send" onClick={this.sendToAddress} disabled={!(parseFloat(this.state.amount) > 0.0) || this.state.address == ""} /><br /><br />
2016-07-19 00:40:15 +02:00
<h4>Results:</h4>
2016-07-22 17:52:50 +02:00
<span>{this.state.results}</span><br />
2016-07-19 00:40:15 +02:00
</div>
);
}
});
var WalletPage = React.createClass({
render: function() {
return (
<main className="page">
<SubPageLogo />
<NewAddressSection /><br />
<SendToAddressSection /><br />
<section>
<Link href="/" label="<< Return" />
</section>
</main>
);
}
});