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

Commit 4615f2d

Browse files
authored
Merge pull request #3721 from chendatony31/1.x
Fix: ensure using this.provider as the context `this`
2 parents 9b92aac + 5e19a84 commit 4615f2d

File tree

1 file changed

+10
-10
lines changed
  • packages/web3-core-requestmanager/src

1 file changed

+10
-10
lines changed

packages/web3-core-requestmanager/src/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ RequestManager.prototype.setProvider = function (provider, net) {
9191

9292

9393
// reset the old one before changing, if still connected
94-
if(this.provider && this.provider.connected)
94+
if (this.provider && this.provider.connected)
9595
this.clearSubscriptions();
9696

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

124124
// notify all subscriptions about bad close conditions
125125
this.provider.on('close', function close(event) {
126-
if (!_this._isCleanCloseEvent(event) || _this._isIpcCloseError(event)){
126+
if (!_this._isCleanCloseEvent(event) || _this._isIpcCloseError(event)) {
127127
_this.subscriptions.forEach(function (subscription) {
128128
subscription.callback(errors.ConnectionCloseError(event));
129129
_this.subscriptions.delete(subscription.subscription.id);
130130
});
131131

132-
if(_this.provider && _this.provider.emit){
132+
if (_this.provider && _this.provider.emit) {
133133
_this.provider.emit('error', errors.ConnectionCloseError(event));
134134
}
135135
}
136-
if(_this.provider && _this.provider.emit){
136+
if (_this.provider && _this.provider.emit) {
137137
_this.provider.emit('end', event);
138138
}
139139
});
@@ -151,7 +151,7 @@ RequestManager.prototype.setProvider = function (provider, net) {
151151
* @param {Function} callback
152152
*/
153153
RequestManager.prototype.send = function (data, callback) {
154-
callback = callback || function () {};
154+
callback = callback || function () { };
155155

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

165165
if (this.provider.request) {
166-
const callbackRequest = callbackify(this.provider.request)
166+
const callbackRequest = callbackify(this.provider.request.bind(this.provider))
167167
const requestArgs = { method, params }
168168
callbackRequest(requestArgs, callback);
169169
} else if (this.provider.sendAsync) {
@@ -220,7 +220,7 @@ RequestManager.prototype.addSubscription = function (subscription, callback) {
220220
}
221221
);
222222
} else {
223-
throw new Error('The provider doesn\'t support subscriptions: '+ this.provider.constructor.name);
223+
throw new Error('The provider doesn\'t support subscriptions: ' + this.provider.constructor.name);
224224
}
225225
};
226226

@@ -273,7 +273,7 @@ RequestManager.prototype.clearSubscriptions = function (keepIsSyncing) {
273273
}
274274

275275
// reset notification callbacks etc.
276-
if(this.provider.reset)
276+
if (this.provider.reset)
277277
this.provider.reset();
278278

279279
return true
@@ -320,8 +320,8 @@ RequestManager.prototype._isIpcCloseError = function (event) {
320320
*
321321
*/
322322
RequestManager.prototype._jsonrpcResultCallback = function (callback, payload) {
323-
return function(err, result) {
324-
if(result && result.id && payload.id !== result.id) {
323+
return function (err, result) {
324+
if (result && result.id && payload.id !== result.id) {
325325
return callback(new Error(`Wrong response id ${result.id} (expected: ${payload.id}) in ${JSON.stringify(payload)}`));
326326
}
327327

0 commit comments

Comments
 (0)