Skip to content

Commit

Permalink
Merge pull request #493 from DemocracyEarth/charts
Browse files Browse the repository at this point in the history
Displays charts with economic data of a DAO.
  • Loading branch information
santisiri authored Jan 16, 2020
2 parents 5073c33 + d27dd61 commit 26ac608
Show file tree
Hide file tree
Showing 23 changed files with 540 additions and 197 deletions.
6 changes: 4 additions & 2 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,11 @@
"not-connected-message": "The application is not connected to a server.",
"dao-confirm-tally": "You are voting for <strong>{{voteValue}}</strong> on:<br><em>{{proposalName}}</em><br><br>Confirm vote in your blockchain wallet.<br>",
"dao-default-tally": "You are voting on<br><em>{{proposalName}}</em><br><br>Confirm vote in your blockchain wallet.<br>",
"moloch-guild": "Guild.",
"moloch-guild": "Budget.",
"guild-total-shares": "Total Shares",
"guild-total-assets": "Total Assets",
"guild-share-value": "Value per Share",
"guild-total-value": "Total Value"
"guild-total-value": "Total Value",
"guild-voting-address": "Voter",
"guild-voting-addresses": "Voters"
}
53 changes: 53 additions & 0 deletions imports/api/collectives/Collectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,51 @@ Schema.Menu = new SimpleSchema({
},
});

Schema.Dataset = new SimpleSchema({
data: {
type: Array,
optional: true,
defaultValue: [],
},
'data.$': {
type: Object,
optional: true,
},
'data.$.t': {
type: Date,
optional: true,
},
'data.$.x': {
type: Number,
optional: true,
decimal: true,
},
'data.$.y': {
type: Number,
optional: true,
decimal: true,
},
});

Schema.Chart = new SimpleSchema({
guildLabel: {
type: String,
optional: true,
},
type: {
type: String,
optional: true,
},
dataset: {
type: [Schema.Dataset],
optional: true,
},
lastSyncedBlock: {
type: Number,
optional: true,
},
});

