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,
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');
}
}
}
});
+4 -4
View File
@@ -4,23 +4,23 @@
type="text"
placeholder="GitHub UID (123)"
value=id
class=classId}}
class=(if isValidId 'valid' '')}}
</p>
<p>
{{input name="realname"
type="text"
placeholder="Carl Sagan"
value=realName
class=classRealName}}
class=(if isValidRealName 'valid' '')}}
</p>
<p>
{{input name="address"
type="text"
placeholder="0xF18E631Ea191aE4ebE70046Fcb01a436554421BA4"
value=address
class=classAddress}}
class=(if isValidAddress 'valid' '')}}
</p>
<p class="actions">
<input type="submit" value="Save">
{{input type="submit" value=(if inProgress 'Processing' 'Save') disabled=inProgress}}
</p>
</form>
+19
View File
@@ -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')
@@ -26,6 +26,9 @@ section#add-contributor {
input[type=submit] {
padding: 0.6rem 2rem;
&:disabled {
background-color: transparent;
}
}
}
+1 -1
View File
@@ -42,6 +42,6 @@
</header>
<div class="content">
{{add-contributor kredits=kredits}}
{{add-contributor kredits=kredits contributors=model.contributors}}
</div>
</section>