Show unconfirmed balances in toplist #112

Merged
raucao merged 10 commits from feature/111-unconfirmed_balances into master 2019-05-01 19:30:36 +00:00
3 changed files with 71 additions and 24 deletions
Showing only changes of commit 185d7c58c2 - Show all commits
+3 -24
View File
@@ -2,12 +2,12 @@ import ethers from 'npm:ethers';
import Kredits from 'npm:kredits-contracts';
import RSVP from 'rsvp';
import { A } from '@ember/array';
import Service from '@ember/service';
import { computed, get } from '@ember/object';
import { computed } from '@ember/object';
import { alias, notEmpty } from '@ember/object/computed';
import { isEmpty, isPresent } from '@ember/utils';
import { isEmpty } from '@ember/utils';
import groupBy from 'kredits-web/utils/group-by';
import formatKredits from 'kredits-web/utils/format-kredits';
import config from 'kredits-web/config/environment';
@@ -15,27 +15,6 @@ import Contributor from 'kredits-web/models/contributor'
import Proposal from 'kredits-web/models/proposal'
import Contribution from 'kredits-web/models/contribution'
function groupBy (collection, property) {
let groups = A();
let items = collection;
if (items) {
items.forEach(function(item) {
let value = get(item, property);
let group = groups.findBy('value', value);
if (isPresent(group)) {
get(group, 'items').push(item);
} else {
group = { property: property, value: value, items: [item] };
groups.push(group);
}
});
}
return groups;
}
export default Service.extend({
currentBlock: null,
+27
View File
@@ -0,0 +1,27 @@
//
// Code from https://github.com/HeroicEric/ember-group-by (MIT licensed)
//
import { A } from '@ember/array';
import { get } from '@ember/object';
import { isPresent } from '@ember/utils';
export default function groupBy (collection, property) {
let groups = A();
let items = collection;
if (items) {
bumi commented 2019-05-01 18:43:59 +00:00 (Migrated from github.com)
Review

maybe
if(!items) {
return groups;
}

maybe if(!items) { return groups; }
raucao commented 2019-05-01 18:53:01 +00:00 (Migrated from github.com)
Review

Did you see that you can now suggest changes to commit in code comments? It's the first icon button in the comment topbar. Makes it much easier to see what the suggested change is as well, because the code behind the comment isn't cut off then...

Never mind, it's a bigger change.

<del>Did you see that you can now suggest changes to commit in code comments? It's the first icon button in the comment topbar. Makes it much easier to see what the suggested change is as well, because the code behind the comment isn't cut off then...</del> Never mind, it's a bigger change.
raucao commented 2019-05-01 18:55:03 +00:00 (Migrated from github.com)
Review

I think a single return is a bit cleaner here.

I think a single return is a bit cleaner here.
items.forEach(function(item) {
let value = get(item, property);
let group = groups.findBy('value', value);
if (isPresent(group)) {
get(group, 'items').push(item);
} else {
group = { property: property, value: value, items: [item] };
groups.push(group);
}
});
}
return groups;
}
+41
View File
@@ -0,0 +1,41 @@
//
// Code adapted from https://github.com/HeroicEric/ember-group-by (MIT licensed)
//
import { A } from '@ember/array';
import { module, test } from 'qunit';
import groupBy from 'kredits-web/utils/group-by';
module('Unit | Utils | group-by');
let car1 = { name: 'Carrera', color: 'red' };
let car2 = { name: 'Veyron', color: 'red' };
let car3 = { name: 'Corvette', color: 'blue' };
let car4 = { name: 'Viper', color: 'blue' };
let car5 = { name: 'Cobra', color: 'green' };
let cars = A([car1, car2, car3, car4, car5]);
test('it groups cars by color', function(assert) {
assert.expect(1);
let redGroup = { property: 'color', value: 'red', items: [car1, car2] };
let blueGroup = { property: 'color', value: 'blue', items: [car3, car4] };
let greenGroup = { property: 'color', value: 'green', items: [car5] };
let result = groupBy(cars, 'color');
let expected = [redGroup, blueGroup, greenGroup];
assert.deepEqual(result, expected);
});
test('it does not fail with empty array', function(assert) {
let cars = [];
let result = groupBy(cars, 'color');
assert.deepEqual(result, []);
});
test('it does not failkwith null', function(assert) {
let cars = null;
let result = groupBy(cars, 'color');
assert.deepEqual(result, []);
});