diff --git a/package.json b/package.json index 72954cf..39bd8e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lumerin/wallet-core", - "version": "1.0.71", + "version": "1.0.72", "author": { "name": "Lumerin", "email": "developer@lumerin.io", diff --git a/src/plugins/contracts/index.js b/src/plugins/contracts/index.js index f58222d..bb6f012 100644 --- a/src/plugins/contracts/index.js +++ b/src/plugins/contracts/index.js @@ -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) const lumerin = Lumerin(web3, lmrTokenAddress) diff --git a/src/plugins/eth/index.js b/src/plugins/eth/index.js index e496ffa..e5412aa 100644 --- a/src/plugins/eth/index.js +++ b/src/plugins/eth/index.js @@ -29,6 +29,7 @@ function createPlugin () { return { api: { + web3, web3Provider: web3.currentProvider, web3SubscriptionProvider: web3SubscribAble.currentProvider, }, diff --git a/src/plugins/eth/web3.js b/src/plugins/eth/web3.js index 2789540..a34cddc 100644 --- a/src/plugins/eth/web3.js +++ b/src/plugins/eth/web3.js @@ -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 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 } } 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