Get proposals
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Object.extend({
|
||||||
|
|
||||||
|
creator: null,
|
||||||
|
recipient: null,
|
||||||
|
votesCount: null,
|
||||||
|
votesNeeded: null,
|
||||||
|
amount: null,
|
||||||
|
executed: null,
|
||||||
|
url: null,
|
||||||
|
ipfsHash: null
|
||||||
|
|
||||||
|
});
|
||||||
+6
-3
@@ -5,10 +5,13 @@ export default Ember.Route.extend({
|
|||||||
kredits: Ember.inject.service(),
|
kredits: Ember.inject.service(),
|
||||||
|
|
||||||
model() {
|
model() {
|
||||||
|
let kredits = this.get('kredits');
|
||||||
|
|
||||||
return Ember.RSVP.hash({
|
return Ember.RSVP.hash({
|
||||||
contributors: this.get('kredits').getContributors(),
|
contributors: kredits.getContributors(),
|
||||||
totalSupply: this.get('kredits').getValueFromContract('totalSupply'),
|
totalSupply: kredits.getValueFromContract('totalSupply'),
|
||||||
contributorsCount: this.get('kredits').getValueFromContract('contributorsCount')
|
contributorsCount: kredits.getValueFromContract('contributorsCount'),
|
||||||
|
proposals: kredits.getProposals()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import Ember from 'ember';
|
|||||||
import Web3 from 'npm:web3';
|
import Web3 from 'npm:web3';
|
||||||
import config from 'kredits-web/config/environment';
|
import config from 'kredits-web/config/environment';
|
||||||
import Contributor from 'kredits-web/models/contributor';
|
import Contributor from 'kredits-web/models/contributor';
|
||||||
|
import Proposal from 'kredits-web/models/proposal';
|
||||||
|
|
||||||
export default Ember.Service.extend({
|
export default Ember.Service.extend({
|
||||||
|
|
||||||
@@ -82,6 +83,38 @@ export default Ember.Service.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getProposalData(i) {
|
||||||
|
let promise = new Ember.RSVP.Promise((resolve, reject) => {
|
||||||
|
this.getValueFromContract('proposals', i).then(p => {
|
||||||
|
let proposal = Proposal.create({
|
||||||
|
creatorAddress : p[0],
|
||||||
|
recipientAddress : p[1],
|
||||||
|
votesCount : p[2].toNumber(),
|
||||||
|
votesNeeded : p[3].toNumber(),
|
||||||
|
amount : p[4].toNumber(),
|
||||||
|
executed : p[5],
|
||||||
|
url : p[6],
|
||||||
|
ipfsHash : p[7]
|
||||||
|
});
|
||||||
|
Ember.Logger.debug('[kredits] proposal', proposal);
|
||||||
|
resolve(proposal);
|
||||||
|
}).catch(err => reject(err));
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
},
|
||||||
|
|
||||||
|
getProposals() {
|
||||||
|
return this.getValueFromContract('proposalsCount').then(proposalsCount => {
|
||||||
|
let proposals = [];
|
||||||
|
|
||||||
|
for(var i = 0; i < proposalsCount.toNumber(); i++) {
|
||||||
|
proposals.push(this.getProposalData(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ember.RSVP.all(proposals);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
logKreditsContract: function() {
|
logKreditsContract: function() {
|
||||||
Ember.Logger.debug('[kredits] kreditsContract', this.get('kreditsContract'));
|
Ember.Logger.debug('[kredits] kreditsContract', this.get('kreditsContract'));
|
||||||
}.on('init')
|
}.on('init')
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { moduleFor, test } from 'ember-qunit';
|
||||||
|
|
||||||
|
moduleFor('model:proposal', 'Unit | Model | proposal');
|
||||||
|
|
||||||
|
test('it exists', function(assert) {
|
||||||
|
let model = this.subject();
|
||||||
|
// let store = this.store();
|
||||||
|
assert.ok(!!model);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user