Skip to content

Commit

Permalink
Merge pull request #470 from DemocracyEarth/async-polls
Browse files Browse the repository at this point in the history
Async polls
  • Loading branch information
santisiri authored Jul 4, 2019
2 parents efdf1aa + 83a4583 commit e42d501
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 61 deletions.
4 changes: 3 additions & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,7 @@
"already-voted": "Already Voted",
"already-voted-detail": "Your account balance has already been tallied on this decision.",
"election-rule-onchain": "On chain Tip",
"voting-editor-onchain-tooltip": "A token fraction will be sent to post author and tallied as a vote."
"voting-editor-onchain-tooltip": "A token fraction will be sent to post author and tallied as a vote.",
"election-rule-webvote": "Web Vote",
"voting-editor-webvote-tooltip": "A vote using web based tokens."
}
12 changes: 12 additions & 0 deletions imports/api/server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ Meteor.publish('singleContract', function (terms) {
return Contracts.find(parameters.find, parameters.options);
});

/**
* @summary gets the contracts that are used for a poll
* @return {Object} querying terms
*/
Meteor.publish('pollContracts', function (terms) {
check(terms, Object);
const parameters = query(terms);
log(`{ publish: 'pollContracts', user: ${logUser()}, poll: ${JSON.stringify(terms.poll)}`);
return Contracts.find(parameters.find, parameters.options);
});


/**
* @summary gets a specific delegation
* @return {Object} querying terms
Expand Down
1 change: 0 additions & 1 deletion imports/startup/both/modules/Contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ const _createPoll = (draft) => {
return newDraft;
} else if (draft.poll.length > 0) {
// change info of existing poll
console.log(`removing the poll`);
_removePoll(draft);
newDraft.poll = [];
newDraft.poll = _createPoll(newDraft).poll;
Expand Down
8 changes: 6 additions & 2 deletions imports/startup/both/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Contracts } from '/imports/api/contracts/Contracts';
import { stripHTMLfromText } from '/imports/ui/modules/utils';
import { setupWeb3 } from '/imports/startup/both/modules/metamask.js';
import { displayNotice } from '/imports/ui/modules/notice';
import { token } from '/lib/token';
import { tokenWeb } from '/lib/token';

if (Meteor.isClient) {
import '/imports/ui/templates/layout/main.js';
Expand Down Expand Up @@ -105,7 +105,11 @@ Router.configure({
HTTP.get(Meteor.absoluteUrl(Meteor.settings.public.web.template.settings), function (err, result) {
if (!err) {
HTTP.get(Meteor.absoluteUrl(result.data.lib.token), function (err, result) {
Session.set('token', result.data);
const tokens = result.data;
if (Meteor.settings.public.app.config.allowWebVotes) {
tokens.coin = tokens.coin.concat(tokenWeb.coin);
}
Session.set('token', tokens);
});
}
});
Expand Down
6 changes: 4 additions & 2 deletions imports/ui/templates/components/decision/balance/balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ Template.balance.helpers({
return style;
},
tickerStyle() {
let style = '';
Template.instance().coin = getCoin(Template.currentData().token);
const coin = Template.instance().coin;
if (coin.color) {
return `background-color: ${coin.color}; border-color: ${coin.color};`;
style = `background-color: ${coin.color}; border-color: ${coin.color};`;
}
return '';
return style;
},
hasDate() {
return this.date;
Expand Down
34 changes: 22 additions & 12 deletions imports/ui/templates/components/decision/coin/coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { Meteor } from 'meteor/meteor';
import { templetize, getImage } from '/imports/ui/templates/layout/templater';
import { animatePopup } from '/imports/ui/modules/popup';
import { searchJSON } from '/imports/ui/modules/JSON';
import { token } from '/lib/token';
import { token, tokenWeb } from '/lib/token';
import { createPoll, removePoll } from '/imports/startup/both/modules/Contract';
import { Contracts } from '/imports/api/contracts/Contracts';
import { getCoin } from '/imports/api/blockchain/modules/web3Util';

import '/imports/ui/templates/widgets/setting/setting.js';
Expand Down Expand Up @@ -86,8 +85,20 @@ const _checkInputs = () => {
return !(Session.get('noCoinFound')
|| Session.get('newCoin') === ''
|| (Session.get('draftContract').blockchain.publicAddress && !Session.get('checkBlockchainAddress'))
|| (!Meteor.user().profile.wallet.reserves && Session.get('draftContract').blockchain.coin.code !== 'WEB VOTE')
|| (_verifyBlockchainAddress() && Session.get('newCoin') && Session.get('newCoin').code !== 'WEB VOTE'));
|| (!Meteor.user().profile.wallet.reserves && Session.get('draftContract').blockchain.coin.code !== tokenWeb.coin[0].code)
|| (_verifyBlockchainAddress() && Session.get('newCoin') && Session.get('newCoin').code !== tokenWeb.coin[0].code));
};

/**
* @summary checks if needs a valid address to continue
* @return {boolean} true or false baby
*/
const _brokenAddress = () => {
const newCoin = Session.get('newCoin');
if ((newCoin && (newCoin.code === tokenWeb.coin[0].code)) || (!newCoin && (Session.get('draftContract').blockchain.coin.code === tokenWeb.coin[0].code))) {
return false;
}
return Session.get('isAddressWrong');
};

