Skip to content

Commit

Permalink
Merge pull request #491 from DemocracyEarth/daoverse
Browse files Browse the repository at this point in the history
Guild interface with DAO stats.
  • Loading branch information
santisiri authored Jan 3, 2020
2 parents 1ad96f6 + 0d49a9b commit 3dc71a0
Show file tree
Hide file tree
Showing 38 changed files with 1,099 additions and 373 deletions.
1 change: 0 additions & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ [email protected]
mdg:meteor-apm-agent
tmeasday:publish-counts
konecty:nrr
flowkey:raven
kadira:dochead
[email protected]
[email protected]
Expand Down
1 change: 0 additions & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ [email protected]
[email protected]
[email protected]
[email protected]
flowkey:[email protected]
[email protected]
harrison:[email protected]
[email protected]
Expand Down
13 changes: 11 additions & 2 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
"results": "Results",
"total-votes": "(<votes> votes)",
"no": "No",
"yes": "Yes",
"remove-signature-tooltip": "Remove signature from contract.",
"remove-signature": "Remove Signature",
"remove-signature-message": "Do you confirm removing signature from contract?",
Expand Down Expand Up @@ -592,7 +593,7 @@
"send": "Send",
"close": "Close",
"metamask-denied-signature": "Transaction signature was denied.",
"metamask-invalid-address": "Address mismatch.<br>Verify wallet account is the same used to log in.",
"metamask-invalid-address": "Address mismatch.<br>Verify wallet account is the same used to sign in.",
"blockchain-address": "Blockchain Address",
"blockchain-address-placeholder": "Your account if none specified.",
"cost-per-vote": "Tokens required per vote",
Expand Down Expand Up @@ -813,5 +814,13 @@
"moloch-ragequit-funds-withdraw": "Withdrawn Funds",
"quit": "Quit",
"moloch-contract-ragequit": "Retired shares from DAO.",
"moloch-contract-ragequit-tooltip": "A member has burned shares to withdraw funds from this DAO."
"moloch-contract-ragequit-tooltip": "A member has burned shares to withdraw funds from this DAO.",
"not-synced": "Not synced ",
"not-synced-message": "The application is not synced with the corresponding blockchain for this transaction.",
"dao-confirm-tally": "Confirm vote in your blockchain wallet.<br>This will be a vote for <strong>{{voteValue}}</strong>.",
"moloch-guild": "Guild.",
"guild-total-shares": "Total Shares",
"guild-total-assets": "Total Assets",
"guild-share-value": "Value per Share",
"guild-total-value": "Total Value"
}
1 change: 1 addition & 0 deletions imports/api/blockchain/Blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Schema.Blockchain = new SimpleSchema({
});

export const Blockchain = Schema.Blockchain;
export const Parameter = Schema.Parameter;
export const Ticket = Schema.Ticket;
export const Score = Schema.Score;
export const Coin = Schema.Coin;
10 changes: 5 additions & 5 deletions imports/api/blockchain/modules/web3Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ const _getCoin = (code) => {
if (Session.get('token')) { token = Session.get('token'); }
}

let result = _.where(token.coin, { code: code.toUpperCase() });
let result = _.findWhere(token.coin, { code: code.toUpperCase() });

if (result.length === 0) {
result = _.where(token.coin, { subcode: code.toUpperCase() });
result = _.findWhere(token.coin, { subcode: code.toUpperCase() });
}
if (result.length === 0) {
if (code === 'VOTES') {
result = _.where(token.coin, { code: 'VOTE' });
result = _.findWhere(token.coin, { code: 'VOTE' });
} else {
return { code };
}
}
return result[0];
return result;
};

const _writeZeroes = (quantity) => {
Expand All @@ -48,7 +48,7 @@ const _writeZeroes = (quantity) => {
template += '0';
}
return template;
}
};


/**
Expand Down
7 changes: 5 additions & 2 deletions imports/api/collectives/Collectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

import { Wallet } from '/imports/api/users/Wallet';
import { Blockchain } from '/imports/api/blockchain/Blockchain';
import { Blockchain, Parameter } from '/imports/api/blockchain/Blockchain';

export const Collectives = new Mongo.Collection('collectives');

Expand Down Expand Up @@ -97,7 +97,6 @@ Schema.Menu = new SimpleSchema({
},
});


Schema.CollectiveProfile = new SimpleSchema({
website: {
type: String,
Expand All @@ -108,6 +107,10 @@ Schema.CollectiveProfile = new SimpleSchema({
type: String,
optional: true,
},
guild: {
type: [Parameter],
optional: true,
},
blockchain: {
type: Blockchain,
optional: true,
Expand Down
11 changes: 11 additions & 0 deletions imports/api/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ Meteor.methods({
return Contracts.findOne({ _id: contractId });
},

/**
* @summary given a keyword returns contract id
* @param {keyword} keyword identify contract by given keyword
*/
getCollectiveById(collectiveId) {
check(collectiveId, String);

log(`{ method: 'getCollectiveById', user: ${logUser()}, _id: '${collectiveId}' }`);
return Collectives.findOne({ _id: collectiveId });
},

