simplify add set providers; validation can be done on the client isde

This commit is contained in:
Iuri Matias 2018-07-08 00:56:15 +03:00
parent e07d06fa4c
commit c3fc614cd8
1 changed files with 3 additions and 13 deletions

View File

@ -26,23 +26,13 @@ class Storage {
});
}
/**
* Adds the code to call setProviders in embarkjs after embark is ready
*
* @returns {void}
*/
addSetProviders() {
const self = this;
// filter list of dapp connections based on available_providers set in config
let hasSwarm = _.contains(this.storageConfig.available_providers, 'swarm'); // don't need to eval this in every loop iteration
// contains valid dapp storage providers
this._validDappProviders = _.filter(this.storageConfig.dappConnection, (conn) => {
return _.contains(self.storageConfig.available_providers, conn.provider) || (conn === '$BZZ' && hasSwarm);
});
let code = `\nEmbarkJS.Storage.setProviders(${JSON.stringify(this._validDappProviders)});`;
let code = `\nEmbarkJS.Storage.setProviders(${JSON.stringify(this.storageConfig.dappConnection)});`;
let shouldInit = (storageConfig) => {
return (this._validDappProviders !== undefined && this._validDappProviders.length > 0 && storageConfig.enabled === true);
return storageConfig.enabled;
};
this.embark.addProviderInit('storage', code, shouldInit);