Veto contributions #113
@@ -0,0 +1,20 @@
|
||||
import Helper from '@ember/component/helper';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { alias } from '@ember/object/computed';
|
||||
|
||||
export default Helper.extend({
|
||||
|
||||
kredits: service(),
|
||||
currentBlock: alias('kredits.currentBlock'),
|
||||
|
||||
compute([contribution]) {
|
||||
|
|
||||
if (contribution.vetoed) {
|
||||
return 'vetoed';
|
||||
} else if (contribution.confirmedAt > this.currentBlock) {
|
||||
return 'unconfirmed';
|
||||
} else {
|
||||
return 'confirmed'
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import Helper from '@ember/component/helper';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { alias } from '@ember/object/computed';
|
||||
|
||||
export default Helper.extend({
|
||||
|
||||
kredits: service(),
|
||||
currentBlock: alias('kredits.currentBlock'),
|
||||
|
||||
compute([contribution]) {
|
||||
return !contribution.vetoed &&
|
||||
(contribution.confirmedAt <= this.currentBlock);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Helper | contribution-status', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('returns the appropriate status', function (assert) {
|
||||
const contributionStatus = this.owner.factoryFor('helper:contribution-status').create();
|
||||
const kredits = this.owner.lookup('service:kredits');
|
||||
|
||||
kredits.set('currentBlock', 23000);
|
||||
|
||||
const contributionUnconfirmed = { confirmedAt: 23001, vetoed: false };
|
||||
const contributionConfirmed = { confirmedAt: 21000, vetoed: false };
|
||||
const contributionVetoed = { confirmedAt: 23001, vetoed: true };
|
||||
|
||||
assert.eq(contributionStatus.compute([contributionUnconfirmed]), 'unconfirmed');
|
||||
assert.eq(contributionStatus.compute([contributionConfirmed]), 'confirmed');
|
||||
assert.eq(contributionStatus.compute([contributionVetoed]), 'vetoed');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Helper | contribution-status', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('returns the appropriate status', function (assert) {
|
||||
const contributionStatus = this.owner.factoryFor('helper:contribution-status').create();
|
||||
const kredits = this.owner.lookup('service:kredits');
|
||||
|
||||
kredits.set('currentBlock', 23000);
|
||||
|
||||
const contributionUnconfirmed = { confirmedAt: 23001, vetoed: false };
|
||||
const contributionConfirmed = { confirmedAt: 21000, vetoed: false };
|
||||
const contributionVetoed = { confirmedAt: 23001, vetoed: true };
|
||||
|
||||
assert.notOk(contributionStatus.compute([contributionUnconfirmed]), 'unconfirmed');
|
||||
assert.notOk(contributionStatus.compute([contributionVetoed]), 'vetoed');
|
||||
assert.ok(contributionStatus.compute([contributionConfirmed]), 'confirmed');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user
can this also be something on the model? (#rubythinking :)
No, because you cannot inject services into a model.