Skip to content

Commit

Permalink
eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
andremury committed Dec 19, 2023
1 parent af7635b commit 27dc8d0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 44 deletions.
4 changes: 2 additions & 2 deletions assets/javascripts/discourse/components/karma-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default Component.extend({

@action
selectDao(daoName) {
if(!daoName) { return };
if(!this.availableDaos.find(d => d.name === daoName)) { return };
if(!daoName) { return; };
if(!this.availableDaos.find(d => d.name === daoName)) { return; };
set(this, 'daoName', daoName);
window.selectedDao = daoName;
this.fetchProfile();
Expand Down
5 changes: 2 additions & 3 deletions assets/javascripts/discourse/components/proposal-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default Component.extend({

@action
selectDao(daoName) {
if (!daoName) { return };
if (!this.availableDaos.find(d => d.name === daoName)) { return };
if (!daoName) { return; };
if (!this.availableDaos.find(d => d.name === daoName)) { return; };
set(this, 'daoName', daoName);
window.selectedDao = daoName;
set(this, 'fetched', false);
Expand All @@ -61,7 +61,6 @@ export default Component.extend({
async fetchDataProposals() {
const {
Banner_past_proposal_days: daysAgo,
daoIds,
} = this.siteSettings;
// Fix this workaround when voting history is refactored into components
const graphqlIds =
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/discourse/components/vote-breakdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Component from "@ember/component";
import { set, action } from "@ember/object";
import { action, set } from "@ember/object";
import { shortenNumber } from "../../lib/shorten-number";

export default Component.extend({
Expand Down
29 changes: 0 additions & 29 deletions assets/javascripts/lib/karma-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,35 +106,6 @@ class KarmaApiClient {
});
}


/**
* @param {import('karma-score').KarmaApiVotesSummaryRes} summary
* @returns {import('karma-score').ParsedProposal[]}
*/
#parseVotingSummary = (summary) => {
const { proposals, votes } = summary;
const parsedVotes = [];

votes.sort().forEach((vote) => {
const [id, version] = vote.proposalId.split('-');
const proposal = proposals.find(p => p.id === +id && p.version === version);
if (!proposal) {
return;
}

parsedVotes.push({
title: proposal?.title,
proposalId: proposal.id,
voteMethod: "Off-chain",
proposal: proposal?.title,
choice: vote.reason,
executed: moment(proposal.endDate).format("MMMM D, YYYY"),
});
})

return parsedVotes.sort((a, b) => moment(a.executed).isBefore(moment(b.executed)) ? 1 : -1);
}

/**
* Get voting summary for moonbeam and moonriver ONLY
* @returns {Promise<import("karma-score").KarmaApiVotesSummaryRes>
Expand Down
1 change: 0 additions & 1 deletion assets/javascripts/lib/voting-history/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { fetchDaoSnapshotAndOnChainIds } from "../fetch-snapshot-onchain-ids";
import KarmaApiClient from "../karma-api-client";
import { fetchOffChainProposalVotes } from "./gql/off-chain-fetcher";
import { fetchOnChainProposalVotes } from "./gql/on-chain-fetcher";
import { moonriverFetcher } from "./moonbeam/moonbeam";
Expand Down
17 changes: 9 additions & 8 deletions assets/javascripts/lib/voting-history/moonbeam/moonbeam.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import KarmaApiClient from "../../karma-api-client";

const getVoteReason = (vote) => {
if (!vote.reason || typeof vote.reason === 'boolean') return 'Did not vote';
if (vote.reason.toLowerCase() === 'for') return 1;
if (vote.reason.toLowerCase() === 'abstain') return 'ABSTAIN';
if (!vote.reason || typeof vote.reason === 'boolean') { return 'Did not vote'; }
if (vote.reason.toLowerCase() === 'for') { return 1; }
if (vote.reason.toLowerCase() === 'abstain') { return 'ABSTAIN'; }
return 0;
};

Expand Down Expand Up @@ -35,7 +35,7 @@ function concatOnChainProposals(proposals, votes) {
});

proposals.forEach(proposal => {
if (!array.find(item => item.voteId && +item.voteId === +proposal.id))
if (!array.find(item => item.voteId && +item.voteId === +proposal.id)) {
array.push({
voteMethod: 'On-chain',
proposal: proposal.description,
Expand All @@ -48,6 +48,7 @@ function concatOnChainProposals(proposals, votes) {
trackId: Number(proposal?.trackId),
version: proposal?.version,
});
}
});

return array.sort((a, b) => b.executedTimestamp - a.executedTimestamp);
Expand Down Expand Up @@ -97,9 +98,9 @@ async function getDaoProposals(
}

async function fetchOnChainVotes(daoName, address) {
if (!daoName || !address) return [];
if (!daoName || !address) { return []; }
try {
daoName = [daoName].flat()[0]
daoName = [daoName].flat()[0];
const cli = new KarmaApiClient([daoName].flat()[0], address);
const { votes, proposals: cachedProposals } = await cli.fetchVoteSummary();

Expand All @@ -114,7 +115,7 @@ async function fetchOnChainVotes(daoName, address) {
return concatOnChainProposals(proposals, voteList);
}
} catch (error) {
console.error(error)
console.error(error);

Check failure on line 118 in assets/javascripts/lib/voting-history/moonbeam/moonbeam.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
return [];
}
return [];
Expand All @@ -128,7 +129,7 @@ export async function moonriverFetcher(
const votes = await fetchOnChainVotes(daoName, address);
return votes;
} catch (error) {
console.error(error)
console.error(error);

Check failure on line 132 in assets/javascripts/lib/voting-history/moonbeam/moonbeam.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
return [];
}
}

0 comments on commit 27dc8d0

Please sign in to comment.