Skip to content

Commit

Permalink
Merge pull request #465 from DemocracyEarth/webVote-qv
Browse files Browse the repository at this point in the history
Quadratic Voting & Coin Votes
  • Loading branch information
santisiri authored May 1, 2019
2 parents 0d3f1c2 + 4d2bf6f commit 86f7b8f
Show file tree
Hide file tree
Showing 134 changed files with 5,729 additions and 1,095 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Custom
config/production/settings.json
config/production/decentraland.json
config/production/colorado.json
config/staging/settings.json

.vscode
_deprecations

Expand Down
28 changes: 26 additions & 2 deletions config/development/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"codename": "Quixote",
"config":
{
"blockchainLogin": false,
"commentRanking": true,
"proposalDrafting": true,
"appCache": false,
Expand All @@ -71,7 +70,32 @@
"checkList": true
},
"displayLanding": false,
"allowWebVotes": true
"allowWebVotes": true,
"defaultRules": {
"quadraticVoting": false,
"balanceVoting": false,
"pollVoting": false
},
"interface": {
"showTransactions": false,
"adminBallotCreatorOnly": {
"active": false,
"email": "[email protected]"
}
},
"governance": {
"dictatorship": true,
"dictator": {
"userId": "y2RPht3xHDLf7KN3u",
"publicAddress": ""
}
},
"loginOptions": {
"blockstack": true,
"metamask": true,
"email": true,
"blockchainLogin": false
}
}
},

