diff --git a/lib/modules/storage/embarkjs.js b/lib/modules/storage/embarkjs.js new file mode 100644 index 000000000..20cf842ba --- /dev/null +++ b/lib/modules/storage/embarkjs.js @@ -0,0 +1,37 @@ +/* global EmbarkJS */ + +import {detectSeries} from 'async'; + +let __embarkStorage = {}; + +__embarkStorage.setProviders = async function (dappConnOptions) { + try { + await detectSeries(dappConnOptions, async (dappConn, callback) => { + if(dappConn === '$BZZ' || dappConn.provider === 'swarm'){ + let options = dappConn; + if(dappConn === '$BZZ') options = {"useOnlyGivenProvider": true}; + try{ + await EmbarkJS.Storage.setProvider('swarm', options); + let isAvailable = await EmbarkJS.Storage.isAvailable(); + callback(null, isAvailable); + }catch(err){ + callback(null, false); // catch errors for when bzz object not initialised but config has requested it to be used + } + } + else if(dappConn.provider === 'ipfs') { + // set the provider then check the connection, if true, use that provider, else, check next provider + try{ + await EmbarkJS.Storage.setProvider('ipfs', dappConn); + let isAvailable = await EmbarkJS.Storage.isAvailable(); + callback(null, isAvailable); + } catch(err) { + callback(null, false); // catch but keep looping by not passing err to callback + } + } + }, function(err, result){ + if(!result) throw new Error('Could not connect to a storage provider using any of the dappConnections in the storage config'); + }); + } catch (err) { + throw new Error('Failed to connect to a storage provider: ' + err.message); + } + }; diff --git a/test_apps/test_app/embark.json b/test_apps/test_app/embark.json index a4c2f1d27..e4a75559c 100644 --- a/test_apps/test_app/embark.json +++ b/test_apps/test_app/embark.json @@ -16,7 +16,7 @@ "config": "config/", "versions": { "solc": "0.4.24", - "web3": "1.0.0-beta", + "web3": "1.0.0-beta.34", "ipfs-api": "17.2.7" }, "plugins": {