-
Notifications
You must be signed in to change notification settings - Fork 3
use overloaded web3 instance instead of single provider. required fo… #76
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ function createPlugin() { | |
| const { lmrTokenAddress, cloneFactoryAddress } = config | ||
| const { eth } = plugins | ||
|
|
||
| const web3 = new Web3(eth.web3Provider) | ||
| const web3 = eth.web3 | ||
| const web3Subscriptionable = new Web3(plugins.eth.web3SubscriptionProvider) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is creating a new instance of Web3 using To improve this, you should wrap the creation of the new Web3 instance in a try-catch block and handle any potential errors appropriately. This could involve logging the error, retrying the operation, or failing gracefully with a user-friendly error message. |
||
|
|
||
| const lumerin = Lumerin(web3, lmrTokenAddress) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ function createPlugin () { | |
|
|
||
| return { | ||
| api: { | ||
| web3, | ||
| web3Provider: web3.currentProvider, | ||
| web3SubscriptionProvider: web3SubscribAble.currentProvider, | ||
|
srt0422 marked this conversation as resolved.
Comment on lines
+32
to
34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is directly exposing the |
||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,8 +87,8 @@ const overrideFunctions = function (object, providers) { | |
| !key.startsWith('set') | ||
| ) { | ||
| object[key] = function () { | ||
| const isAsync = | ||
| originalFunctions[key][Symbol.toStringTag] === 'AsyncFunction' | ||
| const originalFunction = originalFunctions[key] | ||
| const isAsync = originalFunction[Symbol.toStringTag] === 'AsyncFunction' | ||
| const args = arguments | ||
|
srt0422 marked this conversation as resolved.
|
||
| let providerIndex = lastUsedProviderIndex | ||
| let result | ||
|
|
@@ -97,7 +97,7 @@ const overrideFunctions = function (object, providers) { | |
| const provider = providers[providerIndex] | ||
| originalSetProvider(provider) | ||
| if (isAsync) { | ||
| result = originalFunctions[key] | ||
| result = originalFunction | ||
| .apply(this, args) | ||
| .then((res) => { | ||
| if (res !== undefined) { | ||
|
|
@@ -111,8 +111,19 @@ const overrideFunctions = function (object, providers) { | |
| }) | ||
| } else { | ||
| try { | ||
| result = originalFunctions[key].apply(this, args) | ||
| if (result !== undefined) { | ||
| if (new.target) { | ||
| function F(args) { | ||
| return originalFunction.apply(this, args) | ||
| } | ||
|
|
||
| F.prototype = originalFunction.prototype | ||
|
|
||
| return new F(args) | ||
| } else { | ||
| result = originalFunctions[key].apply(this, args) | ||
| } | ||
|
|
||
| if (typeof result !== "undefined") { | ||
| break | ||
| } | ||
|
Comment on lines
111
to
128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling in this code is not sufficient. In the catch block, the error is caught but nothing is done with it. This can make debugging difficult because you lose information about what caused the error. To improve this, you should at least log the error. Depending on your application's requirements, you might also want to handle specific types of errors differently. For example, you might want to retry on certain types of errors, or report them to an error tracking service. |
||
| } catch (error) { | ||
|
|
@@ -121,7 +132,7 @@ const overrideFunctions = function (object, providers) { | |
| } | ||
| } while (providerIndex !== lastUsedProviderIndex) | ||
| lastUsedProviderIndex = providerIndex | ||
| if (result === undefined) { | ||
| if (typeof result === "undefined") { | ||
| throw new Error('All providers failed to execute the function') | ||
| } | ||
| return result | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.