/**
* @summary given a username returns user Id
* @param {string} keyword identify contract by given keyword
Expand Down
19 changes: 18 additions & 1 deletion imports/api/server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Counts } from 'meteor/tmeasday:publish-counts';

import { query } from '/lib/views';
import { log, logUser } from '/lib/const';
import { getFinality } from '/lib/interpreter';

import { Transactions } from '/imports/api/transactions/Transactions';
import { Files } from '/imports/api/files/Files';
import { Contracts } from '/imports/api/contracts/Contracts';
import { Collectives } from '/imports/api/collectives/Collectives';
import { Tokens } from '/imports/api/tokens/tokens';

log('[starting publications]');

Expand Down Expand Up @@ -247,3 +247,20 @@ Meteor.publish('collectives', function (terms) {
}
return this.ready();
});


/**
* @summary gets information of registered collectives on this instance
* @param {Object} terms of query
*/
Meteor.publish('tokens', function (terms) {
check(terms, Object);
const parameters = query(terms);
const tokens = Tokens.find(parameters.find, parameters.options);
if (tokens) {
log(`{ publish: 'tokens', user: ${logUser()} }`);
return tokens;
}
return this.ready();
});

123 changes: 123 additions & 0 deletions imports/api/tokens/tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

export const Tokens = new Mongo.Collection('tokens');

const Schema = {};

Schema.Token = new SimpleSchema({
code: {
type: String,
optional: true,
},
format: {
type: String,
optional: true,
},
emoji: {
type: String,
optional: true,
},
unicode: {
type: String,
optional: true,
},
name: {
type: String,
optional: true,
},
maxSupply: {
type: Number,
optional: true,
},
supply: {
type: Number,
optional: true,
},
decimals: {
type: Number,
optional: true,
},
inflationary: {
type: Boolean,
optional: true,
},
title: {
type: String,
optional: true,
},
color: {
type: String,
optional: true,
},
type: {
type: String,
optional: true,
},
blockchain: {
type: String,
optional: true,
},
contractAddress: {
type: String,
optional: true,
},
defaultVote: {
type: String,
optional: true,
},
oracle: {
type: Boolean,
optional: true,
},
method: {
type: String,
optional: true,
},
abi: {
type: String,
optional: true,
},
editor: {
type: Object,
optional: true,
},
'editor.allowBalanceToggle': {
type: Boolean,
optional: true,
},
'editor.allowBlockchainAddress': {
type: Boolean,
optional: true,
},
'editor.allowQuadraticToggle': {
type: Boolean,
optional: true,
},
});


Tokens.attachSchema(Schema.Token);

Tokens.allow({
insert(userId) {
if (userId) {
return true;
}
return false;
},
update(userId) {
if (userId) {
return true;
}
return false;
},
remove(userId) {
if (userId) {
return true;
}
return false;
},
});

export const Token = Schema.Token;
79 changes: 77 additions & 2 deletions imports/startup/both/modules/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { animatePopup } from '/imports/ui/modules/popup';
import { Transactions } from '/imports/api/transactions/Transactions';
import { sync } from '/imports/ui/templates/layout/sync';
import { defaults } from '/lib/const';
import { Collectives } from '/imports/api/collectives/Collectives';

import { BigNumber } from 'bignumber.js';

Expand Down Expand Up @@ -228,6 +229,79 @@ const _delegate = (sourceId, targetId, contractId, hash, value) => {
}
};

/**
* @summary obtains the map of a given contract based on required function to execute
* @param {object} smartContracts from collective map
* @param {string} functionName to identify abi from contract context
*/
const _getMap = (smartContracts, functionName) => {
let myself;
let index;
let found = false;
if (smartContracts) {
for (let i = 0; i < smartContracts.length; i += 1) {
myself = _.findWhere(smartContracts[i].map, { eventName: functionName });
if (myself.eventName === functionName) {
found = true;
index = i;
break;
}
}
if (found) {
return smartContracts[index];
}
}
return undefined;
};

/**
* @summary submit vote to moloch dao
* @param {number} proposalIndex uint256
* @param {number} uintVote uint8
*/
const _submitVote = async (proposalIndex, uintVote, collectiveId) => {
if (_web3(true)) {
const collective = Collectives.findOne({ _id: collectiveId });
const smartContracts = collective.profile.blockchain.smartContracts;

const map = _getMap(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 res;
});

console.log(`dao: ${dao}`);
// const dao = await new web3.eth.Contract(abi, smartContract.publicAddress);
console.log('submitting vote....');
console.log(`proposalIndex: ${proposalIndex}`);
console.log(`uintVote: ${uintVote}`);
}
};

/**
* @summary send crypto with mask;
* @param {string} from blockchain address
Expand Down Expand Up @@ -336,10 +410,10 @@ const _transactWithMetamask = (from, to, quantity, tokenCode, contractAddress, s
}
});
}).catch(function (e) {
if (e.message === 'Returned error: Error: MetaMask Tx Signature: User denied transaction signature.') {
if (e.code === 4001) {
modal.message = TAPi18n.__('metamask-denied-signature');
displayModal(true, modal);
} else if (e.message.substring(0, 65) === 'Returned error: Error: WalletMiddleware - Invalid "from" address.') {
} else if (e.code === -32603) {
modal.message = TAPi18n.__('metamask-invalid-address');
displayModal(true, modal);
} else {
Expand Down Expand Up @@ -732,3 +806,4 @@ export const hideLogin = _hideLogin;
export const getBlockHeight = _getBlockHeight;
export const getLastTimestamp = _getLastTimestamp;
export const verifyCoinVote = _verifyCoinVote;
export const submitVote = _submitVote;
Loading

0 comments on commit 3dc71a0

Please sign in to comment.