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