Implement lbry.call() and get balance display working
This commit is contained in:
parent
8c39a0716f
commit
972674ce2e
2 changed files with 32 additions and 8 deletions
15
js/gui.js
15
js/gui.js
|
@ -101,12 +101,23 @@ var logoStyle = {
|
||||||
};
|
};
|
||||||
|
|
||||||
var Header = React.createClass({
|
var Header = React.createClass({
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
balance: 0
|
||||||
|
};
|
||||||
|
},
|
||||||
|
componentDidMount: function() {
|
||||||
|
lbry.getBalance(function(balance) {
|
||||||
|
this.setState({
|
||||||
|
balance: balance
|
||||||
|
});
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var balance = lbry.getBalance();
|
|
||||||
return (
|
return (
|
||||||
<header>
|
<header>
|
||||||
<span style={balanceStyle}>
|
<span style={balanceStyle}>
|
||||||
<CreditAmount amount={balance}/>
|
<CreditAmount amount={this.state.balance}/>
|
||||||
</span>
|
</span>
|
||||||
<div style={logoStyle}>
|
<div style={logoStyle}>
|
||||||
<img src="../../web/img/lbry-dark-1600x528.png" style={imgStyle}/>
|
<img src="../../web/img/lbry-dark-1600x528.png" style={imgStyle}/>
|
||||||
|
|
25
js/lbry.js
25
js/lbry.js
|
@ -6,13 +6,26 @@ var lbry = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
lbry.call = function(method, params, callback)
|
lbry.call = function (method, params, callback)
|
||||||
{
|
{
|
||||||
/*
|
var xhr = new XMLHttpRequest;
|
||||||
* XHR magic
|
xhr.addEventListener('load', function() {
|
||||||
*/
|
// The response from the HTTP endpoint has a "result" key containing a JSON string of the output of the JSON-RPC method itself
|
||||||
//when XHR returns and is successful
|
var method_output = JSON.parse(JSON.parse(xhr.responseText).result);
|
||||||
// callback(JSON.parse(xhr.responseText));
|
|
||||||
|
if (method_output.code !== 200) {
|
||||||
|
throw new Error('Call to method ' + method + ' failed with message: ' + method_output.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(method_output.result);
|
||||||
|
});
|
||||||
|
xhr.open('POST', 'http://localhost:5279/lbryapi', true);
|
||||||
|
xhr.send(JSON.stringify({
|
||||||
|
'jsonrpc': '2.0',
|
||||||
|
'method': method,
|
||||||
|
'params': params,
|
||||||
|
'id': 0
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
//core
|
//core
|
||||||
|
|
Loading…
Reference in a new issue