From d5b34ad396ddd16312c0b4b2fcad0b67776821ba Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 11 Sep 2018 17:08:51 -0400 Subject: [PATCH] fix onReady not returning the error --- src/blockchain.js | 15 ++++++--------- src/index.js | 5 +---- src/names.js | 15 +++++++++------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/blockchain.js b/src/blockchain.js index 7fb7435..68b41a0 100644 --- a/src/blockchain.js +++ b/src/blockchain.js @@ -2,7 +2,7 @@ import {reduce} from './async' function isNewWeb3_1() { return (typeof(web3.version) === "string"); -}; +} function getAccounts(cb) { if (isNewWeb3_1()) { @@ -13,7 +13,7 @@ function getAccounts(cb) { }); } web3.eth.getAccounts(cb); -}; +} let Blockchain = {}; @@ -52,12 +52,12 @@ Blockchain.connect = function(connectionList, opts, doneCb) { if (accounts) { web3.eth.defaultAccount = accounts[0]; } - cb(); + cb(err); doneCb(err); }); }); }) -} +}; Blockchain.execWhenReady = function(cb) { if (this.done) { @@ -67,7 +67,7 @@ Blockchain.execWhenReady = function(cb) { this.list = []; } this.list.push(cb) -} +}; Blockchain.doFirst = function(todo) { var self = this; @@ -77,11 +77,8 @@ Blockchain.doFirst = function(todo) { if (self.list) { self.list.map((x) => x.apply(x, [self.err])); } - if (self.finalCb) { - self.finalCb.apply(self.finalCb, []); - } }) -} +}; let Contract = function (options) { var self = this; diff --git a/src/index.js b/src/index.js index debe954..f5f5977 100644 --- a/src/index.js +++ b/src/index.js @@ -6,10 +6,7 @@ import Utils from './utils'; var EmbarkJS = { onReady: function (cb) { - Blockchain.execWhenReady(cb) - Blockchain.finalCb = function() { - cb(); - } + Blockchain.execWhenReady(cb); } }; diff --git a/src/names.js b/src/names.js index 0431e68..4dab637 100644 --- a/src/names.js +++ b/src/names.js @@ -3,11 +3,11 @@ let Names = {}; Names.Providers = {}; Names.noProviderError = 'Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")'; -Names.registerProvider = function (providerName, obj) { +Names.registerProvider = function(providerName, obj) { Names.Providers[providerName] = obj; }; -Names.setProvider = function (providerName, options) { +Names.setProvider = function(providerName, options) { let provider = this.Providers[providerName]; if (!provider) { @@ -21,7 +21,7 @@ Names.setProvider = function (providerName, options) { }; // resolve resolves a name into an identifier of some kind -Names.resolve = function (name, callback) { +Names.resolve = function(name, callback) { if (!this.currentNameSystems) { throw new Error(this.noProviderError); } @@ -29,15 +29,18 @@ Names.resolve = function (name, callback) { }; // the reverse of resolve, resolves using an identifier to get to a name -Names.lookup = function (identifier, callback) { +Names.lookup = function(identifier, callback) { if (!this.currentNameSystems) { throw new Error(this.noProviderError); } return this.currentNameSystems.lookup(identifier, callback); }; -Names.isAvailable = function () { - return this.currentNameSystems.isAvailable(); +Names.isAvailable = function() { + if (!this.currentNameSystems) { + return false; + } + return this.currentNameSystems.isAvailable(); }; Names.registerSubDomain = function(name, address, callback) {