PR feedback

This commit is contained in:
Anthony Laibe 2018-07-30 17:06:20 +01:00 committed by Iuri Matias
parent e19fca7d6f
commit b548f9efae
6 changed files with 51 additions and 35 deletions

View File

@ -4,9 +4,9 @@ let __embarkIPFS = {};
__embarkIPFS.setProvider = function (options) { __embarkIPFS.setProvider = function (options) {
var self = this; var self = this;
var promise = new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
try { try {
if (options === undefined) { if (!options) {
self._config = options; self._config = options;
self._ipfsConnection = IpfsApi('localhost', '5001'); self._ipfsConnection = IpfsApi('localhost', '5001');
self._getUrl = "http://localhost:8080/ipfs/"; self._getUrl = "http://localhost:8080/ipfs/";
@ -28,7 +28,6 @@ __embarkIPFS.setProvider = function (options) {
reject(new Error('Failed to connect to IPFS')); reject(new Error('Failed to connect to IPFS'));
} }
}); });
return promise;
}; };
__embarkIPFS.isAvailable = function () { __embarkIPFS.isAvailable = function () {

View File

@ -19,12 +19,12 @@ class IPFS {
this.webServerConfig = embark.config.webServerConfig; this.webServerConfig = embark.config.webServerConfig;
this.blockchainConfig = embark.config.blockchainConfig; this.blockchainConfig = embark.config.blockchainConfig;
if (this.isIpfsEnabledInTheConfig() || this.isIpnsEnabledInTheConfig()) { if (this.isIpfsStorageEnabledInTheConfig() || this.isIpfsNameEnabledInTheConfig()) {
this.downloadIpfsApi(); this.downloadIpfsApi();
this.addDefaultToEmbarkJS(); this.addDefaultToEmbarkJS();
} }
if (this.isIpfsEnabledInTheConfig()) { if (this.isIpfsStorageEnabledInTheConfig()) {
this.setServiceCheck(); this.setServiceCheck();
this.addStorageProviderToEmbarkJS(); this.addStorageProviderToEmbarkJS();
this.addObjectToConsole(); this.addObjectToConsole();
@ -39,7 +39,7 @@ class IPFS {
}); });
} }
if (this.isIpnsEnabledInTheConfig()) { if (this.isIpfsNameEnabledInTheConfig()) {
this.addNamesystemProviderToEmbarkJS(); this.addNamesystemProviderToEmbarkJS();
this.setNamesystemProvider(); this.setNamesystemProvider();
} }
@ -156,12 +156,12 @@ class IPFS {
}); });
} }
isIpfsEnabledInTheConfig() { isIpfsStorageEnabledInTheConfig() {
let {enabled, available_providers, dappConnection} = this.storageConfig; let {enabled, available_providers, dappConnection} = this.storageConfig;
return enabled && (available_providers.indexOf('ipfs') > 0 || dappConnection.find(c => c.provider === 'ipfs')); return enabled && (available_providers.indexOf('ipfs') > 0 || dappConnection.find(c => c.provider === 'ipfs'));
} }
isIpnsEnabledInTheConfig() { isIpfsNameEnabledInTheConfig() {
let {enabled, available_providers} = this.namesystemConfig; let {enabled, available_providers} = this.namesystemConfig;
return enabled && available_providers.indexOf('ipns') > 0; return enabled && available_providers.indexOf('ipns') > 0;
} }

2
package-lock.json generated
View File

