Skip to content

Commit

Permalink
Merge pull request #488 from DemocracyEarth/daoverse
Browse files Browse the repository at this point in the history
Correctly processes a proposal.
  • Loading branch information
santisiri authored Dec 13, 2019
2 parents dfead32 + 13929b1 commit 92826df
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@
"moloch-period-voting": "Voting now.",
"moloch-period-grace": "Grace period.",
"moloch-period-abort": "Aborted.:",
"moloch-period-complete": "Aborted.",
"moloch-period-complete": "Completed.",
"moloch-period-passed": "Passed.",
"moloch-period-rejected": "Rejected.",
"moloch-period-aborted": "Aborted.",
Expand Down
11 changes: 6 additions & 5 deletions imports/api/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,18 @@ Meteor.methods({
*/
sync(lastTimestamp) {
check(lastTimestamp, Date);
const feed = Contracts.find({ $or: [{ period: 'VOTING' }, { period: 'GRACE' }, { period: 'QUEUE' }, { period: 'PROCESS' }] }).fetch();
const feed = Contracts.find({ $or: [{ period: 'COMPLETE' }, { period: 'VOTING' }, { period: 'GRACE' }, { period: 'QUEUE' }, { period: 'PROCESS' }] }).fetch();

log(`{ method: 'sync', feed.length: '${feed.length}' }`);
log(`{ method: 'sync', feed.length: '${feed.length}', lastTimestamp: '${lastTimestamp}' }`);

let newPeriod;
let queueEnd;
for (let i = 0; i < feed.length; i += 1) {
newPeriod = feed[i].period;
switch (feed[i].period) {
case 'PROCESS':
if (lastTimestamp > feed[i].closing.graceCalendar && feed[i].processed) {
case 'COMPLETE':
if (lastTimestamp >= feed[i].closing.graceCalendar && feed[i].processed) {
if (!feed[i].aborted) {
newPeriod = 'COMPLETE';
}
Expand All @@ -360,14 +361,14 @@ Meteor.methods({
}
break;
case 'VOTING':
if (lastTimestamp > feed[i].closing.calendar) {
if (lastTimestamp > feed[i].closing.calendar && !feed[i].processed) {
newPeriod = 'GRACE';
}
break;
case 'QUEUE':
default:
queueEnd = parseInt(feed[i].timestamp.getTime() + feed[i].closing.periodDuration, 10);
if (lastTimestamp > queueEnd) {
if (lastTimestamp > queueEnd && !feed[i].processed) {
newPeriod = 'VOTING';
}
break;
Expand Down
22 changes: 8 additions & 14 deletions imports/startup/both/modules/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,22 +587,16 @@ const _getLastTimestamp = async () => {
if (!Session.get('blockTimes')) {
await sync();
}
return await _getBlockHeight().then(async (resolved) => {
return await web3.eth.getBlock(resolved).then((res) => {
const timestamp = res.timestamp * 1000;
Session.set('lastTimestamp', timestamp);
Meteor.call('sync', new Date(timestamp), (error) => {
if (error) {
console.log(error);
}
});
const blockTimes = Session.get('blockTimes');
if (blockTimes && blockTimes.length > 0) {
return _.pluck(_.where(blockTimes, { collectiveId: defaults.ROOT }), 'timestamp');
const blockTimes = Session.get('blockTimes');
if (blockTimes && blockTimes.length > 0) {
const timestamp = _.pluck(_.where(blockTimes, { collectiveId: defaults.ROOT }), 'timestamp');
Meteor.call('sync', new Date(timestamp[0]), (error) => {
if (error) {
console.log(error);
}
return undefined;
});
});
return timestamp;
}
}
return undefined;
};
Expand Down
3 changes: 0 additions & 3 deletions imports/startup/both/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ Router.route('/', {
loadingTemplate: 'load',
onBeforeAction() {
_reset();
sync();
this.next();
},
data() {
Expand Down Expand Up @@ -166,7 +165,6 @@ Router.route('/address/:username', {
onBeforeAction() {
Session.set('sidebarMenuSelectedId', 999);
_reset();
sync();
this.next();
},
data() {
Expand Down Expand Up @@ -222,7 +220,6 @@ Router.route('/tx/:keyword', {
onBeforeAction() {
Session.set('sidebarMenuSelectedId', 999);
_reset();
sync();
this.next();
},
data() {
Expand Down
1 change: 1 addition & 0 deletions imports/ui/templates/layout/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';

const _sync = async () => {
console.log('syncing....');
return await new Promise((resolve, reject) => {
Meteor.call('getBlock', [], (error, result) => {
if (error) { reject(error); }
Expand Down
14 changes: 8 additions & 6 deletions imports/ui/templates/widgets/feed/feedItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const _getProposalDescription = (title, onlyTitle) => {
const json = JSON.parse(xmlDescription.json);
if (json && json.description !== undefined) {
const description = wrapURLs(json.description, true);
const html = `<div>${json.title}</div><div class='title-description'>${description}</div>`;
const html = `<div class='title-header'>${json.title}</div><div class='title-description'>${description}</div>`;
if (onlyTitle) { return json.title; }
return html;
}
Expand Down Expand Up @@ -188,10 +188,12 @@ const parseURL = (text) => {
*/
const _hasSubstring = (str, items) => {
let item;
for (let i = 0; i < items.length; i += 1) {
item = items[i];
if (str.indexOf(item) > -1) {
return true;
if (str) {
for (let i = 0; i < items.length; i += 1) {
item = str.match(items[i]);
if (item && item.length > 0) {
return true;
}
}
}
return false;
Expand All @@ -203,7 +205,7 @@ const _hasSubstring = (str, items) => {
* @return {string} html with linked url
*/
const _clickOnWhitespace = (className) => {
return _hasSubstring(className, ['checkbox', 'title-input', 'option-title', 'identity-list']);
return _hasSubstring(className, ['checkbox', 'title-input', 'title-header', 'title-description', 'smart-contract', 'identity-peer', 'parameter-name', 'parameter-line', 'option-title', 'identity-list']);
};

/**
Expand Down
10 changes: 7 additions & 3 deletions lib/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ const _mirrorTransactionState = (event, map, state, collectiveId, block) => {
log(`[web3] Updating user data with reserves: ${JSON.stringify(reserves)}...`);
migrateAddress(authorUsername, settings);
}

const index = new BigNumber(event.returnValues.proposalIndex).toString();
const contractDB = Contracts.findOne({ importId: index });
if (contractDB) {
Contracts.update({ _id: contractDB._id }, { $set: { processed: true, didPass: event.returnValues.didPass } });
log(`[web3] Processed proposal ${index}...`);
}
};


Expand Down Expand Up @@ -640,19 +647,16 @@ const _writeEvents = async (event, smartContract, state, collectiveId) => {
if (eventTimestamp >= lastEventBlockTimestamp) {
_mirrorContractEvent(event[i], map[k], state, collectiveId, block);
}
// processingIndex += 1;
}
if (event[i].event === 'ProcessProposal') {
if (eventTimestamp >= lastEventBlockTimestamp) {
_mirrorTransactionState(event[i], map[k], state, collectiveId, block);
}
// processingIndex += 1;
}
if (event[i].event === 'SubmitVote') {
if (eventTimestamp >= lastEventBlockTimestamp) {
_mirrorTransaction(event[i], map[k], collectiveId, block);
}
// processingIndex += 1;
}
if (event[i].event === 'SummonComplete') {
if (eventTimestamp >= lastEventBlockTimestamp) {
Expand Down

0 comments on commit 92826df

Please sign in to comment.