Process contribution data before loading models

This commit is contained in:
basti committed 2020-05-28 13:44:32 +02:00
1 parent e7c9620bbe
commit 69141a31c4
10 files changed
+501 -34

No files matched your search

+11 -5
View File
@@ -1,6 +1,5 @@
import EmberObject, { computed } from '@ember/object';
import { isEmpty, isPresent } from '@ember/utils';
import bignumber from 'kredits-web/utils/cps/bignumber';
import moment from 'moment';
export default EmberObject.extend({
@@ -9,11 +8,15 @@ export default EmberObject.extend({
id: null,
contributorId: null,
amount: null,
confirmedAt: bignumber('confirmedAtBlock', 'toNumber'),
confirmedAt: null,
vetoed: null,
ipfsHash: null,
creatorAccount: null,
// contributor model instance
contributor: null,
// TODO contributor who submitted the contribution
// submittedBy: null,
// IPFS
kind: null,
@@ -22,7 +25,6 @@ export default EmberObject.extend({
url: null,
date: null,
time: null,
ipfsData: '',
pendingTx: null,
@@ -41,6 +43,10 @@ export default EmberObject.extend({
hasPendingChanges: computed('pendingTx', function() {
return isPresent(this.pendingTx);
})
}),
serialize () {
return JSON.stringify(this);
}
});
+1
View File
@@ -22,4 +22,5 @@ export default EmberObject.extend({
serialize () {
return JSON.stringify(this);
}
});
+26 -12
View File
@@ -11,6 +11,7 @@ import { inject as service } from '@ember/service';
import groupBy from 'kredits-web/utils/group-by';
import processContributorData from 'kredits-web/utils/process-contributor-data';
import processContributionData from 'kredits-web/utils/process-contribution-data';
import formatKredits from 'kredits-web/utils/format-kredits';
import config from 'kredits-web/config/environment';
@@ -185,11 +186,11 @@ export default Service.extend({
}
const numCachedContributions = await this.browserCache.contributions.length();
if (numCachedContributions > 0) {
// if (numCachedContributions > 0) {
// TODO promises.push(this.loadContributionsFromCache);
} else {
// } else {
await this.fetchContributions({ page: { size: 30 } });
}
// }
return Promise.resolve();
},
@@ -235,11 +236,11 @@ export default Service.extend({
});
})
.then(() => {
return this.cacheContributors();
return this.cacheLoadedContributors();
});
},
async cacheContributors () {
async cacheLoadedContributors () {
for (const c of this.contributors) {
await this.browserCache.contributors.setItem(c.id, c.serialize());
}
@@ -248,9 +249,9 @@ export default Service.extend({
},
async loadContributorsFromCache () {
return this.browserCache.contributors.iterate((value, key/* , iterationNumber */) => {
return this.browserCache.contributors.iterate((value/*, key , iterationNumber */) => {
this.contributors.pushObject(Contributor.create(JSON.parse(value)));
}).then(result => {
}).then((/* result */) => {
console.debug(`[kredits] Loaded ${this.contributors.length} contributors from cache`);
});
},
@@ -275,15 +276,28 @@ export default Service.extend({
return this.kredits.Contribution.all(options)
.then(contributions => {
return contributions.map(data => {
data.contributor = this.contributors.findBy('id', data.contributorId.toString());
const contribution = Contribution.create(data);
const contribution = Contribution.create(processContributionData(data));
contribution.set('contributor', this.contributors.findBy('id', data.contributorId.toString()));
this.contributions.pushObject(contribution);
return contribution;
});
})
.then(contributions => {
const cacheWrites = contributions.map(c => {
return this.browserCache.contributions.setItem(c.id.toString(), c.serialize());
});
return Promise.all(cacheWrites).then(() => {
console.debug(`[kredits] Cached ${contributions.length} contributions in browser storage`);
});
});
// TODO .then(() => {
// this.cacheContributions()
// });
},
async cacheLoadedContributions () {
for (const c of this.contributions) {
await this.browserCache.contributions.setItem(c.id, c.serialize());
}
console.debug(`[kredits] Cached ${this.contributions.length} contributions in browser storage`);
return Promise.resolve();
},
veto (contributionId) {
+21
View File
@@ -0,0 +1,21 @@
export default function processContributionData(data) {
const processed = {}
if (data.confirmedAtBlock && (typeof data.confirmedAtBlock.toNumber === 'function')) {
processed.confirmedAt = data.confirmedAtBlock.toNumber();
} else if (data.confirmedAt !== 'undefined') {
processed.confirmedAt = data.confirmedAt;
}
const otherProperties = [
'id', 'contributorId', 'amount', 'vetoed',
'ipfsHash', 'kind', 'description', 'details',
'url', 'date', 'time', 'pendingTx'
];
otherProperties.forEach(prop => {
processed[prop] = data[prop];
});
return processed;
}
+1 -1
View File
@@ -3,7 +3,7 @@ export default function processContributorData(data) {
id: data.id.toString(),
balance: data.balanceInt,
totalKreditsEarned: data.totalKreditsEarned,
contributionsCount: data.contributionsCount.toNumber()
contributionsCount: data.contributionsCount?.toNumber()
}
const otherProperties = [
+391
View File
@@ -0,0 +1,391 @@
export default {
"0": 511,
"1": 1,
"2": 500,
"3": false,
"4": "0x4e918f5b0199311fffa2c930cd6ec8e82de65d4caa5a84e6e850c9c956a92ed7",
"5": 18,
"6": 32,
"7": {
"_hex": "0x64bf54"
},
"8": true,
"9": false,
"id": 511,
"contributorId": 1,
"amount": 500,
"claimed": false,
"hashDigest": "0x4e918f5b0199311fffa2c930cd6ec8e82de65d4caa5a84e6e850c9c956a92ed7",
"hashFunction": 18,
"hashSize": 32,
"confirmedAtBlock": {
"_hex": "0x64bf54",
"toNumber": function() { return 6602580; }
},
"exists": true,
"vetoed": false,
"ipfsHash": "QmTdMF6u8TBNp2riP43m8p49VxMasS73Qbdj3fSo2V8SJ2",
"date": "2020-05-27",
"time": "14:22:41Z",
"kind": "dev",
"description": "67P/kredits-contracts: Chore/dependency updates",
"details": {
"url": "https://api.github.com/repos/67P/kredits-contracts/pulls/196",
"id": 423708597,
"node_id": "MDExOlB1bGxSZXF1ZXN0NDIzNzA4NTk3",
"html_url": "https://github.com/67P/kredits-contracts/pull/196",
"diff_url": "https://github.com/67P/kredits-contracts/pull/196.diff",
"patch_url": "https://github.com/67P/kredits-contracts/pull/196.patch",
"issue_url": "https://api.github.com/repos/67P/kredits-contracts/issues/196",
"number": 196,
"state": "closed",
"locked": false,
"title": "Chore/dependency updates",
"user": {
"login": "bumi",
"id": 318,
"node_id": "MDQ6VXNlcjMxOA==",
"avatar_url": "https://avatars1.githubusercontent.com/u/318?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bumi",
"html_url": "https://github.com/bumi",
"followers_url": "https://api.github.com/users/bumi/followers",
"following_url": "https://api.github.com/users/bumi/following{/other_user}",
"gists_url": "https://api.github.com/users/bumi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bumi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bumi/subscriptions",
"organizations_url": "https://api.github.com/users/bumi/orgs",
"repos_url": "https://api.github.com/users/bumi/repos",
"events_url": "https://api.github.com/users/bumi/events{/privacy}",
"received_events_url": "https://api.github.com/users/bumi/received_events",
"type": "User",
"site_admin": false
},
"body": "Updated the npm dependencies to the latest versions\r\n\r\nmissing: \r\n- [ ] ipfs-http-client - which has some breaking changes. I think it is not a problem for us but needs to be tested\r\n- [ ] solhint - wich also has a breaking change and now needs pretier for codestyle linting. I did not want that additional dependency now. Also we probably needs to improve the linting of the solidity files\r\n",
"created_at": "2020-05-27T08:57:43Z",
"updated_at": "2020-05-27T14:22:41Z",
"closed_at": "2020-05-27T14:22:41Z",
"merged_at": "2020-05-27T14:22:41Z",
"merge_commit_sha": "2b99593699999756f0f49549873f2cfb679d3f4c",
"assignee": null,
"assignees": [],
"requested_reviewers": [],
"requested_teams": [],
"labels": [
{
"id": 923540870,
"node_id": "MDU6TGFiZWw5MjM1NDA4NzA=",
"url": "https://api.github.com/repos/67P/kredits-contracts/labels/kredits-1",
"name": "kredits-1",
"color": "008080",
"default": false,
"description": ""
}
],
"milestone": null,
"draft": false,
"commits_url": "https://api.github.com/repos/67P/kredits-contracts/pulls/196/commits",
"review_comments_url": "https://api.github.com/repos/67P/kredits-contracts/pulls/196/comments",
"review_comment_url": "https://api.github.com/repos/67P/kredits-contracts/pulls/comments{/number}",
"comments_url": "https://api.github.com/repos/67P/kredits-contracts/issues/196/comments",
"statuses_url": "https://api.github.com/repos/67P/kredits-contracts/statuses/606350eb5e173a38a8c5f1b3faf30aa03224065c",
"head": {
"label": "67P:chore/dependency-updates",
"ref": "chore/dependency-updates",
"sha": "606350eb5e173a38a8c5f1b3faf30aa03224065c",
"user": {
"login": "67P",
"id": 9769503,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk3Njk1MDM=",
"avatar_url": "https://avatars1.githubusercontent.com/u/9769503?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/67P",
"html_url": "https://github.com/67P",
"followers_url": "https://api.github.com/users/67P/followers",
"following_url": "https://api.github.com/users/67P/following{/other_user}",
"gists_url": "https://api.github.com/users/67P/gists{/gist_id}",
"starred_url": "https://api.github.com/users/67P/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/67P/subscriptions",
"organizations_url": "https://api.github.com/users/67P/orgs",
"repos_url": "https://api.github.com/users/67P/repos",
"events_url": "https://api.github.com/users/67P/events{/privacy}",
"received_events_url": "https://api.github.com/users/67P/received_events",
"type": "Organization",
"site_admin": false
},
"repo": {
"id": 124804465,
"node_id": "MDEwOlJlcG9zaXRvcnkxMjQ4MDQ0NjU=",
"name": "kredits-contracts",
"full_name": "67P/kredits-contracts",
"private": false,
"owner": {
"login": "67P",
"id": 9769503,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk3Njk1MDM=",
"avatar_url": "https://avatars1.githubusercontent.com/u/9769503?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/67P",
"html_url": "https://github.com/67P",
"followers_url": "https://api.github.com/users/67P/followers",
"following_url": "https://api.github.com/users/67P/following{/other_user}",
"gists_url": "https://api.github.com/users/67P/gists{/gist_id}",
"starred_url": "https://api.github.com/users/67P/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/67P/subscriptions",
"organizations_url": "https://api.github.com/users/67P/orgs",
"repos_url": "https://api.github.com/users/67P/repos",
"events_url": "https://api.github.com/users/67P/events{/privacy}",
"received_events_url": "https://api.github.com/users/67P/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/67P/kredits-contracts",
"description": "Smart contracts and JS API for Kosmos Kredits",
"fork": false,
"url": "https://api.github.com/repos/67P/kredits-contracts",
"forks_url": "https://api.github.com/repos/67P/kredits-contracts/forks",
"keys_url": "https://api.github.com/repos/67P/kredits-contracts/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/67P/kredits-contracts/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/67P/kredits-contracts/teams",
"hooks_url": "https://api.github.com/repos/67P/kredits-contracts/hooks",
"issue_events_url": "https://api.github.com/repos/67P/kredits-contracts/issues/events{/number}",
"events_url": "https://api.github.com/repos/67P/kredits-contracts/events",
"assignees_url": "https://api.github.com/repos/67P/kredits-contracts/assignees{/user}",
"branches_url": "https://api.github.com/repos/67P/kredits-contracts/branches{/branch}",
"tags_url": "https://api.github.com/repos/67P/kredits-contracts/tags",
"blobs_url": "https://api.github.com/repos/67P/kredits-contracts/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/67P/kredits-contracts/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/67P/kredits-contracts/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/67P/kredits-contracts/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/67P/kredits-contracts/statuses/{sha}",
"languages_url": "https://api.github.com/repos/67P/kredits-contracts/languages",
"stargazers_url": "https://api.github.com/repos/67P/kredits-contracts/stargazers",
"contributors_url": "https://api.github.com/repos/67P/kredits-contracts/contributors",
"subscribers_url": "https://api.github.com/repos/67P/kredits-contracts/subscribers",
"subscription_url": "https://api.github.com/repos/67P/kredits-contracts/subscription",
"commits_url": "https://api.github.com/repos/67P/kredits-contracts/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/67P/kredits-contracts/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/67P/kredits-contracts/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/67P/kredits-contracts/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/67P/kredits-contracts/contents/{+path}",
"compare_url": "https://api.github.com/repos/67P/kredits-contracts/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/67P/kredits-contracts/merges",
"archive_url": "https://api.github.com/repos/67P/kredits-contracts/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/67P/kredits-contracts/downloads",
"issues_url": "https://api.github.com/repos/67P/kredits-contracts/issues{/number}",
"pulls_url": "https://api.github.com/repos/67P/kredits-contracts/pulls{/number}",
"milestones_url": "https://api.github.com/repos/67P/kredits-contracts/milestones{/number}",
"notifications_url": "https://api.github.com/repos/67P/kredits-contracts/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/67P/kredits-contracts/labels{/name}",
"releases_url": "https://api.github.com/repos/67P/kredits-contracts/releases{/id}",
"deployments_url": "https://api.github.com/repos/67P/kredits-contracts/deployments",
"created_at": "2018-03-11T22:11:45Z",
"updated_at": "2020-05-07T08:08:30Z",
"pushed_at": "2020-05-27T14:22:41Z",
"git_url": "git://github.com/67P/kredits-contracts.git",
"ssh_url": "git@github.com:67P/kredits-contracts.git",
"clone_url": "https://github.com/67P/kredits-contracts.git",
"svn_url": "https://github.com/67P/kredits-contracts",
"homepage": "https://wiki.kosmos.org/Kredits",
"size": 2289,
"stargazers_count": 3,
"watchers_count": 3,
"language": "JavaScript",
"has_issues": true,
"has_projects": false,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"forks_count": 3,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 35,
"license": null,
"forks": 3,
"open_issues": 35,
"watchers": 3,
"default_branch": "master"
}
},
"base": {
"label": "67P:master",
"ref": "master",
"sha": "31c29ab6d0bf0d4fc4c27dbc1ecbb3d27659cf7e",
"user": {
"login": "67P",
"id": 9769503,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk3Njk1MDM=",
"avatar_url": "https://avatars1.githubusercontent.com/u/9769503?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/67P",
"html_url": "https://github.com/67P",
"followers_url": "https://api.github.com/users/67P/followers",
"following_url": "https://api.github.com/users/67P/following{/other_user}",
"gists_url": "https://api.github.com/users/67P/gists{/gist_id}",
"starred_url": "https://api.github.com/users/67P/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/67P/subscriptions",
"organizations_url": "https://api.github.com/users/67P/orgs",
"repos_url": "https://api.github.com/users/67P/repos",
"events_url": "https://api.github.com/users/67P/events{/privacy}",
"received_events_url": "https://api.github.com/users/67P/received_events",
"type": "Organization",
"site_admin": false
},
"repo": {
"id": 124804465,
"node_id": "MDEwOlJlcG9zaXRvcnkxMjQ4MDQ0NjU=",
"name": "kredits-contracts",
"full_name": "67P/kredits-contracts",
"private": false,
"owner": {
"login": "67P",
"id": 9769503,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjk3Njk1MDM=",
"avatar_url": "https://avatars1.githubusercontent.com/u/9769503?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/67P",
"html_url": "https://github.com/67P",
"followers_url": "https://api.github.com/users/67P/followers",
"following_url": "https://api.github.com/users/67P/following{/other_user}",
"gists_url": "https://api.github.com/users/67P/gists{/gist_id}",
"starred_url": "https://api.github.com/users/67P/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/67P/subscriptions",
"organizations_url": "https://api.github.com/users/67P/orgs",
"repos_url": "https://api.github.com/users/67P/repos",
"events_url": "https://api.github.com/users/67P/events{/privacy}",
"received_events_url": "https://api.github.com/users/67P/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/67P/kredits-contracts",
"description": "Smart contracts and JS API for Kosmos Kredits",
"fork": false,
"url": "https://api.github.com/repos/67P/kredits-contracts",
"forks_url": "https://api.github.com/repos/67P/kredits-contracts/forks",
"keys_url": "https://api.github.com/repos/67P/kredits-contracts/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/67P/kredits-contracts/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/67P/kredits-contracts/teams",
"hooks_url": "https://api.github.com/repos/67P/kredits-contracts/hooks",
"issue_events_url": "https://api.github.com/repos/67P/kredits-contracts/issues/events{/number}",
"events_url": "https://api.github.com/repos/67P/kredits-contracts/events",
"assignees_url": "https://api.github.com/repos/67P/kredits-contracts/assignees{/user}",
"branches_url": "https://api.github.com/repos/67P/kredits-contracts/branches{/branch}",
"tags_url": "https://api.github.com/repos/67P/kredits-contracts/tags",
"blobs_url": "https://api.github.com/repos/67P/kredits-contracts/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/67P/kredits-contracts/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/67P/kredits-contracts/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/67P/kredits-contracts/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/67P/kredits-contracts/statuses/{sha}",
"languages_url": "https://api.github.com/repos/67P/kredits-contracts/languages",
"stargazers_url": "https://api.github.com/repos/67P/kredits-contracts/stargazers",
"contributors_url": "https://api.github.com/repos/67P/kredits-contracts/contributors",
"subscribers_url": "https://api.github.com/repos/67P/kredits-contracts/subscribers",
"subscription_url": "https://api.github.com/repos/67P/kredits-contracts/subscription",
"commits_url": "https://api.github.com/repos/67P/kredits-contracts/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/67P/kredits-contracts/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/67P/kredits-contracts/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/67P/kredits-contracts/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/67P/kredits-contracts/contents/{+path}",
"compare_url": "https://api.github.com/repos/67P/kredits-contracts/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/67P/kredits-contracts/merges",
"archive_url": "https://api.github.com/repos/67P/kredits-contracts/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/67P/kredits-contracts/downloads",
"issues_url": "https://api.github.com/repos/67P/kredits-contracts/issues{/number}",
"pulls_url": "https://api.github.com/repos/67P/kredits-contracts/pulls{/number}",
"milestones_url": "https://api.github.com/repos/67P/kredits-contracts/milestones{/number}",
"notifications_url": "https://api.github.com/repos/67P/kredits-contracts/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/67P/kredits-contracts/labels{/name}",
"releases_url": "https://api.github.com/repos/67P/kredits-contracts/releases{/id}",
"deployments_url": "https://api.github.com/repos/67P/kredits-contracts/deployments",
"created_at": "2018-03-11T22:11:45Z",
"updated_at": "2020-05-07T08:08:30Z",
"pushed_at": "2020-05-27T14:22:41Z",
"git_url": "git://github.com/67P/kredits-contracts.git",
"ssh_url": "git@github.com:67P/kredits-contracts.git",
"clone_url": "https://github.com/67P/kredits-contracts.git",
"svn_url": "https://github.com/67P/kredits-contracts",
"homepage": "https://wiki.kosmos.org/Kredits",
"size": 2289,
"stargazers_count": 3,
"watchers_count": 3,
"language": "JavaScript",
"has_issues": true,
"has_projects": false,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"forks_count": 3,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 35,
"license": null,
"forks": 3,
"open_issues": 35,
"watchers": 3,
"default_branch": "master"
}
},
"_links": {
"self": {
"href": "https://api.github.com/repos/67P/kredits-contracts/pulls/196"
},
"html": {
"href": "https://github.com/67P/kredits-contracts/pull/196"
},
"issue": {
"href": "https://api.github.com/repos/67P/kredits-contracts/issues/196"
},
"comments": {
"href": "https://api.github.com/repos/67P/kredits-contracts/issues/196/comments"
},
"review_comments": {
"href": "https://api.github.com/repos/67P/kredits-contracts/pulls/196/comments"
},
"review_comment": {
"href": "https://api.github.com/repos/67P/kredits-contracts/pulls/comments{/number}"
},
"commits": {
"href": "https://api.github.com/repos/67P/kredits-contracts/pulls/196/commits"
},
"statuses": {
"href": "https://api.github.com/repos/67P/kredits-contracts/statuses/606350eb5e173a38a8c5f1b3faf30aa03224065c"
}
},
"author_association": "CONTRIBUTOR",
"merged": true,
"mergeable": null,
"rebaseable": null,
"mergeable_state": "unknown",
"merged_by": {
"login": "bumi",
"id": 318,
"node_id": "MDQ6VXNlcjMxOA==",
"avatar_url": "https://avatars1.githubusercontent.com/u/318?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bumi",
"html_url": "https://github.com/bumi",
"followers_url": "https://api.github.com/users/bumi/followers",
"following_url": "https://api.github.com/users/bumi/following{/other_user}",
"gists_url": "https://api.github.com/users/bumi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bumi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bumi/subscriptions",
"organizations_url": "https://api.github.com/users/bumi/orgs",
"repos_url": "https://api.github.com/users/bumi/repos",
"events_url": "https://api.github.com/users/bumi/events{/privacy}",
"received_events_url": "https://api.github.com/users/bumi/received_events",
"type": "User",
"site_admin": false
},
"comments": 3,
"review_comments": 0,
"maintainer_can_modify": false,
"commits": 4,
"additions": 16649,
"deletions": 4256,
"changed_files": 10
},
"url": "https://github.com/67P/kredits-contracts/pull/196",
"ipfsData": "{\n \"@context\": \"https://schema.kosmos.org\",\n \"@type\": \"Contribution\",\n \"contributor\": {\n \"ipfs\": \"QmYgiRd1FZ7JjDGBwkmLQNF6XQuyF8AWoFDRvUWhhmxiEj\"\n },\n \"date\": \"2020-05-27\",\n \"time\": \"14:22:41Z\",\n \"kind\": \"dev\",\n \"description\": \"67P/kredits-contracts: Chore/dependency updates\",\n \"details\": {\n \"url\": \"https://api.github.com/repos/67P/kredits-contracts/pulls/196\",\n \"id\": 423708597,\n \"node_id\": \"MDExOlB1bGxSZXF1ZXN0NDIzNzA4NTk3\",\n \"html_url\": \"https://github.com/67P/kredits-contracts/pull/196\",\n \"diff_url\": \"https://github.com/67P/kredits-contracts/pull/196.diff\",\n \"patch_url\": \"https://github.com/67P/kredits-contracts/pull/196.patch\",\n \"issue_url\": \"https://api.github.com/repos/67P/kredits-contracts/issues/196\",\n \"number\": 196,\n \"state\": \"closed\",\n \"locked\": false,\n \"title\": \"Chore/dependency updates\",\n \"user\": {\n \"login\": \"bumi\",\n \"id\": 318,\n \"node_id\": \"MDQ6VXNlcjMxOA==\",\n \"avatar_url\": \"https://avatars1.githubusercontent.com/u/318?v=4\",\n \"gravatar_id\": \"\",\n \"url\": \"https://api.github.com/users/bumi\",\n \"html_url\": \"https://github.com/bumi\",\n \"followers_url\": \"https://api.github.com/users/bumi/followers\",\n \"following_url\": \"https://api.github.com/users/bumi/following{/other_user}\",\n \"gists_url\": \"https://api.github.com/users/bumi/gists{/gist_id}\",\n \"starred_url\": \"https://api.github.com/users/bumi/starred{/owner}{/repo}\",\n \"subscriptions_url\": \"https://api.github.com/users/bumi/subscriptions\",\n \"organizations_url\": \"https://api.github.com/users/bumi/orgs\",\n \"repos_url\": \"https://api.github.com/users/bumi/repos\",\n \"events_url\": \"https://api.github.com/users/bumi/events{/privacy}\",\n \"received_events_url\": \"https://api.github.com/users/bumi/received_events\",\n \"type\": \"User\",\n \"site_admin\": false\n },\n \"body\": \"Updated the npm dependencies to the latest versions\\r\\n\\r\\nmissing: \\r\\n- [ ] ipfs-http-client - which has some breaking changes. I think it is not a problem for us but needs to be tested\\r\\n- [ ] solhint - wich also has a breaking change and now needs pretier for codestyle linting. I did not want that additional dependency now. Also we probably needs to improve the linting of the solidity files\\r\\n\",\n \"created_at\": \"2020-05-27T08:57:43Z\",\n \"updated_at\": \"2020-05-27T14:22:41Z\",\n \"closed_at\": \"2020-05-27T14:22:41Z\",\n \"merged_at\": \"2020-05-27T14:22:41Z\",\n \"merge_commit_sha\": \"2b99593699999756f0f49549873f2cfb679d3f4c\",\n \"assignee\": null,\n \"assignees\": [],\n \"requested_reviewers\": [],\n \"requested_teams\": [],\n \"labels\": [\n {\n \"id\": 923540870,\n \"node_id\": \"MDU6TGFiZWw5MjM1NDA4NzA=\",\n \"url\": \"https://api.github.com/repos/67P/kredits-contracts/labels/kredits-1\",\n \"name\": \"kredits-1\",\n \"color\": \"008080\",\n \"default\": false,\n \"description\": \"\"\n }\n ],\n \"milestone\": null,\n \"draft\": false,\n \"commits_url\": \"https://api.github.com/repos/67P/kredits-contracts/pulls/196/commits\",\n \"review_comments_url\": \"https://api.github.com/repos/67P/kredits-contracts/pulls/196/comments\",\n \"review_comment_url\": \"https://api.github.com/repos/67P/kredits-contracts/pulls/comments{/number}\",\n \"comments_url\": \"https://api.github.com/repos/67P/kredits-contracts/issues/196/comments\",\n \"statuses_url\": \"https://api.github.com/repos/67P/kredits-contracts/statuses/606350eb5e173a38a8c5f1b3faf30aa03224065c\",\n \"head\": {\n \"label\": \"67P:chore/dependency-updates\",\n \"ref\": \"chore/dependency-updates\",\n \"sha\": \"606350eb5e173a38a8c5f1b3faf30aa03224065c\",\n \"user\": {\n \"login\": \"67P\",\n \"id\": 9769503,\n \"node_id\": \"MDEyOk9yZ2FuaXphdGlvbjk3Njk1MDM=\",\n \"avatar_url\": \"https://avatars1.githubusercontent.com/u/9769503?v=4\",\n \"gravatar_id\": \"\",\n \"url\": \"https://api.github.com/users/67P\",\n \"html_url\": \"https://github.com/67P\",\n \"followers_url\": \"https://api.github.com/users/67P/followers\",\n \"following_url\": \"https://api.github.com/users/67P/following{/other_user}\",\n \"gists_url\": \"https://api.github.com/users/67P/gists{/gist_id}\",\n \"starred_url\": \"https://api.github.com/users/67P/starred{/owner}{/repo}\",\n \"subscriptions_url\": \"https://api.github.com/users/67P/subscriptions\",\n \"organizations_url\": \"https://api.github.com/users/67P/orgs\",\n \"repos_url\": \"https://api.github.com/users/67P/repos\",\n \"events_url\": \"https://api.github.com/users/67P/events{/privacy}\",\n \"received_events_url\":Line truncated
}
+13 -11
View File
@@ -1,23 +1,25 @@
import Model from 'kredits-web/models/contribution';
import contributors from '../../tests/fixtures/contributors';
import processContributionData from 'kredits-web/utils/process-contribution-data';
const items = [];
const data = [
{ id: 1, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'dev' },
{ id: 2, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'ops' },
{ id: 3, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'ops' },
{ id: 4, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'docs' },
{ id: 5, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'design' },
{ id: 6, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: true, amount: 500, kind: 'dev' },
{ id: 7, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 5000, kind: 'dev' },
{ id: 8, contributorId: 1, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 1500, kind: 'community' },
{ id: 9, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: true, amount: 1500, kind: 'docs' },
{ id: 1, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'dev' },
{ id: 2, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'ops' },
{ id: 3, contributorId: 2, confirmedAt: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'ops' },
{ id: 4, contributorId: 2, confirmedAt: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'docs' },
{ id: 5, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'design' },
{ id: 6, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: true, amount: 500, kind: 'dev' },
{ id: 7, contributorId: 3, confirmedAt: 2000, claimed: false, vetoed: false, amount: 5000, kind: 'dev' },
{ id: 8, contributorId: 1, confirmedAt: 2000, claimed: false, vetoed: false, amount: 1500, kind: 'community' },
{ id: 9, contributorId: 3, confirmedAt: 2000, claimed: false, vetoed: true, amount: 1500, kind: 'docs' },
];
data.forEach(attrs => {
attrs.contributor = contributors.findBy('id', attrs.contributorId.toString());
items.push(Model.create(attrs))
const c = Model.create(processContributionData(attrs));
c.set('contributor', contributors.findBy('id', attrs.contributorId.toString()));
items.push(c);
});
export default items;
+5 -1
View File
@@ -1,4 +1,5 @@
import Contributor from 'kredits-web/models/contributor';
import processContributorData from 'kredits-web/utils/process-contributor-data';
const contributors = [];
@@ -8,6 +9,9 @@ const data = [
{ id: '3', name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
];
data.forEach(attrs => contributors.push(Contributor.create(attrs)));
data.forEach(attrs => {
const c = Contributor.create(processContributorData(attrs));
contributors.push(c);
});
export default contributors;
@@ -0,0 +1,28 @@
import { module, test } from 'qunit';
import processContributionData from 'kredits-web/utils/process-contribution-data';
import testData from '../../fixtures/contribution-data';
module('Unit | Utility | process-contribution-data', function() {
let result = processContributionData(testData);
test('formats the data correctly', function(assert) {
assert.ok(typeof result.confirmedAt === 'number');
});
test('copies other properties', function(assert) {
[
'id', 'contributorId', 'amount', 'vetoed',
'ipfsHash', 'kind', 'description', 'details',
'url', 'date', 'time', 'pendingTx'
].forEach(p => {
assert.ok(Object.prototype.hasOwnProperty.call(result, p), `copies property ${p}`);
})
});
test('does not copy unnecessary properties', function(assert) {
['exists', '5'].forEach(p => {
assert.notOk(Object.prototype.hasOwnProperty.call(result, p));
})
});
});
@@ -8,10 +8,10 @@ module('Unit | Utility | process-contributor-data', function() {
test('formats the data correctly', function(assert) {
// TODO use integers everywhere for IDs
assert.ok(typeof result.id == 'string');
assert.ok(typeof result.balance == 'number');
assert.ok(typeof result.totalKreditsEarned == 'number');
assert.ok(typeof result.contributionsCount == 'number');
assert.ok(typeof result.id === 'string');
assert.ok(typeof result.balance === 'number');
assert.ok(typeof result.totalKreditsEarned === 'number');
assert.ok(typeof result.contributionsCount === 'number');
});
test('copies other properties', function(assert) {