diff --git a/app/models/proposal.js b/app/models/proposal.js index ea59765..6d01d27 100644 --- a/app/models/proposal.js +++ b/app/models/proposal.js @@ -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 diff --git a/app/services/kredits.js b/app/services/kredits.js index e133093..7a844f2 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -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;