Refactor contributor
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
<li><a href="https://ipfs.io/ipfs/{{contributor.profileHash}}">Inspect IPFS profile</a></li>
|
||||
{{/if}}
|
||||
</ul>
|
||||
{{#if contributor.showMetadata}}
|
||||
<pre>{{contributor.ipfsData}}</pre>
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import Contributor from 'kredits-web/models/contributor';
|
||||
import Proposal from 'kredits-web/models/proposal';
|
||||
|
||||
export default {
|
||||
name: 'register-models',
|
||||
initialize: function(app) {
|
||||
app.register('model:contributor', Contributor, { singleton: false });
|
||||
app.register('model:proposal', Proposal, { singleton: false });
|
||||
}
|
||||
};
|
||||
+23
-19
@@ -1,11 +1,15 @@
|
||||
import Ember from 'ember';
|
||||
import computed from 'ember-computed';
|
||||
import injectService from 'ember-service/inject';
|
||||
|
||||
const {
|
||||
isPresent,
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Object.extend({
|
||||
ipfs: injectService(),
|
||||
|
||||
id: null,
|
||||
address: null,
|
||||
name: null,
|
||||
kind: null,
|
||||
@@ -18,10 +22,12 @@ export default Ember.Object.extend({
|
||||
isCore: false,
|
||||
isCurrentUser: false,
|
||||
|
||||
avatarURL: function() {
|
||||
return `https\:\/\/avatars2.githubusercontent.com/u/${this.get('github_uid')}?v=3&s=128`;
|
||||
}.property('github_uid'),
|
||||
|
||||
avatarURL: computed('github_uid', function() {
|
||||
let github_uid = this.get('github_uid');
|
||||
if (github_uid) {
|
||||
return `https://avatars2.githubusercontent.com/u/${github_uid}?v=3&s=128`;
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Loads the contributor's profile data from IPFS and sets local instance
|
||||
@@ -30,16 +36,19 @@ export default Ember.Object.extend({
|
||||
* @method
|
||||
* @public
|
||||
*/
|
||||
loadProfile(ipfs) {
|
||||
return new Ember.RSVP.Promise((resolve, reject) => {
|
||||
if (!this.get('profileHash')) {
|
||||
resolve(this);
|
||||
return;
|
||||
}
|
||||
loadProfile() {
|
||||
let profileHash = this.get('profileHash');
|
||||
if (!profileHash) {
|
||||
return;
|
||||
}
|
||||
|
||||
ipfs.getFile(this.get('profileHash')).then(content => {
|
||||
let profileJSON = JSON.parse(content);
|
||||
let profile = Ember.Object.create(profileJSON);
|
||||
return this.get('ipfs')
|
||||
.getFile(profileHash)
|
||||
.then((content) => {
|
||||
let profile = Ember.Object.create(JSON.parse(content));
|
||||
this.set('ipfsData', JSON.stringify(profile, null, 2));
|
||||
|
||||
Ember.Logger.debug('[contributor] loaded contributor profile', profile);
|
||||
|
||||
this.setProperties({
|
||||
name: profile.get('name'),
|
||||
@@ -61,14 +70,9 @@ export default Ember.Object.extend({
|
||||
wiki_username: wiki.username
|
||||
});
|
||||
}
|
||||
|
||||
Ember.Logger.debug('[contributor] loaded contributor profile', profile);
|
||||
resolve(this);
|
||||
}).catch((err) => {
|
||||
Ember.Logger.error('[contributor] error trying to load contributor profile', this.get('profileHash'), err);
|
||||
reject(err);
|
||||
Ember.Logger.error('[contributor] error trying to load contributor profile', profileHash, err);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+4
-2
@@ -1,5 +1,4 @@
|
||||
import Ember from 'ember';
|
||||
import Contributor from 'kredits-web/models/contributor';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
|
||||
@@ -20,6 +19,9 @@ export default Ember.Route.extend({
|
||||
},
|
||||
|
||||
model() {
|
||||
let newContributor = Ember.getOwner(this).lookup('model:contributor');
|
||||
newContributor.set('kind', 'person');
|
||||
|
||||
let kredits = this.get('kredits');
|
||||
let totalSupply = kredits.get('tokenContract')
|
||||
.then((contract) => contract.invoke('totalSupply'));
|
||||
@@ -28,7 +30,7 @@ export default Ember.Route.extend({
|
||||
contributors: kredits.getContributors(),
|
||||
proposals: kredits.getProposals(),
|
||||
totalSupply,
|
||||
newContributor: Contributor.create({ kind: 'person' })
|
||||
newContributor: newContributor,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+15
-14
@@ -9,13 +9,13 @@ import injectService from 'ember-service/inject';
|
||||
import computed from 'ember-computed';
|
||||
|
||||
import config from 'kredits-web/config/environment';
|
||||
import Contributor from 'kredits-web/models/contributor';
|
||||
import Proposal from 'kredits-web/models/proposal';
|
||||
|
||||
import abis from 'contracts/abis';
|
||||
import addresses from 'contracts/addresses';
|
||||
|
||||
const {
|
||||
getOwner,
|
||||
Logger: {
|
||||
debug,
|
||||
warn
|
||||
@@ -52,7 +52,7 @@ export default Service.extend({
|
||||
|
||||
if (typeof window.web3 !== 'undefined') {
|
||||
debug('[kredits] Using user-provided instance, e.g. from Mist browser or Metamask');
|
||||
web3Instance = window.web3;
|
||||
web3Instance = new Web3(window.web3.currentProvider);
|
||||
this.set('web3Provided', true);
|
||||
} else {
|
||||
debug('[kredits] Creating new instance from npm module class');
|
||||
@@ -110,33 +110,34 @@ export default Service.extend({
|
||||
getContributorData(id) {
|
||||
return this.get('contributorsContract')
|
||||
.then((contract) => contract.invoke('contributors', id))
|
||||
.then(contributorData => {
|
||||
debug('[kredits] contributor', contributorData);
|
||||
|
||||
let [ address, digest, hashFunction, size, isCore ] = contributorData;
|
||||
.then((data) => {
|
||||
debug('[kredits] contributor', data);
|
||||
|
||||
let [ address, digest, hashFunction, size, isCore ] = data;
|
||||
let isCurrentUser = this.get('currentUserAccounts').includes(address);
|
||||
let profileHash = this.getMultihashFromBytes32({
|
||||
digest,
|
||||
hashFunction: hashFunction.toNumber(),
|
||||
size: size.toNumber()
|
||||
});
|
||||
|
||||
let isCurrentUser = this.get('currentUserAccounts').includes(address);
|
||||
|
||||
return this.get('tokenContract')
|
||||
.then((contract) => contract.invoke('balanceOf', address))
|
||||
.then(balance => {
|
||||
let contributor = Contributor.create({
|
||||
.then((balance) => {
|
||||
balance = balance.toNumber();
|
||||
|
||||
let contributor = getOwner(this).lookup('model:contributor');
|
||||
contributor.setProperties({
|
||||
id,
|
||||
address,
|
||||
profileHash,
|
||||
isCore,
|
||||
isCurrentUser,
|
||||
kredits: balance.toNumber()
|
||||
balance
|
||||
});
|
||||
|
||||
// TODO: move ipfs into model
|
||||
return contributor.loadProfile(this.get('ipfs'));
|
||||
// Load data from IPFS
|
||||
contributor.loadProfile();
|
||||
return contributor;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -77,6 +77,11 @@ table.contributor-list {
|
||||
padding-left: 0.2rem;
|
||||
}
|
||||
}
|
||||
|
||||
pre {
|
||||
line-height: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+1185
-664
File diff suppressed because it is too large
Load Diff
+6
-4
@@ -30,7 +30,10 @@
|
||||
"broccoli-file-creator": "^1.1.1",
|
||||
"broccoli-json-module": "^1.0.0",
|
||||
"broccoli-merge-trees": "^3.0.0",
|
||||
"bs58": "^4.0.1",
|
||||
"buffer": "^5.1.0",
|
||||
"ember-ajax": "^2.4.1",
|
||||
"ember-awesome-macros": "0.41.0",
|
||||
"ember-browserify": "^1.1.13",
|
||||
"ember-cli": "2.10.0",
|
||||
"ember-cli-app-version": "^2.0.0",
|
||||
@@ -42,22 +45,21 @@
|
||||
"ember-cli-jshint": "^2.0.1",
|
||||
"ember-cli-qunit": "^3.0.1",
|
||||
"ember-cli-release": "^0.2.9",
|
||||
"ember-cli-sass": "^7.0.0",
|
||||
"ember-cli-sass": "^7.2.0",
|
||||
"ember-cli-sri": "^2.1.0",
|
||||
"ember-cli-test-loader": "^1.1.0",
|
||||
"ember-cli-uglify": "^1.2.0",
|
||||
"ember-export-application-global": "^1.0.5",
|
||||
"ember-load-initializers": "^0.5.1",
|
||||
"ember-macro-helpers": "0.17.0",
|
||||
"ember-parachute": "0.1.0",
|
||||
"ember-resolver": "^2.0.3",
|
||||
"ember-truth-helpers": "1.3.0",
|
||||
"ipfs-api": "^19.0.0",
|
||||
"kosmos-schemas": "^1.1.2",
|
||||
"kredits-contracts": "github:67P/truffle-kredits#master",
|
||||
"kredits-contracts": "*",
|
||||
"loader.js": "^4.0.10",
|
||||
"tv4": "^1.3.0",
|
||||
"bs58": "^4.0.1",
|
||||
"buffer": "^5.1.0",
|
||||
"web3": "^0.18.2"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
Reference in New Issue
Block a user