Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update helpers.js #4613

Merged
merged 4 commits into from Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
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
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