lbry-desktop/js/page/wallet.js

103 lines
2.5 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>
<h1>Create New Address:</h1>
<button type="button" onClick={this.generateAddress}>Generate New Address</button> <input type="text" size="60" value={this.state.address}></input>
</div>
);
}
});
var SendToAddressSection = React.createClass({
sendToAddress: function() {
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({
results: "Your transaction was completed successfully.",
});
}
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>
<h1>Send To Address:</h1>
<label for="balance">Balance: {this.state.balance}</label><br />
2016-07-22 17:33:05 +02:00
<label for="amount">Amount:</label> <input id="amount" type="text" size="10" onChange={this.setAmount}></input><br />
2016-07-19 00:40:15 +02:00
<label for="address">Address:</label> <input id="address" type="text" size="60" onChange={this.setAddress}></input><br />
<button type="button" onClick={this.sendToAddress}>Send Amount to Address</button><br /><br />
<h4>Results:</h4>
<span>{this.state.results}</span>
</div>
);
}
});
var WalletPage = React.createClass({
render: function() {
return (
<main className="page">
<SubPageLogo />
<NewAddressSection /><br />
<SendToAddressSection /><br />
<section>
<Link href="/" label="<< Return" />
</section>
</main>
);
}
});