Load contribution details from IPFS
This commit is contained in:
@@ -23,6 +23,39 @@ export default Ember.Object.extend({
|
|||||||
details: null,
|
details: null,
|
||||||
ipfsHash: 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
|
* Creates a JSON-LD object of the contribution, according to
|
||||||
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contribution.json
|
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contribution.json
|
||||||
|
|||||||
@@ -148,8 +148,16 @@ export default Service.extend({
|
|||||||
url : p[6],
|
url : p[6],
|
||||||
ipfsHash : p[7]
|
ipfsHash : p[7]
|
||||||
});
|
});
|
||||||
Ember.Logger.debug('[kredits] proposal', 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);
|
resolve(proposal);
|
||||||
|
}
|
||||||
}).catch(err => reject(err));
|
}).catch(err => reject(err));
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
|
|||||||
Reference in New Issue
Block a user