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

Handling Promise, Async, and Javascript 'new' objects? #135

Closed
chris-shyft opened this issue Nov 3, 2019 · 3 comments
Closed

Handling Promise, Async, and Javascript 'new' objects? #135

chris-shyft opened this issue Nov 3, 2019 · 3 comments

Comments

@chris-shyft
Copy link

chris-shyft commented Nov 3, 2019

Re: issue 64

I am actually trying to run Ether JS library. The official documentation is available here.

I am trying to create a Wallet using the fromBrainWallet constructor. It takes in an emailID, password and a callback function.

When I use your code, the promise object does not have a property called then.

I have absolutely no idea about how I should handle this.

This is the code I am using (https://docs.ethers.io/ethers.js/html/api-providers.html#connecting-to-ethereum for reference) is able to get a reference to:

let defaultProvider = ethers.getDefaultProvider('ropsten');

but has an error when trying to use a 'new' object re:

let etherscanProvider = new ethers.providers.EtherscanProvider('ropsten');

which is the following:

I/System.out(17764): providerSetupFunction :: function EtherscanProvider(network, apiKey) {
I/System.out(17764):         var _this = _super.call(this, network) || this;
I/System.out(17764):         errors.checkNew(_this, EtherscanProvider);
I/System.out(17764):         var name = 'invalid';
I/System.out(17764):         if (_this.network) {
I/System.out(17764):             name = _this.network.name;
I/System.out(17764):         }
I/System.out(17764):         var baseUrl = null;
I/System.out(17764):         switch (name) {
I/System.out(17764):             case 'homestead':
I/System.out(17764):                 baseUrl = 'https://api.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'ropsten':
I/System.out(17764):                 baseUrl = 'https://api-ropsten.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'rinkeby':
I/System.out(17764):                 baseUrl = 'https://api-rinkeby.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'kovan':
I/System.out(17764):                 baseUrl = 'https://api-kovan.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             case 'goerli':
I/System.out(17764):                 baseUrl = 'https://api-goerli.etherscan.io';
I/System.out(17764):                 break;
I/System.out(17764):             default:
I/System.out(17764):                 throw new Error('unsupported network');
I/System.out(17764):         }
I/System.out(17764):         properties_1.defineReadOnly(_this, 'baseUrl', baseUrl);
I/System.out(17764):         properties_1.defineReadOnly(_this, 'apiKey', apiKey);
I/System.out(17764):         return _this;
I/System.out(17764):     }
E/AndroidRuntime(17764): FATAL EXCEPTION: Thread-3
E/AndroidRuntime(17764): Process: com.shyftnetwork.wx, PID: 17764
E/AndroidRuntime(17764): TypeError: Object.defineProperty called on non-object
E/AndroidRuntime(17764): 	at org.liquidplayer.javascript.JSFunction.apply(JSFunction.java:416)
E/AndroidRuntime(17764): 	at org.liquidplayer.javascript.JSFunction.call(JSFunction.java:377)

further, re:

let defaultProvider = ethers.getDefaultProvider('ropsten');

Getting that (which does work) and then calling a function on one of its members, I'm getting the following error when using "getProviderBlockNumber" (which should return a promise object, though it crashes before returning the object):

I/System.out(14807):     myProviderObjectFunction ::function () {
I/System.out(14807):         var _this = this;
I/System.out(14807):         return this.ready.then(function () {
I/System.out(14807):             return _this.perform('getBlockNumber', {}).then(function (result) {
I/System.out(14807):                 var value = parseInt(result);
I/System.out(14807):                 if (value != result) {
I/System.out(14807):                     throw new Error('invalid response - getBlockNumber');
I/System.out(14807):                 }
I/System.out(14807):                 _this._setFastBlockNumber(value);
I/System.out(14807):                 return value;
I/System.out(14807):             });
I/System.out(14807):         });
I/System.out(14807):     }
E/AndroidRuntime(14807): FATAL EXCEPTION: Thread-3
E/AndroidRuntime(14807): Process: com.shyftnetwork.wx, PID: 14807
E/AndroidRuntime(14807): TypeError: Cannot read property 'ready' of null
E/AndroidRuntime(14807): 	at org.liquidplayer.javascript.JSFunction.apply(JSFunction.java:416)
E/AndroidRuntime(14807): 	at org.liquidplayer.javascript.JSFunction.call(JSFunction.java:377)

If you could point me to a framework example which work in this case, that would be excellent.

q1) Why would getting a JSObject of the type "new" have internal issues referencing itself?
q2) How do I get a promise object returned without it crashing inside of the function call?

I'm assuming these issues are directly related?

Thanks for your help, I'd vastly prefer understanding how your microservices work and then extending the same mechanisms in the IOS realm rather than patching together different implementations on various platforms.

Fyi:
I'm using the format:

var service = MicroService(this@MainActivity, uri, startListener)

where in the service object I'm starting a new Thread inside of the onStart function, and then running the code that results in the errors referenced above inside of the "run" of the Runnable (which I'm assuming maintains the object references to the various JSObjects, as I thought that may have been the issue with the "new" objects)

@ericwlange
Copy link
Member

@chris-shyft This is unlikely related to promises and async per se. I have, in fact, tried to get Ethereum to work correctly with LiquidCore on a few past occasions with some success. The problem is typically related to the bundling process. Metro is not very smart when it comes to cyclic dependencies (e.g. file1.js has const file2 = require('./file2') and file2.js has const file2 = require('./file1')). I have tried to fix as many of these as possible in liquidcore-cli (see comment here), but I have had to manually edit the bundled file from time to time because I just couldn't fully bend Metro to my will.

I am in the process of updating liquidcore-cli to work with the newest version of Metro and LiquidCore 0.7.0. I will use Ethereum as a test case and update this issue when I have news to share.

@chris-shyft
Copy link
Author

super thanks @ericwlange I'd love to take a look at what you can come up with!

@ericwlange
Copy link
Member

Please try the latest version of LiquidCore (0.7.5+) and see if this is still a problem. IPFS seems to work ok, which uses ethereum. Please re-open if there is still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants