lbry-desktop/js/page/wallet.js

117 lines
3 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 (
<section>
<h1>Generate New Address</h1>
<section><input type="text" size="60" value={this.state.address}></input></section>
2016-07-22 17:52:50 +02:00
<Link button="primary" label="Generate" onClick={this.generateAddress} />
</section>
2016-07-19 00:40:15 +02:00
);
}
});
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 (
<section>
<h1>Send Credits</h1>
<section>
<section><label for="balance">Balance {this.state.balance}</label></section>
<label for="amount">Amount <input id="amount" type="text" size="10" onChange={this.setAmount}></input></label>
<label for="address">Recipient address <input id="address" type="text" size="60" onChange={this.setAddress}></input></label>
<Link button="primary" label="Send" onClick={this.sendToAddress} disabled={!(parseFloat(this.state.amount) > 0.0) || this.state.address == ""} />
</section>
<section className={!this.state.results ? 'hidden' : ''}>
<h4>Results:</h4>
{this.state.results}
</section>
</section>
2016-07-19 00:40:15 +02:00
);
}
});
var WalletPage = React.createClass({
render: function() {
return (
<main className="page">
<NewAddressSection />
<SendToAddressSection />
2016-08-08 00:45:26 +02:00
<section>
<h4>Claim invite code</h4>
<Link href="?claim" label="Claim a LBRY beta invite code"/>
</section>
2016-07-19 00:40:15 +02:00
<section>
2016-08-07 20:00:56 +02:00
<ReturnLink />
2016-07-19 00:40:15 +02:00
</section>
</main>
);
}
});