Add Web3 library and service

This commit is contained in:
2017-02-02 17:27:50 +08:00
parent 256798ae40
commit 5f108557cc
5 changed files with 62 additions and 3 deletions
+6 -1
View File
@@ -1,11 +1,16 @@
import Ember from 'ember'; import Ember from 'ember';
const { const {
computed computed,
inject: {
service
}
} = Ember; } = Ember;
export default Ember.Controller.extend({ export default Ember.Controller.extend({
kredits: service(),
contributorsCount: computed('model.contributors.[]', function() { contributorsCount: computed('model.contributors.[]', function() {
return this.get('model.contributors').length; return this.get('model.contributors').length;
}), }),
+40
View File
@@ -0,0 +1,40 @@
import Ember from 'ember';
import Web3 from 'npm:web3';
export default Ember.Service.extend({
web3Instance: null,
web3: function() {
if (Ember.isPresent(this.get('web3Instance'))) {
return this.get('web3Instance');
}
let web3Instance;
if (typeof window.web3 !== 'undefined') {
Ember.Logger.debug('[web3] Using user-provided instance, e.g. from Mist browser or Metamask');
web3Instance = window.web3;
} else {
Ember.Logger.debug('[web3] Creating new instance from npm module class');
let provider = new Web3.providers.HttpProvider("http://localhost:8545");
web3Instance = new Web3(provider);
}
this.set('web3Instance', web3Instance);
return web3Instance;
}.property('web3Instance'),
contract: function() {
// let web3 = this.get('web3');
let contract = null;
return contract;
}.property('web3'),
totalSupply: function() {
return 23000;
}.property()
});
+1 -1
View File
@@ -8,7 +8,7 @@
{{contributor-list contributors=model.contributors}} {{contributor-list contributors=model.contributors}}
<p class="stats"> <p class="stats">
<span class="number">{{kreditsSum}}</span> kredits issued and distributed among <span class="number">{{kredits.totalSupply}}</span> kredits issued and distributed among
<span class="number">{{contributorsCount}}</span> contributors. <span class="number">{{contributorsCount}}</span> contributors.
</p> </p>
</div> </div>
+3 -1
View File
@@ -17,6 +17,7 @@
"devDependencies": { "devDependencies": {
"broccoli-asset-rev": "^2.4.5", "broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1", "ember-ajax": "^2.4.1",
"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",
"ember-cli-babel": "^5.1.7", "ember-cli-babel": "^5.1.7",
@@ -34,7 +35,8 @@
"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-resolver": "^2.0.3", "ember-resolver": "^2.0.3",
"loader.js": "^4.0.10" "loader.js": "^4.0.10",
"web3": "^0.18.2"
}, },
"engines": { "engines": {
"node": ">= 0.12.0" "node": ">= 0.12.0"
+12
View File
@@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('service:kredits', 'Unit | Service | kredits', {
// Specify the other units that are required for this test.
// needs: ['service:foo']
});
// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.subject();
assert.ok(service);
});