diff --git a/app/models/contributor.js b/app/models/contributor.js index 7840199..ebe41ea 100644 --- a/app/models/contributor.js +++ b/app/models/contributor.js @@ -11,6 +11,20 @@ export default Ember.Object.extend({ avatarURL: function() { return `https\:\/\/avatars2.githubusercontent.com/u/${this.get('github_uid')}?v=3&s=128`; - }.property('github_uid') + }.property('github_uid'), + + serialize() { + return JSON.stringify({ + profiles: { + 'github.com': { + uid: this.get('github_uid'), + username: this.get('github_username'), + } + // 'wiki.kosmos.org': { + // username: this.get('wiki_username') + // } + } + }); + } }); diff --git a/app/services/ipfs.js b/app/services/ipfs.js index e3f9f41..453a005 100644 --- a/app/services/ipfs.js +++ b/app/services/ipfs.js @@ -18,6 +18,7 @@ export default Ember.Service.extend({ storeFile(content) { let ipfs = this.get('ipfs'); return ipfs.add(new ipfs.Buffer(content)).then(res => { + Ember.Logger.debug('[ipfs] stored content in IPFS', content, res[0].hash); return res[0].hash; }); }, diff --git a/app/services/kredits.js b/app/services/kredits.js index 2f3d7d1..6479360 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -140,19 +140,23 @@ export default Ember.Service.extend({ addContributor(address, name, ipfsHash, isCore, id) { Ember.Logger.debug('[kredits] add contributor', name, address); + + let contributor = Contributor.create({ + address: address, + github_username: name, + github_uid: id, + kredits: 0, + isCurrentUser: this.get('currentUserAccounts').includes(address) + }); + return new Ember.RSVP.Promise((resolve, reject) => { - this.get('kreditsContract').addContributor(address, name, ipfsHash, isCore, id, (err, data) => { - if (err) { reject(err); } - Ember.Logger.debug('[kredits] add contributor response', data); - let contributor = Contributor.create({ - address: address, - github_username: name, - github_uid: id, - ipfsHash: ipfsHash, - kredits: 0, - isCurrentUser: this.get('currentUserAccounts').includes(address) + this.get('ipfs').storeFile(contributor.serialize()).then(ipfsHash => { + contributor.set('ipfsHash', ipfsHash); + this.get('kreditsContract').addContributor(address, name, ipfsHash, isCore, id, (err, data) => { + if (err) { reject(err); } + Ember.Logger.debug('[kredits] add contributor response', data); + resolve(contributor); }); - resolve(contributor); }); }); },