diff --git a/app/components/add-contributor/component.js b/app/components/add-contributor/component.js index db067b9..96c644a 100644 --- a/app/components/add-contributor/component.js +++ b/app/components/add-contributor/component.js @@ -5,31 +5,58 @@ export default Ember.Component.extend({ id: null, realName: null, address: null, + ipfsHash: null, + isCore: true, - classId: function() { - let value = this.get('id'); - return (Ember.isEmpty(value)) ? null : 'valid'; + inProgress: false, + + isValidId: function() { + return Ember.isPresent(this.get('id')); }.property('id'), - classRealName: function() { - let value = this.get('realName'); - return (Ember.isEmpty(value)) ? null : 'valid'; + isValidRealName: function() { + return Ember.isPresent(this.get('realName')) }.property('realName'), - classAddress: function() { - let value = this.get('address'); - return (Ember.isEmpty(value)) ? null : 'valid'; + isValidAddress: function() { + return this.get('kredits.web3Instance').isAddress(this.get('address')); }.property('address'), + isValid: function() { + return this.get('isValidId') && this.get('isValidRealName') && this.get('isValidAddress'); + }.property('isValidAddress', 'isValidId', 'isValidRealName'), + + reset: function() { + this.setProperties({ + id: null, + realName: null, + address: null, + ipfsHash: null, + isCore: true, + inProgress: false + }); + + }, actions: { - save() { - console.log('id', this.get('id')); - console.log('realName', this.get('realName')); - console.log('address', this.get('address')); + if(this.get('isValid')) { + this.set('inProgress', true); + this.get('kredits').addContributor( + this.get('address'), + this.get('realName'), + '', // TODO: this.get('ipfsHash') + this.get('isCore'), + this.get('id') + ).then(contributor => { + this.reset(); + this.get('contributors').pushObject(contributor); + window.scroll(0,0); + }); + } else { + alert('invalid data. please review'); + } } - } }); diff --git a/app/components/add-contributor/template.hbs b/app/components/add-contributor/template.hbs index 9ef8f6b..4885873 100644 --- a/app/components/add-contributor/template.hbs +++ b/app/components/add-contributor/template.hbs @@ -4,23 +4,23 @@ type="text" placeholder="GitHub UID (123)" value=id - class=classId}} + class=(if isValidId 'valid' '')}}

{{input name="realname" type="text" placeholder="Carl Sagan" value=realName - class=classRealName}} + class=(if isValidRealName 'valid' '')}}

{{input name="address" type="text" placeholder="0xF18E631Ea191aE4ebE70046Fcb01a436554421BA4" value=address - class=classAddress}} + class=(if isValidAddress 'valid' '')}}

- + {{input type="submit" value=(if inProgress 'Processing' 'Save') disabled=inProgress}}

diff --git a/app/services/kredits.js b/app/services/kredits.js index 54ae838..4312148 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -38,6 +38,7 @@ export default Ember.Service.extend({ return this.get('kreditsContractInstance'); } + console.log(config.ethereumChain); let contract = kreditsContracts(this.get('web3'), config.ethereumChain)['Kredits']; this.set('kreditsContractInstance', contract); @@ -130,6 +131,24 @@ export default Ember.Service.extend({ }); }, + addContributor(address, name, ipfsHash, isCore, id) { + Ember.Logger.debug('[kredits] add contributor', name, 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 + }); + resolve(contributor); + }); + }); + }, + logKreditsContract: function() { Ember.Logger.debug('[kredits] kreditsContract', this.get('kreditsContract')); }.on('init') diff --git a/app/styles/components/_add-contributor.scss b/app/styles/components/_add-contributor.scss index fb6f754..a17667e 100644 --- a/app/styles/components/_add-contributor.scss +++ b/app/styles/components/_add-contributor.scss @@ -26,6 +26,9 @@ section#add-contributor { input[type=submit] { padding: 0.6rem 2rem; + &:disabled { + background-color: transparent; + } } } diff --git a/app/templates/index.hbs b/app/templates/index.hbs index adf4053..5ce1c70 100644 --- a/app/templates/index.hbs +++ b/app/templates/index.hbs @@ -42,6 +42,6 @@
- {{add-contributor kredits=kredits}} + {{add-contributor kredits=kredits contributors=model.contributors}}