Schema.CollectiveProfile = new SimpleSchema({
website: {
type: String,
Expand All @@ -111,6 +156,10 @@ Schema.CollectiveProfile = new SimpleSchema({
type: [Parameter],
optional: true,
},
chart: {
type: [Schema.Chart],
optional: true,
},
blockchain: {
type: Blockchain,
optional: true,
Expand Down Expand Up @@ -161,6 +210,10 @@ Schema.CollectiveProfile = new SimpleSchema({
type: Date,
optional: true,
},
lastSyncedBlock: {
type: Number,
optional: true,
},
});


Expand Down
4 changes: 2 additions & 2 deletions imports/api/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getTime } from '/imports/api/time';
import { logUser, log, defaults, gui } from '/lib/const';
import { stripHTML, urlDoctor, fixDBUrl } from '/lib/utils';
import { notifierHTML } from '/imports/api/notifier/notifierTemplate.js';
import { computeDAOStats } from '/lib/dao';
import { refreshDAOs } from '/lib/dao';
import { getLastTimestamp, getBlockHeight } from '/lib/web3';
import { Collectives } from '/imports/api/collectives/Collectives';

Expand Down Expand Up @@ -388,7 +388,7 @@ Meteor.methods({
Contracts.update({ _id: feed[i]._id }, { $set: { period: newPeriod } });
}
}
computeDAOStats();
refreshDAOs();
},

async getBlock(collectives) {
Expand Down
38 changes: 1 addition & 37 deletions imports/startup/both/modules/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,47 +382,11 @@ const _hasRightToVote = async (memberAddress, proposalIndex, collectiveId) => {
*/
const _submitVote = async (proposalIndex, uintVote, contract, choice) => {
const res = await _callDAOMethod('submitVote', [proposalIndex, uintVote], choice.collectiveId, 'send', { from: Meteor.user().username });
console.log(res);
if (res) {
_pendingTransaction(Meteor.user().username, res, contract, choice);
displayModal(false, modal);
}

/**
const collective = Collectives.findOne({ _id: choice.collectiveId });
const smartContracts = collective.profile.blockchain.smartContracts;
const map = _getMethodMap(smartContracts, 'submitVote');
const contractABI = JSON.parse(map.abi);
const dao = await new web3.eth.Contract(contractABI, map.publicAddress);
await dao.methods[`${'submitVote'}`](proposalIndex, uintVote).send({ from: Meteor.user().username }, (err, res) => {
if (err) {
let message;
switch (err.code) {
case -32603:
message = TAPi18n.__('metamask-invalid-address');
break;
case 4001:
default:
message = TAPi18n.__('metamask-denied-signature');
}
displayModal(
true,
{
icon: Meteor.settings.public.app.logo,
title: TAPi18n.__('wallet'),
message,
cancel: TAPi18n.__('close'),
alertMode: true,
},
);
return err;
}
_pendingTransaction(Meteor.user().username, res, contract, choice);
displayModal(false, modal);
return res;
});*/
};

/**
Expand Down
15 changes: 12 additions & 3 deletions imports/ui/templates/components/collective/guild/guild.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
<div class="guild-title">
<a href="{{url}}" class="guild-title-label" target="_blank">{{name}}</a>
</div>
<div class="guild-detail">
</div>
<div class="guild-detail">
<div class="guild-meta">
<img src="{{getImage 'vote-icon-black'}}" class="clock-icon guild-verifier">
<div class="verifier verifier-live verifier-feed verifier-mini">{{{members}}}</div>
</div>
<div class="guild-meta">
<img src="{{getImage 'key'}}" class="clock-icon guild-verifier">
<a href="{{blockchainLink}}" target="_blank" class="verifier verifier-live verifier-feed verifier-mini verifier-key">{{{publicAddress}}}</a>
<a href="{{blockchainLink}}" target="_blank" class="verifier verifier-live verifier-feed verifier-mini verifier-key verifier-guild">{{{publicAddress}}}</a>
</div>
</div>
{{#with guildChart}}
{{> chart}}
{{/with}}
</div>
</div>
<div class="guild-row">
Expand Down Expand Up @@ -47,7 +56,7 @@
{{/with}}
</div>
</div>
<div class="guild-row guild-row-total">
<div class="guild-row guild-row-last">
<div class="guild-label">
{{_ 'guild-total-value'}}
</div>
Expand Down
16 changes: 11 additions & 5 deletions imports/ui/templates/components/collective/guild/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getCoin } from '/imports/api/blockchain/modules/web3Util';

import '/imports/ui/templates/components/collective/guild/guild.html';
import '/imports/ui/templates/components/decision/balance/balance.js';
import '/imports/ui/templates/widgets/chart/chart.js';


const standardBalance = {
Expand All @@ -24,7 +25,6 @@ const standardBalance = {
value: 100,
};


Template.guild.onCreated(function () {
Template.instance().collective = new ReactiveVar();
Template.instance().ready = new ReactiveVar(false);
Expand Down Expand Up @@ -85,18 +85,21 @@ Template.guild.helpers({
},
totalValue() {
const row = _getRow('guild-total-value', Template.instance());
row.tokenTotal = true;
row.tokenTotal = false;
return row;
},
getImage(pic) {
return getImage(Template.instance().imageTemplate.get(), pic);
},
members() {
const count = Template.instance().memberCount.get();
if (count === 1) {
return `${count} ${TAPi18n.__('member')}`;
if (count) {
if (count === 1) {
return `${count} ${TAPi18n.__('guild-voting-address')}`;
}
return `${count} ${TAPi18n.__('guild-voting-addresses')}`;
}
return `${count} ${TAPi18n.__('members')}`;
return '';
},
totalStyle() {
const coin = getCoin(Template.instance().collective.get().profile.blockchain.coin.code);
Expand All @@ -113,4 +116,7 @@ Template.guild.helpers({
blockchainLink() {
return `${Meteor.settings.public.web.sites.blockExplorer}/address/${Template.instance().collective.get().profile.blockchain.publicAddress}`;
},
guildChart() {
return { collectiveId: this.collectiveId, guildLabel: 'guild-total-assets' };
},
});
4 changes: 2 additions & 2 deletions imports/ui/templates/components/decision/ballot/ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ const _cryptoVote = async () => {
switch (voteValue) {
case defaults.YES:
message = TAPi18n.__('dao-confirm-tally').replace('{{voteValue}}', TAPi18n.__('yes')).replace('{{proposalName}}', getProposalDescription(poll.title, true));
submitVote(poll.importId.toNumber(), 1, poll, contract);
await submitVote(poll.importId.toNumber(), 1, poll, contract);
break;
case defaults.NO:
message = TAPi18n.__('dao-confirm-tally').replace('{{voteValue}}', TAPi18n.__('no')).replace('{{proposalName}}', getProposalDescription(poll.title, true));
submitVote(poll.importId.toNumber(), 2, poll, contract);
await submitVote(poll.importId.toNumber(), 2, poll, contract);
break;
default:
message = TAPi18n.__('dao-default-tally').replace('{{proposalName}}', getProposalDescription(poll.title, true));
Expand Down
1 change: 0 additions & 1 deletion imports/ui/templates/layout/sidebar/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<div style="height: 50px"></div>
</div>
<div class="menu menu-empty menu-footer">
{{{members}}}
{{{replicator}}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/templates/layout/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Template.sidebar.helpers({
return 0;
},
replicator() {
return `&#183; <a href="${Meteor.settings.public.web.sites.tokens}" target="_blank" ontouchstart="">${TAPi18n.__('start-a-democracy')}</a>`;
return `<a href="${Meteor.settings.public.web.sites.tokens}" target="_blank" ontouchstart="">${TAPi18n.__('start-a-democracy')}</a>`;
},
totalDelegates() {
if (Template.instance().delegates.get()) {
Expand Down
1 change: 0 additions & 1 deletion imports/ui/templates/layout/url/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ Template.homeFeed.onCreated(function () {

instance.autorun(function (computation) {
if (subscription.ready()) {
console.log(Contracts.findOne());
const collectiveId = Contracts.findOne().collectiveId;
Session.set('search', {
input: '',
Expand Down
6 changes: 6 additions & 0 deletions imports/ui/templates/widgets/chart/chart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<template name="chart">
<div class="guild-chart">
<canvas id="collectiveChart-{{collectiveId}}" class="chart"></canvas>
</div>
</template>
Loading

0 comments on commit 26ac608

Please sign in to comment.