diff --git a/test/embark-test/app/app.js b/test/embark-test/app/app.js
index 9227695..53a1101 100644
--- a/test/embark-test/app/app.js
+++ b/test/embark-test/app/app.js
@@ -7,22 +7,22 @@ import Ranking from '../embarkArtifacts/contracts/Ranking';
import Phoenix from 'phoenix';
import withObservables from '@nozbe/with-observables'
-const {scan} = require('rxjs/operators');
+const { scan, map } = require('rxjs/operators');
import { of } from 'rxjs';
const phoenix = new Phoenix(web3);
-const RankItem = ({votes, onUpvote, onDownvote}) => (
-
- 1 - 0x00000000000000000000000000001
- Upvotes: {votes.upvotes} - Downvotes: {votes.downvotes}
- |
-
-);
+const RankItem = ({items, onUpvote, onDownvote}) => {
+ return items.map((item, i) =>
+ {i+1} - {item.addr}
+ Upvotes: {item.upvotes} - Downvotes: {item.downvotes}
+ |
+
);
+};
-const enhance = withObservables(['votes'], ({ votes }) => ({votes: votes || of({ /* default empty object */ })}));
+const enhance = withObservables(['items'], ({ items }) => ({items: items || of({ /* default empty object */ })}));
const EnhancedRankItem = enhance(RankItem)
const observables = {};
@@ -40,34 +40,43 @@ class App extends React.Component {
}
phoenix.init(() => {
- observables.votes = phoenix.trackEvent(Ranking, 'Rating', {filter: {}, fromBlock: 1}).pipe(
- scan((acc, curr) => {
- if(curr.rating >= 3){
- acc.upvotes++;
- } else {
- acc.downvotes++;
- }
- return acc;
- }, {upvotes: 0, downvotes: 0})
- );
+ observables.items = phoenix
+ .trackEvent(Ranking, 'Rating', {filter: {}, fromBlock: 1})
+ .pipe(
+ scan((acc, curr) => {
+ const votes = {...acc[curr.addr]} || {};
+ return {
+ ...acc,
+ [curr.addr]: {
+ upvotes: (votes.upvotes || 0) + (curr.rating >= 3 ? 1 : 0),
+ downvotes: (votes.downvotes || 0) + (curr.rating < 3 ? 1 : 0)
+ }
+ }
+ }, {}),
+ map(summary => {
+ return Object.keys(summary).map(k => {
+ return {addr: k, ...summary[k]}
+ })
+ })
+ );
- this.setState({ready: true});
+ this.setState({ready: true});
});
});
}
- upvote = () => {
- Ranking.methods.rate("0x0000000000000000000000000000000000000001", 5).send();
+ upvote = address => () => {
+ Ranking.methods.rate(address, 5).send();
}
- downvote = () => {
- Ranking.methods.rate("0x0000000000000000000000000000000000000001", 1).send();
+ downvote = address => () => {
+ Ranking.methods.rate(address, 1).send();
}
render() {
const {ready} = this.state;
if(!ready) return Loading...;
- return ;
+ return ;
}
}
diff --git a/test/embark-test/app/index.html b/test/embark-test/app/index.html
index 115c3bd..b198587 100644
--- a/test/embark-test/app/index.html
+++ b/test/embark-test/app/index.html
@@ -1,5 +1,10 @@
+
diff --git a/test/embark-test/config/contracts.js b/test/embark-test/config/contracts.js
index c43cb42..40763d2 100644
--- a/test/embark-test/config/contracts.js
+++ b/test/embark-test/config/contracts.js
@@ -57,7 +57,13 @@ module.exports = {
// filteredFields: [],
contracts: {
-
+ "Ranking": {
+ onDeploy: async (dependencies) => {
+ await dependencies.contracts.Ranking.methods.rate('0xcafecafecafecafecafecafecafecafecafecafe', 4).send({from: dependencies.web3.eth.defaultAccount}),
+ await dependencies.contracts.Ranking.methods.rate('0x0001020304050607080900010203040506070809', 1).send({from: dependencies.web3.eth.defaultAccount}),
+ await dependencies.contracts.Ranking.methods.rate('0x0000000100000001000000010000000100000001', 3).send({from: dependencies.web3.eth.defaultAccount})
+ }
+ }
}
},