PR feedback

This commit is contained in:
Anthony Laibe 2018-07-30 17:06:20 +01:00
parent 93dfac8e5d
commit d90774a50e
6 changed files with 51 additions and 35 deletions

View File

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

View File

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

2
package-lock.json generated
View File

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

View File

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

View File

@ -18,8 +18,8 @@ class Storage extends React.Component {
url: '',
logs: [],
storageError: '',
ipfsHash: '',
ipnsResolveName: '',
valueRegister: '',
valueResolver: '',
};
}
@ -101,34 +101,45 @@ class Storage extends React.Component {
ipnsRegister(e) {
e.preventDefault();
this.setState({ ipnsRegistering: true });
EmbarkJS.Names.register(this.state.ipfsHash, (err, name) => {
this.setState({ registering: true, responseRegister: false });
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) {
console.log("Name Register Error => " + err.message);
isRegisterError = true;
responseRegister = "Name Register Error: " + err.message
} else {
responseRegister = name;
}
this.setState({
ipnsResolveName: name,
ipnsName: name,
ipnsRegistering: false
responseRegister: responseRegister,
registering: false,
isRegisterError: isRegisterError
});
this.addToLog("EmbarkJS.Names.register(this.state.ipfsHash).then(function(hash) { })");
});
}
ipnsResolve(e) {
e.preventDefault();
this.setState({ ipnsResolving: true });
EmbarkJS.Names.resolve(this.state.ipnsName, (err, path) => {
this.setState({ resolving: true, responseResolver: false });
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) {
console.log("Name Resolve Error => " + err.message);
isResolverError = true;
responseResolver = "Name Resolve Error: " + err.message
} else {
responseResolver = path;
}
this.setState({
ipfsPath: path,
ipnsResolving: false
responseResolver: responseResolver,
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>
<FormControl
type="text"
value={this.state.ipfsHash}
onChange={e => this.handleChange(e, 'ipfsHash')}/>
value={this.state.valueRegister}
onChange={e => this.handleChange(e, 'valueRegister')}/>
<Button bsStyle="primary" onClick={(e) => this.ipnsRegister(e)}>
{this.state.ipnsRegistering ? 'Registering...' : 'Register' }
{this.state.registering ? 'Registering...' : 'Register' }
</Button>
<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>
</Form>
@ -216,13 +230,16 @@ class Storage extends React.Component {
<FormGroup>
<FormControl
type="text"
value={this.state.ipnsResolveName}
onChange={e => this.handleChange(e, 'ipnsResolveName')}/>
value={this.state.valueResolver}
onChange={e => this.handleChange(e, 'valueResolver')}/>
<Button bsStyle="primary" onClick={(e) => this.ipnsResolve(e)}>
{this.state.ipnsResolving ? 'Resolving...' : 'Resolve' }
{this.state.resolving ? 'Resolving...' : 'Resolve' }
</Button>
<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>
</Form>

View File

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