connect add contributor form to ethereum
This commit is contained in:
@@ -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,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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,6 @@
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
{{add-contributor kredits=kredits}}
|
||||
{{add-contributor kredits=kredits contributors=model.contributors}}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user