Load contribution details from IPFS
This commit is contained in:
@@ -23,6 +23,39 @@ export default Ember.Object.extend({
|
||||
details: null,
|
||||
ipfsHash: null,
|
||||
|
||||
/**
|
||||
* Loads the contribution details from IPFS and sets local instance
|
||||
* properties from it
|
||||
*
|
||||
* @method
|
||||
* @public
|
||||
*/
|
||||
loadContribution(ipfs) {
|
||||
let promise = new Ember.RSVP.Promise((resolve, reject) => {
|
||||
ipfs.getFile(this.get('ipfsHash')).then(content => {
|
||||
let contributionJSON = JSON.parse(content);
|
||||
let contribution = Ember.Object.create(contributionJSON);
|
||||
|
||||
this.setProperties({
|
||||
kind: contribution.get('kind'),
|
||||
description: contribution.get('description'),
|
||||
url: contribution.get('url')
|
||||
});
|
||||
|
||||
// TODO load details
|
||||
// let details = profile.get('accounts');
|
||||
|
||||
Ember.Logger.debug('[proposal] loaded contribution details', contributionJSON);
|
||||
resolve();
|
||||
}).catch((err) => {
|
||||
Ember.Logger.error('[proposal] error trying to load contribution details', this.get('ipfsHash'), err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
return promise;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a JSON-LD object of the contribution, according to
|
||||
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contribution.json
|
||||
|
||||
+10
-2
@@ -148,8 +148,16 @@ export default Service.extend({
|
||||
url : p[6],
|
||||
ipfsHash : p[7]
|
||||
});
|
||||
Ember.Logger.debug('[kredits] proposal', proposal);
|
||||
resolve(proposal);
|
||||
|
||||
if (proposal.get('ipfsHash')) {
|
||||
proposal.loadContribution(this.get('ipfs')).then(
|
||||
() => resolve(proposal),
|
||||
err => reject(err)
|
||||
);
|
||||
} else {
|
||||
Ember.Logger.warn('[kredits] proposal from blockchain is missing IPFS hash', proposal);
|
||||
resolve(proposal);
|
||||
}
|
||||
}).catch(err => reject(err));
|
||||
});
|
||||
return promise;
|
||||
|
||||
Reference in New Issue
Block a user