simplified polling && jsonrpc payload creation
This commit is contained in:
@@ -43,18 +43,14 @@ var ProviderManager = function() {
|
||||
var poll = function () {
|
||||
if (self.provider) {
|
||||
self.polls.forEach(function (data) {
|
||||
data.data._id = self.id;
|
||||
self.id++;
|
||||
var result = self.provider.send(data.data);
|
||||
var result = self.send(data.data);
|
||||
|
||||
result = JSON.parse(result);
|
||||
|
||||
// dont call the callback if result is not an array, or empty one
|
||||
if (result.error || !(result.result instanceof Array) || result.result.length === 0) {
|
||||
if (!(result instanceof Array) || result.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.callback(result.result);
|
||||
data.callback(result);
|
||||
});
|
||||
}
|
||||
setTimeout(poll, 1000);
|
||||
@@ -63,10 +59,12 @@ var ProviderManager = function() {
|
||||
};
|
||||
|
||||
/// sends outgoing requests
|
||||
/// @params data - an object with at least 'method' property
|
||||
ProviderManager.prototype.send = function(data) {
|
||||
|
||||
data.args = data.args || [];
|
||||
data._id = this.id++;
|
||||
data.jsonrpc = '2.0';
|
||||
data.params = data.params || [];
|
||||
data.id = this.id++;
|
||||
|
||||
if (this.provider === undefined) {
|
||||
console.error('provider is not set');
|
||||
|
Reference in New Issue
Block a user