Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Fix: ensure using this.provider as the context this #3721

Merged
merged 2 commits into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/web3-core-requestmanager/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ RequestManager.prototype.setProvider = function (provider, net) {


// reset the old one before changing, if still connected
if(this.provider && this.provider.connected)
if (this.provider && this.provider.connected)
this.clearSubscriptions();

this.provider = provider || null;
Expand Down Expand Up @@ -123,17 +123,17 @@ RequestManager.prototype.setProvider = function (provider, net) {

// notify all subscriptions about bad close conditions
this.provider.on('close', function close(event) {
if (!_this._isCleanCloseEvent(event) || _this._isIpcCloseError(event)){
if (!_this._isCleanCloseEvent(event) || _this._isIpcCloseError(event)) {
_this.subscriptions.forEach(function (subscription) {
subscription.callback(errors.ConnectionCloseError(event));
_this.subscriptions.delete(subscription.subscription.id);
});

if(_this.provider && _this.provider.emit){
if (_this.provider && _this.provider.emit) {
_this.provider.emit('error', errors.ConnectionCloseError(event));
}
}
if(_this.provider && _this.provider.emit){
if (_this.provider && _this.provider.emit) {
_this.provider.emit('end', event);
}
});
Expand All @@ -151,7 +151,7 @@ RequestManager.prototype.setProvider = function (provider, net) {
* @param {Function} callback
*/
RequestManager.prototype.send = function (data, callback) {
callback = callback || function () {};
callback = callback || function () { };

if (!this.provider) {
return callback(errors.InvalidProvider());
Expand All @@ -163,7 +163,7 @@ RequestManager.prototype.send = function (data, callback) {
const jsonrpcResultCallback = this._jsonrpcResultCallback(callback, jsonrpcPayload)

if (this.provider.request) {
const callbackRequest = callbackify(this.provider.request)
const callbackRequest = callbackify(this.provider.request.bind(this.provider))
const requestArgs = { method, params }
callbackRequest(requestArgs, callback);
} else if (this.provider.sendAsync) {
Expand Down Expand Up @@ -220,7 +220,7 @@ RequestManager.prototype.addSubscription = function (subscription, callback) {
}
);
} else {
throw new Error('The provider doesn\'t support subscriptions: '+ this.provider.constructor.name);
throw new Error('The provider doesn\'t support subscriptions: ' + this.provider.constructor.name);
}
};

Expand Down Expand Up @@ -273,7 +273,7 @@ RequestManager.prototype.clearSubscriptions = function (keepIsSyncing) {
}

// reset notification callbacks etc.
if(this.provider.reset)
if (this.provider.reset)
this.provider.reset();

return true
Expand Down Expand Up @@ -320,8 +320,8 @@ RequestManager.prototype._isIpcCloseError = function (event) {
*
*/
RequestManager.prototype._jsonrpcResultCallback = function (callback, payload) {
return function(err, result) {
if(result && result.id && payload.id !== result.id) {
return function (err, result) {
if (result && result.id && payload.id !== result.id) {
return callback(new Error(`Wrong response id ${result.id} (expected: ${payload.id}) in ${JSON.stringify(payload)}`));
}

Expand Down