Expand Down
68 changes: 61 additions & 7 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
"new-profile-pic": "Profile picture updated.",
"valid-country": "The typed nationality does not exist.",
"missing-name": "At least a first name is required.",
"missing-username": "Username is required without spaces.",
"missing-username": "This username is invalid.",
"digital-citizen": "Digital",
"pending-verification": "E-mail not verified. <a href='' class='resend-verification-link'>Resend link</a>?",
"user-not-found": "User not found.",
Expand Down Expand Up @@ -230,6 +230,12 @@
"hours-compressed" : "hours",
"minutes-compressed" : "min",
"seconds-compressed" : "sec",
"years-singular": "year",
"months-singular": "month",
"days-singular": "day",
"hours-singular": "hour",
"minutes-singular": "min",
"seconds-singular": "sec",
"latest-proposals": "Latest Proposals",
"all-proposals": "All Proposals",
"drafts": "Drafts",
Expand Down Expand Up @@ -426,6 +432,7 @@
"remove-all-votes": "remove all votes",
"empty-values-ballot": "No values found on ballot.",
"not-enough-funds": "Not enough funds.",
"not-enough-funds-qv": "Not enough funds. The cost of voting for this option is {{qvCost}}",
"invalid-transaction": "Self voting is not allowed.",
"events": "Events",
"actions": "Actions",
Expand Down Expand Up @@ -519,7 +526,7 @@
"hashtag-tag-description": "All posts tagged #{{hashtag}} on {{collective}}.",
"country-tag-title": "{{country}} posts on {{collective}}.",
"country-tag-description": "All posts from citizens of {{country}} on {{collective}}.",
"recent-activity": "Recent Transactions",
"recent-activity": "Recent Activity",
"bitcoin": "Bitcoin",
"fund-organization": "Fund Organization",
"btc": "BTC",
Expand Down Expand Up @@ -547,7 +554,7 @@
"valid-coin": "This cryptocurrency does not exist.",
"from": "from",
"holding": "holding",
"valid-email-domain": "with a {{domain}} valid e-mail",
"valid-email-domain": "with a verified {{domain}} e-mail address",
"electorate-incompatible-warning": "To vote on this proposal you must meet the requirements.",
"log-in-network": "Login to network.",
"authenticate-self": "Authenticate",
Expand All @@ -566,7 +573,7 @@
"post-idea": "Post Idea",
"happening-now": "Happening Now",
"requisites": "Requisites",
"post-new-idea": "A new idea...",
"post-new-idea": "A new decision...",
"insufficient-votes": "Unable to find the required token balance in your wallet",
"tokenless-post": "No tokens specified for voting here",
"get-tokens": "Get tokens",
Expand Down Expand Up @@ -599,9 +606,9 @@
"transaction-broadcast": "{{token}} Transaction sent to blockchain.",
"ethereum-metamask": "Ethereum",
"no-chain-found": "No blockchain address found.",
"metamask-confirm-transaction": "Confirm transaction in your blockchain wallet. <br>Delegate responsible for post tokens:",
"metamask-confirm-transaction": "Confirm transaction in your blockchain wallet. <br>To be included Delegate list:",
"ticket": "ticket",
"transaction-status-confirmed-onchain": "Confirmed on chain transaciton",
"transaction-status-confirmed-onchain": "Confirmed on chain transaction",
"transaction-status-signed-offchain": "Signed off chain stake",
"transaction-status-pending-onchain": "Pending on chain transaction",
"transaction-status-fail-onchain": "Failed on chain transaction",
Expand Down Expand Up @@ -670,5 +677,52 @@
"token-erc-20": "ERC 20 Token",
"token-blockchain": "Blockchain Activity",
"token-saft": "SAFT Purchase",
"off-chain": "off chain"
"off-chain": "off chain",
"voting-editor-offchain-toggle": "Off-chain",
"voting-editor-balance-toggle": "Coin vote",
"voting-editor-quadratic-toggle": "Quadratic vote",
"voting-editor-poll-voting": "Include poll",
"advanced-rules": "Advanced",
"voting-editor-balance-tooltip": "Account balance gets tallied after signing with private key.",
"voting-editor-quadratic-tooltip": "The cost of voting for a choice increases at a quadratic rate.",
"voting-editor-poll-tooltip": "Include a poll with multiple options on this post.",
"poll-choice": "Poll choice {{number}}",
"poll-default-title-0": "Downvote 👎",
"poll-default-title-1": "Upvote 👍",
"poll-inside": "Election Poll",
"ticker-rule-quadratic": "",
"ticker-rule-balance": "Balance",
"decision-rules": "Decision Mechanism",
"remove-vote": "Remove vote from this choice.",
"election-rule-quadratic": "Quadratic Vote",
"election-rule-balance": "Coin Vote",
"token-budget": "Budget",
"closing-date": "Closing",
"always-on-tooltip": "An <em>Always On</em> decision does not have a closing date.",
"decision-deadline": "Decision Deadline",
"blockchain-time": "Blockchain Time",
"blockchain-time-daily": "24 hours",
"blockchain-time-weekly": "7 days",
"blockchain-time-monthly": "30 days",
"blockchain-time-quarterly": "1 quarter",
"blockchain-time-annual": "1 year",
"duration": "Duration",
"blockchain-time-closing-criteria": "Poll ends when <strong>{{blockchain}}</strong> reaches a block height of <strong>{{height}}</strong> blocks estimated on <strong>{{date}}</strong>.",
"blockchain-time-always-on": "This poll never ends and tallies an ongoing result.",
"countdown-expiration": "Poll ends in {{days}} {{hours}} {{minutes}} {{seconds}} (in {{blocks}})",
"blocks-compressed": "blocks",
"blocks-singular": "block",
"poll-closed-after-time": "Poll ended after {{days}} (at block {{height}})",
"poll-never-ends": "This poll never ends (always on).",
"height-compressed": "blocks",
"height-singular": "block",
"poll-is-closed": "This poll is no longer open for voting.",
"feeds": "Feeds",
"poll-hypothetical": "Poll will end in {{days}} {{hours}} {{minutes}} {{seconds}} (in {{blocks}})",
"coinvote-signature": "A total of {{quantity}} {{ticker}} will be tallied in support of {{choice}} in the proposal available on {{url}}. No tokens will be spent.",
"metamask-confirm-tally": "Sign vote with your private key.<br>To be included on Delegate list:",
"transaction-tally": "{{token}} Signature verified, account balance tallied.",
"transaction-tally-denied": "{{token}} Signature denied, no votes tallied.",
"already-voted": "Already Voted",
"already-voted-detail": "Your account balance has already been tallied on this decision."
}
83 changes: 71 additions & 12 deletions imports/api/blockchain/modules/web3Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Meteor } from 'meteor/meteor';
import Web3 from 'web3';
import abi from 'human-standard-token-abi';
import { BigNumber } from 'bignumber.js';

