Create contribution IPFS objects, attach to proposals
This commit is contained in:
@@ -2,6 +2,7 @@ import Ember from 'ember';
|
||||
|
||||
const {
|
||||
Component,
|
||||
isPresent,
|
||||
inject: {
|
||||
service
|
||||
},
|
||||
@@ -13,6 +14,7 @@ export default Component.extend({
|
||||
kredits: service(),
|
||||
|
||||
proposal: null,
|
||||
contributors: null,
|
||||
inProgress: false,
|
||||
|
||||
isValidRecipient: computed('proposal.recipientAddress', function() {
|
||||
@@ -24,35 +26,39 @@ export default Component.extend({
|
||||
}),
|
||||
|
||||
isValidUrl: computed('proposal.url', function() {
|
||||
// TODO
|
||||
return true;
|
||||
return isPresent(this.get('proposal.url'));
|
||||
}),
|
||||
|
||||
isValidIpfsHash: computed('proposal.ipfsHash', function() {
|
||||
// TODO
|
||||
return true;
|
||||
isValidDescription: computed('proposal.description', function() {
|
||||
return isPresent(this.get('proposal.description'));
|
||||
}),
|
||||
|
||||
isValid: computed.and('isValidRecipient', 'isValidAmount', 'isValidUrl',
|
||||
'isValidIpfsHash'),
|
||||
isValid: computed.and('isValidRecipient',
|
||||
'isValidAmount',
|
||||
'isValidDescription'),
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
if (this.get('isValid')) {
|
||||
this.set('inProgress', true);
|
||||
|
||||
this.get('kredits').addProposal(this.get('proposal'))
|
||||
.then(() => {
|
||||
this.attrs.onSave();
|
||||
}).catch((error) => {
|
||||
Ember.Logger.error('[add-proposal] error creating the proposal', error);
|
||||
alert('Something went wrong.');
|
||||
}).finally(() => {
|
||||
this.set('inProgress', false);
|
||||
});
|
||||
} else {
|
||||
if (! this.get('isValid')) {
|
||||
alert('Invalid data. Please review and try again.');
|
||||
}
|
||||
this.set('inProgress', true);
|
||||
let proposal = this.get('proposal');
|
||||
|
||||
// Set the recipient's IPFS profile hash so it can be used in the
|
||||
// contribution object (which is to be stored in IPFS as well)
|
||||
let contributor = this.get('contributors').findBy('address', proposal.get('recipientAddress'));
|
||||
proposal.set('recipientProfile', contributor.get('ipfsHash'));
|
||||
|
||||
this.get('kredits').addProposal(proposal)
|
||||
.then(() => {
|
||||
this.attrs.onSave();
|
||||
}).catch((error) => {
|
||||
Ember.Logger.error('[add-proposal] error creating the proposal', error);
|
||||
alert('Something went wrong.');
|
||||
}).finally(() => {
|
||||
this.set('inProgress', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user