Skip to content

Commit

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

* fix: remove more window use

* Update CHANGELOG.md
  • Loading branch information
Jack-Works authored Jan 7, 2022
1 parent 8783f4d commit 843d456
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,6 @@ Released with 1.0.0-beta.37 code base.
## [1.7.1]

### Fixed
- Fix a typo in the documentation for `methods.myMethod.send` (#4599)
- Fix a typo in the documentation for `methods.myMethod.send` (#4599)
- Use globalThis to locate global object if possible (#4613)

12 changes: 7 additions & 5 deletions packages/web3-core-requestmanager/src/givenProvider.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 843d456

Please sign in to comment.