import { token } from '/lib/token';

const numeral = require('numeral');

// Set web3 provider
let web3;
Expand Down Expand Up @@ -172,23 +174,79 @@ const _getTokenData = async (_publicAddress) => {
let _balance;

for (let i = 0; i < token.coin.length; i++) {
_balance = await _getTokenBalance(_publicAddress, token.coin[i].contractAddress);
if (_balance.toNumber() !== 0) {
const withoutDecimal = _removeDecimal(_balance.toNumber(), token.coin[i].decimals);
const tokenObj = {
balance: withoutDecimal.toNumber(),
placed: 0,
available: withoutDecimal.toNumber(),
token: token.coin[i].code,
publicAddress: _publicAddress,
};

tokenData.push(tokenObj);
if (token.coin[i].type === 'ERC20') {
_balance = await _getTokenBalance(_publicAddress, token.coin[i].contractAddress);
if (_balance.toNumber() !== 0) {
const withoutDecimal = _removeDecimal(_balance.toNumber(), token.coin[i].decimals);
const tokenObj = {
balance: withoutDecimal.toNumber(),
placed: 0,
available: withoutDecimal.toNumber(),
token: token.coin[i].code,
publicAddress: _publicAddress,
};

tokenData.push(tokenObj);
}
}
}
return tokenData;
};

/**
* @summary shows balance in currency not decimals
* @param {object} value value to be changed
* @param {string} token currency being used
* @returns {number}
*/
const _currencyValue = (value, tokenCode) => {
switch (tokenCode) {
case 'WEI':
return _wei2eth(value.toString());
// case 'VOTE':
// return adjustDecimal(value);
default:
return value;
}
};


/**
* @summary format currency display according to crypto rules
* @param {string} value value to be changed
* @param {string} tokenCode currency being used
* @returns {string} formatted number
*/
const _formatCryptoValue = (value, tokenCode) => {
let tokenFinal;
if (!tokenCode) { tokenFinal = 'ETH'; } else { tokenFinal = tokenCode; }
return numeral(_currencyValue(value, tokenFinal)).format(_getCoin(tokenFinal).format);
};


/**
* @summary get the token balance a user has for a given contract coin
* @param {object} user with token
* @param {object} contract to be checked
* @return {string} the balance quantity
*/
const _getBalance = (user, contract) => {
let result;
for (let i = 0; i < user.profile.wallet.reserves.length; i += 1) {
const coin = _getCoin(user.profile.wallet.reserves[i].token);
if (coin.code === contract.blockchain.coin.code) {
if (coin.code === 'ETH') {
result = _formatCryptoValue(_removeDecimal(Meteor.user().profile.wallet.reserves[i].balance, coin.decimals).toNumber(), coin.code);
console.log(result);
} else {
result = _formatCryptoValue(Meteor.user().profile.wallet.reserves[i].balance, coin.code);
}
return result;
}
}
return undefined;
}

export const wei2eth = _wei2eth;
export const getEthBalance = _getEthBalance;
export const getWeiBalance = _getWeiBalance;
Expand All @@ -199,3 +257,4 @@ export const smallNumber = _smallNumber;
export const addDecimal = _addDecimal;
export const getCoin = _getCoin;
export const getTokenData = _getTokenData;
export const getBalance = _getBalance;
Loading

0 comments on commit 86f7b8f

Please sign in to comment.