@ -3917,7 +3917,7 @@
} }
}, },
"embarkjs": { "embarkjs": {
"version": "file:../EmbarkJS", "version": "0.3.1",
"requires": { "requires": {
"@babel/runtime": "^7.0.0-beta.54", "@babel/runtime": "^7.0.0-beta.54",
"async": "^2.0.1" "async": "^2.0.1"

View File

@ -39,7 +39,7 @@
"decompress": "^4.2.0", "decompress": "^4.2.0",
"deep-equal": "^1.0.1", "deep-equal": "^1.0.1",
"ejs": "^2.5.8", "ejs": "^2.5.8",
"embarkjs": "file:../EmbarkJS", "embarkjs": "^0.3.1",
"eth-ens-namehash": "^2.0.8", "eth-ens-namehash": "^2.0.8",
"eth-lib": "^0.2.8", "eth-lib": "^0.2.8",
"ethereumjs-wallet": "0.6.0", "ethereumjs-wallet": "0.6.0",

View File

@ -18,8 +18,8 @@ class Storage extends React.Component {
url: '', url: '',
logs: [], logs: [],
storageError: '', storageError: '',
ipfsHash: '', valueRegister: '',
ipnsResolveName: '', valueResolver: '',
}; };
} }
@ -101,34 +101,45 @@ class Storage extends React.Component {
ipnsRegister(e) { ipnsRegister(e) {
e.preventDefault(); e.preventDefault();
this.setState({ ipnsRegistering: true }); this.setState({ registering: true, responseRegister: false });
EmbarkJS.Names.register(this.state.ipfsHash, (err, name) => { this.addToLog("EmbarkJS.Names.register(this.state.ipfsHash).then(function(hash) { })");
EmbarkJS.Names.register(this.state.valueRegister, (err, name) => {
let responseRegister;
let isRegisterError = false;
if (err) { if (err) {
console.log("Name Register Error => " + err.message); isRegisterError = true;
responseRegister = "Name Register Error: " + err.message
} else {
responseRegister = name;
} }
this.setState({ this.setState({
ipnsResolveName: name, responseRegister: responseRegister,
ipnsName: name, registering: false,
ipnsRegistering: false isRegisterError: isRegisterError
}); });
this.addToLog("EmbarkJS.Names.register(this.state.ipfsHash).then(function(hash) { })");
}); });
} }
ipnsResolve(e) { ipnsResolve(e) {
e.preventDefault(); e.preventDefault();
this.setState({ ipnsResolving: true }); this.setState({ resolving: true, responseResolver: false });
EmbarkJS.Names.resolve(this.state.ipnsName, (err, path) => { this.addToLog("EmbarkJS.Names.resolve(this.state.ipnsName, function(err, path) { })");
EmbarkJS.Names.resolve(this.state.valueResolver, (err, path) => {
let responseResolver;
let isResolverError = false;
if (err) { if (err) {
console.log("Name Resolve Error => " + err.message); isResolverError = true;
responseResolver = "Name Resolve Error: " + err.message
} else {
responseResolver = path;
} }
this.setState({ this.setState({
ipfsPath: path, responseResolver: responseResolver,
ipnsResolving: false resolving: false,
isResolverError: isResolverError
}); });
this.addToLog("EmbarkJS.Names.resolve(this.state.ipnsName, function(err, path) { })");
}); });
} }
@ -201,13 +212,16 @@ class Storage extends React.Component {
<FormGroup> <FormGroup>
<FormControl <FormControl
type="text" type="text"
value={this.state.ipfsHash} value={this.state.valueRegister}
onChange={e => this.handleChange(e, 'ipfsHash')}/> onChange={e => this.handleChange(e, 'valueRegister')}/>
<Button bsStyle="primary" onClick={(e) => this.ipnsRegister(e)}> <Button bsStyle="primary" onClick={(e) => this.ipnsRegister(e)}>
{this.state.ipnsRegistering ? 'Registering...' : 'Register' } {this.state.registering ? 'Registering...' : 'Register' }
</Button> </Button>
<HelpBlock>It will take around 1 minute</HelpBlock> <HelpBlock>It will take around 1 minute</HelpBlock>
<HelpBlock>registered at: <span>{this.state.ipnsName}</span></HelpBlock> {this.state.responseRegister &&
<Alert className="alert-result" bsStyle={this.state.isRegisterError ? 'danger' : 'success'}>
<span className="value">{this.state.responseRegister}</span>
</Alert>}
</FormGroup> </FormGroup>
</Form> </Form>
@ -216,13 +230,16 @@ class Storage extends React.Component {
<FormGroup> <FormGroup>
<FormControl <FormControl
type="text" type="text"
value={this.state.ipnsResolveName} value={this.state.valueResolver}
onChange={e => this.handleChange(e, 'ipnsResolveName')}/> onChange={e => this.handleChange(e, 'valueResolver')}/>
<Button bsStyle="primary" onClick={(e) => this.ipnsResolve(e)}> <Button bsStyle="primary" onClick={(e) => this.ipnsResolve(e)}>
{this.state.ipnsResolving ? 'Resolving...' : 'Resolve' } {this.state.resolving ? 'Resolving...' : 'Resolve' }
</Button> </Button>
<HelpBlock>It will take around 1 minute</HelpBlock> <HelpBlock>It will take around 1 minute</HelpBlock>
<HelpBlock>IPFS path: <span>{this.state.ipfsPath}</span></HelpBlock> {this.state.responseResolver &&
<Alert className="alert-result" bsStyle={this.state.isResolverError ? 'danger' : 'success'}>
<span className="value">{this.state.responseResolver}</span>
</Alert>}
</FormGroup> </FormGroup>
</Form> </Form>

View File

@ -61,9 +61,9 @@ class App extends React.Component {
} }
handleSelect(key) { handleSelect(key) {
if (key == 2) { if (key === 2) {
EmbarkJS.Names.setProvider('ipns', {server: 'localhost', port: '5001'}); EmbarkJS.Names.setProvider('ipns', {server: 'localhost', port: '5001'});
} else if (key == 4) { } else if (key === 4) {
EmbarkJS.Names.currentNameSystems = this.state.ensNameSystems EmbarkJS.Names.currentNameSystems = this.state.ensNameSystems
} }
this.setState({ activeKey: key }); this.setState({ activeKey: key });