web3-providers-http: Migrate from xhr2-cookies to cross-fetch - #5085
Conversation
Pull Request Test Coverage Report for Build 2495828271
💛 - Coveralls |
|
|
||
| // Apply missing polyfill for IE | ||
| require('es6-promise').polyfill(); | ||
| require('abortcontroller-polyfill/dist/polyfill-patch-fetch'); |
There was a problem hiding this comment.
I have added the polyfills in case of compatibility, but I think CI makes some complain about it
| options = options || {}; | ||
|
|
||
| this.withCredentials = options.withCredentials || false; | ||
| this.withCredentials = options.withCredentials; |
There was a problem hiding this comment.
| } | ||
|
|
||
| export interface HttpProviderAgent { | ||
| baseUrl?: string; |
There was a problem hiding this comment.
Have removed it since this isn't supported by fetch as well as this is not a standard for Http Agent
| return new Promise(function(resolve, reject) { | ||
| resolve(response); | ||
| }); | ||
| }; |
There was a problem hiding this comment.
Simple version of fetch-mock function added
|
|
||
| provider.send({}, function (err, result) { | ||
| assert.equal(typeof result, 'object'); | ||
| assert.equal(typeof result, 'undefined'); |
There was a problem hiding this comment.
This should not be an object as we didn't had any url to fetch
| var agent = new https.Agent(); | ||
| var options = {agent: {https: agent}}; | ||
| var provider = new HttpProvider('http://localhost:8545', options); | ||
| var result = await provider._prepareRequest(); |
There was a problem hiding this comment.
Should not _prepareRequest create only a function which unless invoked should not return a promise?
There was a problem hiding this comment.
@nazarhussain You mean we should return the function like () => fetch(this.host, options) instead of the promise itself?
There was a problem hiding this comment.
I believe the _prepareRequest should not be async. It should return the request object synchronously. And later on we should be using request.send() to actually send and await.
If that seems to be a big change, then we can rename the function to _prepareAndSendRequest that will make the context right.
|
@nazarhussain Resolved those three comments |
nikoulai
left a comment
There was a problem hiding this comment.
Please check the failing tests (except for e2e_windows)
|
This pull request introduces 1 alert when merging f0f1fa0 into 2c0324a - view on LGTM.com new alerts:
|
|
@jdevcs @avkos @luu-alex @spacesailor24 @nazarhussain @nikoulai I have fixed the testcase, would like to have a look at? |
|
This pull request introduces 1 alert when merging 4a9235f into 2c0324a - view on LGTM.com new alerts:
|
nazarhussain
left a comment
There was a problem hiding this comment.
@ayanamidev Thanks for your contributions. Left one small comment. Rest seems good to me.
There are two other points that need to address.
- We don't allow community contributions to change the
package-lock.jsonfile. So please remove the change from that file in your PR. Some team member will merge the PR and include the changes inpackage-lock.json. - Add an entry to
CHANGELOG.mddescribing what you are changing in this PR.
| var agent = new https.Agent(); | ||
| var options = {agent: {https: agent}}; | ||
| var provider = new HttpProvider('http://localhost:8545', options); | ||
| var result = await provider._prepareRequest(); |
There was a problem hiding this comment.
I believe the _prepareRequest should not be async. It should return the request object synchronously. And later on we should be using request.send() to actually send and await.
If that seems to be a big change, then we can rename the function to _prepareAndSendRequest that will make the context right.
|
@nazarhussain @nikoulai @spacesailor24 Would like to ask your thought about removing |
|
@nazarhussain @nikoulai @spacesailor24 Addressed comments |
nazarhussain
left a comment
There was a problem hiding this comment.
@ayanamidev LGTM. Please add an entry into CHANGELOG.md describing the change.
|
@nazarhussain Oh, sorry fixed. |
|
@ayanamidev Please resolve the conflicts. Those probably will be in CHANGELOG.md. Then I would be able to merge the PR right away. |
|
@nazarhussain Done. Every conflicts resolved without changes from source code |
* web3-providers-http: Migrate from xhr2-cookies to cross-fetch (#5085) * Update CHANGELOG.md * Migrate from xhr2-cookies to cross-fetch * Address comments for web3-providers-http * web3-providers-http: Prevent global leakage of this.connected * Return server side error without creating additional error object * Fixed type of http.Agent https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export * Removed unused variable * Remove unnecessary catch block * Remove unnecessary internal _prepareRequest function from web3-providers-http * ⬆️ Update package-lock.json * Update packages/web3-providers-http/src/index.js Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com> * ⚰️ Remove dead code * 🎨 Improve the with credentials check Co-authored-by: Ayanami <ayanami0330@protonmail.com> Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com>
closes #4868
I have replaced the old
xhr2-cookieslibrary tocross-fetchsince it was better, and thenpm iforxhr2-cookieswas broken for the latest node LTS version as well.Working perfectly like before.