Template.coin.onCreated(() => {
Expand Down Expand Up @@ -138,7 +149,7 @@ Template.coin.helpers({
},
address() {
const draft = Session.get('draftContract');
if (draft.blockchain && draft.blockchain.publicAddress && Session.get('newCoin') && Session.get('newCoin').code !== 'WEB VOTE') {
if (draft.blockchain && draft.blockchain.publicAddress && Session.get('newCoin') && Session.get('newCoin').code !== tokenWeb.coin[0].code) {
Session.set('checkBlockchainAddress', web3.utils.isAddress(draft.blockchain.publicAddress));
return draft.blockchain.publicAddress;
}
Expand Down Expand Up @@ -184,7 +195,6 @@ Template.coin.helpers({
allowBalance() {
if (Session.get('newCoin')) {
const coin = getCoin(Session.get('newCoin').code);
console.log(coin);
return coin.editor.allowBalanceToggle;
}
return false;
Expand All @@ -197,7 +207,7 @@ Template.coin.helpers({
return false;
},
wrongAddress() {
if (Session.get('isAddressWrong')) { return true; }
if (_brokenAddress()) { return true; }
if (Session.get('newCoin')) {
const coin = getCoin(Session.get('newCoin').code);
if (coin.type === 'ERC20' || coin.type === 'NATIVE') {
Expand All @@ -210,18 +220,18 @@ Template.coin.helpers({
return _verifyBlockchainAddress();
}
}
return Session.get('isAddressWrong');
return _brokenAddress();
},
addressStyle() {
if (Session.get('newCoin') && Session.get('newCoin').code === 'WEB VOTE') {
if (Session.get('newCoin') && Session.get('newCoin').code === tokenWeb.coin[0].code) {
return 'display: none;';
}
return '';
},
buttonDisable() {
if (Session.get('isAddressWrong')) { return 'button-disabled'; }
if (_brokenAddress()) { return 'button-disabled'; }
if (Session.get('newCoin')) {
if (!_checkInputs() || (document.getElementById('editBlockchainAddress') && document.getElementById('editBlockchainAddress').value === '')) {
if (!_checkInputs() || (document.getElementById('editBlockchainAddress') && document.getElementById('editBlockchainAddress').value === '' && Session.get('newCoin').code !== tokenWeb.coin[0].code)) {
return 'button-disabled';
}
}
Expand Down Expand Up @@ -252,7 +262,7 @@ Template.coin.events({
Template.instance().showAdvanced.set(!advanced);
},
'click #execute-coin'() {
if (_checkInputs() || !Session.get('isAddressWrong')) {
if (_checkInputs() || !_brokenAddress()) {
_save();
animatePopup(false, 'blockchain-popup');
Session.set('showCoinSettings', false);
Expand Down
15 changes: 11 additions & 4 deletions imports/ui/templates/components/decision/editor/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@
</div>
{{/if}}
{{else}}
<div class="election-rule">
{{{_ 'election-rule-onchain'}}}
{{> help tooltip='voting-editor-onchain-tooltip'}}
</div>
{{#if webVote}}
<div class="election-rule">
{{{_ 'election-rule-webvote'}}}
{{> help tooltip='voting-editor-webvote-tooltip'}}
</div>
{{else}}
<div class="election-rule">
{{{_ 'election-rule-onchain'}}}
{{> help tooltip='voting-editor-onchain-tooltip'}}
</div>
{{/if}}
{{/unless}}
{{#if pollingEnabled}}
{{#with pollSettings}}
Expand Down
9 changes: 6 additions & 3 deletions imports/ui/templates/components/decision/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { timers } from '/lib/const';
import { Contracts } from '/imports/api/contracts/Contracts';
import { createContract } from '/imports/startup/both/modules/Contract';
import { timeCompressed } from '/imports/ui/modules/chronos';
import { tokenWeb } from '/lib/token';

import '/imports/ui/templates/components/decision/editor/editor.html';
import '/imports/ui/templates/components/decision/editor/editorButton.js';
Expand Down Expand Up @@ -173,6 +174,7 @@ Template.editor.onCreated(function () {
Template.instance().ready = new ReactiveVar(true);
Template.instance().contract = new ReactiveVar(contract);
Template.instance().reply = new ReactiveVar();
Template.instance().pollingEnabled = new ReactiveVar(false);

Template.instance().imageTemplate = new ReactiveVar();
templetize(Template.instance());
Expand Down Expand Up @@ -263,6 +265,7 @@ Template.editor.helpers({
return false;
},
pollingEnabled() {
// return Template.instance().pollingEnabled.get();
return Session.get('draftContract') ? Session.get('draftContract').rules.pollVoting : false;
},
pollList() {
Expand All @@ -279,9 +282,6 @@ Template.editor.helpers({
const pollId = draft ? draft._id : false;
const list = draft ? draft.poll : false;

console.log('this has new poll settings');
console.log(JSON.stringify(draft.poll));

return {
list,
pollId,
Expand Down Expand Up @@ -327,6 +327,9 @@ Template.editor.helpers({
getImage(pic) {
return getImage(Template.instance().imageTemplate.get(), pic);
},
webVote() {
return Session.get('draftContract').blockchain.coin.code === tokenWeb.coin[0].code;
},
menu() {
return [
{
Expand Down
30 changes: 27 additions & 3 deletions imports/ui/templates/components/decision/poll/poll.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
<template name="poll">
{{#if ready}}
{{#if placeholder}}
<div class="section section-poll w-clearfix">
<div class="poll">
{{#each item}}
{{> ballot poll=true contract=this.contract pollTotals=this.totals editorMode=this.editor}}
{{#each listItem}}
<div id="single-vote" class="poll-choice">
<div id="pollPlaceholder" class="button half choice">
<div class="checkbox-mini">
</div>
<div class="poll-score poll-score-button">
<div class="poll-score-bar">
<div class="poll-score-bar-fill" style="width: {{pollScore}}">
</div>
</div>
<div class="poll-score-percentage {{smallPercentageStyle}}">
{{pollScore}}
</div>
</div>
</div>
</div>
{{/each}}
</div>
</div>
{{else}}
{{#if ready}}
<div class="section section-poll w-clearfix">
<div class="poll">
{{#each item}}
{{> ballot poll=true contract=this.contract pollTotals=this.totals editorMode=this.editor}}
{{/each}}
</div>
</div>
{{/if}}
{{/if}}
</template>
24 changes: 19 additions & 5 deletions imports/ui/templates/components/decision/poll/poll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { Session } from 'meteor/session';

import { Contracts } from '/imports/api/contracts/Contracts';
import { query } from '/lib/views';
Expand Down Expand Up @@ -50,13 +51,23 @@ Template.poll.onRendered(function () {

instance.contracts.set(feed);
},
removed: (id) => {
removed: () => {
const feed = instance.contracts.get();

for (let i = 0; i < feed.length; i += 1) {
if (feed[i]._id === id) {
feed.splice(i, 1);
break;
if (instance.data.editorMode) {
const draft = Session.get('draftContract');
for (let i = 0; i < feed.length; i += 1) {
let isDraftPoll = false;
for (let k = 0; k < draft.poll.length; k += 1) {
if (feed[i]._id === draft.poll[k].contractId) {
isDraftPoll = true;
break;
}
}
if (!isDraftPoll) {
feed.splice(i, 1);
break;
}
}
}

Expand Down Expand Up @@ -84,6 +95,9 @@ Template.poll.helpers({
}
return item;
},
listItem() {
return this.list;
},
quadratic() {
return this.quadratic;
},
Expand Down
47 changes: 40 additions & 7 deletions imports/ui/templates/layout/url/landing/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,46 @@ <h1 class='landing-sub landing-sub-big'>{{{_ 'our-clients'}}}</h1>
<div class="landing-company-list">
{{{_ 'landing-companies'}}}
</div>
<div class="landing-client landing-client-start">
<blockquote class="twitter-tweet" data-lang="en">
<p lang="en" dir="ltr">New episode live w/ <a
href="https://twitter.com/santisiri?ref_src=twsrc%5Etfw">@santisiri</a>!<br><br>We discuss what democracy is, how
tech can improve governance, why he started a political party, how he implemented quadratic voting in a US state
&amp; where blockchain tech creates impact in the short term.<br><br>Listen &amp; learn!<a
href="https://t.co/5qItSWZsXo">https://t.co/5qItSWZsXo</a></p>&mdash; Pomp 🌪 (@APompliano) <a
href="https://twitter.com/APompliano/status/1130491357997469696?ref_src=twsrc%5Etfw">May 20, 2019</a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
<div class="landing-client">
<blockquote class="twitter-tweet" data-lang="en">
<p lang="en" dir="ltr">On Unchained, <a href="https://twitter.com/glenweyl?ref_src=twsrc%5Etfw">@glenweyl</a> and <a
href="https://twitter.com/santisiri?ref_src=twsrc%5Etfw">@santisiri</a> discuss blockchain-based borderless
democracies, quadratic finance and quadratic voting, and what infrastructure needs to be in place for
blockchain-based voting systems to work (hint: identity!) <a
href="https://t.co/GSWGGK8PHT">https://t.co/GSWGGK8PHT</a></p>&mdash; Laura Shin (@laurashin) <a
href="https://twitter.com/laurashin/status/1100380012002332673?ref_src=twsrc%5Etfw">February 26, 2019</a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
<div class="landing-client">
<blockquote class="twitter-tweet" data-lang="en">
<p lang="en" dir="ltr">Quadratic voting is a new tool of democracy that makes zealotry expensive. It worked in an
experiment in Colorado this year. <a href="https://twitter.com/glenweyl?ref_src=twsrc%5Etfw">@glenweyl</a> <a
href="https://twitter.com/santisiri?ref_src=twsrc%5Etfw">@santisiri</a> <a
href="https://t.co/cJWUnNFXHq">https://t.co/cJWUnNFXHq</a> via <a
href="https://twitter.com/BW?ref_src=twsrc%5Etfw">@BW</a></p>&mdash; Peter Coy (@petercoy) <a
href="https://twitter.com/petercoy/status/1123588333135900672?ref_src=twsrc%5Etfw">May 1, 2019</a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
<div class="landing-client landing-client-start">
<blockquote class="twitter-tweet" data-lang="en">
<p lang="en" dir="ltr">Experimentation with governance: read about our alpha run with <a
href="https://twitter.com/blockstack?ref_src=twsrc%5Etfw">@Blockstack</a> App Mining, a first look at what is to
come. <a href="https://t.co/IULb5fghEi">https://t.co/IULb5fghEi</a></p>&mdash; Democracy Earth 🌎🌿
(@DemocracyEarth) <a href="https://twitter.com/DemocracyEarth/status/1052990662138716161?ref_src=twsrc%5Etfw">October
(@DemocracyEarth) <a
href="https://twitter.com/DemocracyEarth/status/1052990662138716161?ref_src=twsrc%5Etfw">October
18, 2018</a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
Expand All @@ -228,12 +262,11 @@ <h1 class='landing-sub landing-sub-big'>{{{_ 'our-clients'}}}</h1>
</div>
<div class="landing-client">
<blockquote class="twitter-tweet" data-lang="en">
<p lang="en" dir="ltr">On Unchained, <a href="https://twitter.com/glenweyl?ref_src=twsrc%5Etfw">@glenweyl</a> and <a
href="https://twitter.com/santisiri?ref_src=twsrc%5Etfw">@santisiri</a> discuss blockchain-based borderless
democracies, quadratic finance and quadratic voting, and what infrastructure needs to be in place for
blockchain-based voting systems to work (hint: identity!) <a
href="https://t.co/GSWGGK8PHT">https://t.co/GSWGGK8PHT</a></p>&mdash; Laura Shin (@laurashin) <a
href="https://twitter.com/laurashin/status/1100380012002332673?ref_src=twsrc%5Etfw">February 26, 2019</a>
<p lang="en" dir="ltr">New ep of <a href="https://twitter.com/TFTC21?ref_src=twsrc%5Etfw">@TFTC21</a> is live on
iTunes now! Catch me and <a href="https://twitter.com/santisiri?ref_src=twsrc%5Etfw">@santisiri</a> talking life,
love and the pursuit of happiness. 🔥🔥🔥<a href="https://t.co/MN9k1E3Egf">https://t.co/MN9k1E3Egf</a></p>&mdash;
Marty Bent (@MartyBent) <a href="https://twitter.com/MartyBent/status/927891398304641024?ref_src=twsrc%5Etfw">November
7, 2017</a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
Expand Down
Loading

0 comments on commit e42d501

Please sign in to comment.