connect add contributor form to ethereum

This commit is contained in:
2017-02-08 13:44:27 +08:00
parent 1de2e002bb
commit d05356cfe4
5 changed files with 68 additions and 19 deletions
+41 -14
View File
@@ -5,31 +5,58 @@ export default Ember.Component.extend({
id: null, id: null,
realName: null, realName: null,
address: null, address: null,
ipfsHash: null,
isCore: true,
classId: function() { inProgress: false,
let value = this.get('id');
return (Ember.isEmpty(value)) ? null : 'valid'; isValidId: function() {
return Ember.isPresent(this.get('id'));
}.property('id'), }.property('id'),
classRealName: function() { isValidRealName: function() {
let value = this.get('realName'); return Ember.isPresent(this.get('realName'))
return (Ember.isEmpty(value)) ? null : 'valid';
}.property('realName'), }.property('realName'),
classAddress: function() { isValidAddress: function() {
let value = this.get('address'); return this.get('kredits.web3Instance').isAddress(this.get('address'));
return (Ember.isEmpty(value)) ? null : 'valid';
}.property('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: { actions: {
save() { save() {
console.log('id', this.get('id')); if(this.get('isValid')) {
console.log('realName', this.get('realName')); this.set('inProgress', true);
console.log('address', this.get('address')); 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');
}
} }
} }
}); });
+4 -4
View File
@@ -4,23 +4,23 @@
type="text" type="text"
placeholder="GitHub UID (123)" placeholder="GitHub UID (123)"
value=id value=id
class=classId}} class=(if isValidId 'valid' '')}}
</p> </p>
<p> <p>
{{input name="realname" {{input name="realname"
type="text" type="text"
placeholder="Carl Sagan" placeholder="Carl Sagan"
value=realName value=realName
class=classRealName}} class=(if isValidRealName 'valid' '')}}
</p> </p>
<p> <p>
{{input name="address" {{input name="address"
type="text" type="text"
placeholder="0xF18E631Ea191aE4ebE70046Fcb01a436554421BA4" placeholder="0xF18E631Ea191aE4ebE70046Fcb01a436554421BA4"
value=address value=address
class=classAddress}} class=(if isValidAddress 'valid' '')}}
</p> </p>
<p class="actions"> <p class="actions">
<input type="submit" value="Save"> {{input type="submit" value=(if inProgress 'Processing' 'Save') disabled=inProgress}}
</p> </p>
</form> </form>
+19
View File
@@ -38,6 +38,7 @@ export default Ember.Service.extend({
return this.get('kreditsContractInstance'); return this.get('kreditsContractInstance');
} }
console.log(config.ethereumChain);
let contract = kreditsContracts(this.get('web3'), config.ethereumChain)['Kredits']; let contract = kreditsContracts(this.get('web3'), config.ethereumChain)['Kredits'];
this.set('kreditsContractInstance', contract); 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() { logKreditsContract: function() {
Ember.Logger.debug('[kredits] kreditsContract', this.get('kreditsContract')); Ember.Logger.debug('[kredits] kreditsContract', this.get('kreditsContract'));
}.on('init') }.on('init')
@@ -26,6 +26,9 @@ section#add-contributor {
input[type=submit] { input[type=submit] {
padding: 0.6rem 2rem; padding: 0.6rem 2rem;
&:disabled {
background-color: transparent;
}
} }
} }
+1 -1
View File
@@ -42,6 +42,6 @@
</header> </header>
<div class="content"> <div class="content">
{{add-contributor kredits=kredits}} {{add-contributor kredits=kredits contributors=model.contributors}}
</div> </div>
</section> </section>