Skip to content

Commit

Permalink
Update helpers.js (#4613) (#4671)
Browse files Browse the repository at this point in the history
* Update helpers.js

* fix: remove more window use

* Update CHANGELOG.md

Co-authored-by: Jack Works <jackworks@protonmail.com>
  • Loading branch information
spacesailor24 and Jack-Works committed Feb 2, 2022
1 parent 314e1b5 commit ed825d2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -501,6 +501,7 @@ Released with 1.0.0-beta.37 code base.

### Fixed
- Fix a typo in the documentation for `methods.myMethod.send` (#4599)
- Use globalThis to locate global object if possible (#4613)
- Fix typos in web3-utils.rst (#4662)
- Added effectiveGasPrice to TransactionReceipt (#4692)
- Correction in documentation for `web3.eth.accounts.signTransaction` (#4576)
Expand Down
12 changes: 7 additions & 5 deletions packages/web3-core-requestmanager/src/givenProvider.js
Expand Up @@ -26,11 +26,13 @@ var givenProvider = null;

// ADD GIVEN PROVIDER
/* jshint ignore:start */
var global;
try {
global = Function('return this')();
} catch (e) {
global = window;
var global = typeof globalThis === 'object' ? globalThis : undefined;
if(!global) {
try {
global = Function('return this')();
} catch (e) {
global = self;
}
}

// EIP-1193: window.ethereum
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/index.js
Expand Up @@ -768,7 +768,7 @@ if (!storageAvailable('localStorage')) {
function storageAvailable(type) {
var storage;
try {
storage = window[type];
storage = self[type];
var x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-providers-ws/src/helpers.js
Expand Up @@ -19,7 +19,7 @@ if (isNode || isRN) {
helpers = require('url').parse;
}
} else {
_btoa = btoa.bind(window);
_btoa = btoa.bind(typeof globalThis === 'object' ? globalThis : self);
helpers = function(url) {
return new URL(url);
};
Expand Down

0 comments on commit ed825d2

Please sign in to comment.