From 14323f5430b74d560cbf945ca39563bcec7da442 Mon Sep 17 00:00:00 2001 From: emizzle Date: Mon, 4 Mar 2019 13:49:06 +1100 Subject: [PATCH] fix(@embark/swarm): Fix swarm not being registered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Swarm was not being registered as a service due to a recent change that introduced a bug. The previous change was meant to register “swarm” as a console command to provide output for the `swarm` console command when swarm had not been registered in the VM. The bug, however, returned too early in the cases when swarm was meant to be enabled, thus effectively not registering the entire process. The fix simply returns only when swarm is in fact, disabled, and also alters slightly the way swarm is determined to be enabled (the changes of which have been copied over to `ipfs`). --- packages/embark/src/lib/modules/ipfs/index.js | 9 +++++++-- packages/embark/src/lib/modules/swarm/index.js | 15 ++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/embark/src/lib/modules/ipfs/index.js b/packages/embark/src/lib/modules/ipfs/index.js index 642f89265..523b908c7 100644 --- a/packages/embark/src/lib/modules/ipfs/index.js +++ b/packages/embark/src/lib/modules/ipfs/index.js @@ -195,8 +195,13 @@ class IPFS { } isIpfsStorageEnabledInTheConfig() { - let {enabled, available_providers, dappConnection} = this.storageConfig; - return enabled && (available_providers.indexOf('ipfs') > 0 || dappConnection.find(c => c.provider === 'ipfs')); + let {enabled, available_providers, dappConnection, upload} = this.storageConfig; + return enabled && + available_providers.includes('ipfs') && + ( + dappConnection.some(c => c.provider === 'ipfs') || + upload.provider === 'ipfs' + ); } } diff --git a/packages/embark/src/lib/modules/swarm/index.js b/packages/embark/src/lib/modules/swarm/index.js index a03f439e0..3e1743425 100644 --- a/packages/embark/src/lib/modules/swarm/index.js +++ b/packages/embark/src/lib/modules/swarm/index.js @@ -26,7 +26,9 @@ class Swarm { if(this.isSwarmEnabledInTheConfig() && cantDetermineUrl){ console.warn('\n===== Swarm module will not be loaded ====='); console.warn(`Swarm is enabled in the config, however the config is not setup to provide a URL for swarm and therefore the Swarm module will not be loaded. Please either change the ${'config/storage > upload'.bold} setting to Swarm or add the Swarm config to the ${'config/storage > dappConnection'.bold} array. Please see ${'https://embark.status.im/docs/storage_configuration.html'.underline} for more information.\n`); - } else { + return; + } + if (!this.isSwarmEnabledInTheConfig()) { this.embark.registerConsoleCommand({ matches: cmd => cmd === "swarm" || cmd.indexOf('swarm ') === 0, process: (_cmd, cb) => { @@ -34,7 +36,6 @@ class Swarm { cb(); } }); - return; } @@ -42,7 +43,6 @@ class Swarm { this.getUrl = this.storageConfig.upload.getUrl || this.providerUrl + '/bzz:/'; - this.swarm = new SwarmAPI({gateway: this.providerUrl}); this.setServiceCheck(); @@ -163,8 +163,13 @@ class Swarm { } isSwarmEnabledInTheConfig() { - let {enabled, available_providers, dappConnection} = this.storageConfig; - return enabled && (available_providers.indexOf('swarm') > 0 || dappConnection.find(c => c.provider === 'swarm')); + let {enabled, available_providers, dappConnection, upload} = this.storageConfig; + return enabled && + available_providers.includes('swarm') && + ( + dappConnection.some(c => c.provider === 'swarm') || + upload.provider === "swarm" + ); } }