Skip to content

Commit

Permalink
feat: multi dao banner
Browse files Browse the repository at this point in the history
  • Loading branch information
andremury committed Dec 15, 2023
1 parent d04a525 commit 980d36e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 27 deletions.
4 changes: 1 addition & 3 deletions assets/javascripts/discourse/components/karma-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default Component.extend({
if (!daoName) { return };
if (!this.availableDaos.find(d => d.name === daoName)) { return };
set(this, 'daoName', daoName);
window.selectedDao = daoName?.toLowerCase();
window.selectedDao = daoName;
this.fetchProfile();
},

Expand All @@ -65,6 +65,4 @@ export default Component.extend({
profile?.username === this.currentUser?.username
);
},


});
20 changes: 16 additions & 4 deletions assets/javascripts/discourse/components/proposal-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ export default Component.extend({

daoName: "",

availableDaos: [],

logo: computed(function () {
return this.siteSettings.Custom_banner_icon_url || this.siteSettings.logo;
}),

init() {
this._super(...arguments);
this.daoName = window.selectedDao;
set(this, 'availableDaos', this.siteSettings.DAO_names?.split(",").map(
name => ({ name, select: () => this.selectDao(name) })));
},

@action
selectDao(daoName) {
if (!daoName) { return };
if (!this.availableDaos.find(d => d.name === daoName)) { return };
set(this, 'daoName', daoName);
window.selectedDao = daoName;
set(this, 'fetched', false);
this.fetchDataProposals();
},

@action
Expand All @@ -50,10 +64,8 @@ export default Component.extend({
daoIds,
} = this.siteSettings;
// Fix this workaround when voting history is refactored into components
const graphqlIds = (window.daoIds =
window.daoIds ??
daoIds ??
(await fetchDaoSnapshotAndOnChainIds(this.daoName)));
const graphqlIds =
(await fetchDaoSnapshotAndOnChainIds(this.daoName));

let onChain = [];
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
{{#if (and siteSettings.Show_proposal_banner shouldShow)}}
{{#if availableDaos.length}}
<div id="__dao-select">
{{#each availableDaos as |dao|}}
{{#if (eq daoName dao.name)}}
<div class="__dao-item selected" onclick={{dao.select}}>
{{dao.name}}
</div>
{{else}}
<div class="__dao-item" onclick={{dao.select}}>
{{dao.name}}
</div>
{{/if}}
{{/each}}
</div>
{{/if}}
{{#if fetched}}
{{#if proposals.length}}
<div class="karma-banner-title pl-2.5 mt-1">
Expand All @@ -12,8 +27,8 @@
<div class="__banner-wrapper">
<div class="banner-body">
<div
class={{
html-safe (concat "active-proposals-wrapper" " " openClass)
class={{html-safe
(concat "active-proposals-wrapper" " " openClass)
}}
style={{html-safe (concat "height: " bannerHeight ";")}}
>
Expand Down
7 changes: 2 additions & 5 deletions assets/javascripts/initializers/karma-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ function bootstrap(_, ctx) {
const { DAO_names } = ctx.SiteSettings;
if (!DAO_names || !DAO_names.length) { return; }

window.selectedDao = DAO_names.split(',')?.[0]?.toLowerCase();

console.info("DAO_names", DAO_names);
console.info("selected", window.selectedDao);
window.selectedDao = DAO_names.split(',')?.[0];

function release(wrapperId = "#__karma-stats") {
let showing = false;
Expand Down Expand Up @@ -42,7 +39,7 @@ export default {

async initialize(container) {
// eslint-disable-next-line no-console
console.info("Karma Score (v1.3.8-beta3)");
console.info("Karma Score (v1.4.0-beta1)");
const SiteSettings = container.lookup("site-settings:main");
if (SiteSettings.Enable_Karma_plugin) {
withPluginApi("0.8.7", bootstrap, { SiteSettings, container });
Expand Down
3 changes: 1 addition & 2 deletions assets/javascripts/lib/fetch-snapshot-onchain-ids.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import KarmaStats from "../lib/stats/index";

export async function fetchDaoSnapshotAndOnChainIds(daoName) {
console.log('fetchDaOIds',daoName)
const url = `${KarmaStats.url}/dao/${daoName}`;
const url = `${KarmaStats.url}/dao/${daoName}`.toLowerCase();
const { data } = await fetch(url).then((res) => res.json());
return (
data ?? {
Expand Down
6 changes: 3 additions & 3 deletions assets/javascripts/lib/karma-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class KarmaApiClient {
this.daoName = daoName;
this.publicAddress = publicAddress;

this.voteUrl = `${karmaUrl}/forum-user/${daoName}/vote-reason/${publicAddress}`;
this.pitchUrl = `${karmaUrl}/forum-user/${daoName}/delegate-pitch/${publicAddress}`;
this.voteUrl = `${karmaUrl}/forum-user/${daoName}/vote-reason/${publicAddress}`.toLowerCase();
this.pitchUrl = `${karmaUrl}/forum-user/${daoName}/delegate-pitch/${publicAddress}`.toLowerCase();
}

checkHealth() {
Expand Down Expand Up @@ -96,7 +96,7 @@ class KarmaApiClient {
fetchUser(username) {
isTypeof(username, "string");

const url = `${karmaUrl}/forum-user/${username}/${this.daoName}`;
const url = `${karmaUrl}/forum-user/${username}/${this.daoName}`.toLowerCase();
return request(url, null, "GET");
}

Expand Down
1 change: 0 additions & 1 deletion assets/javascripts/lib/mixpanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const mixpanel = mp || initMixpanel();
*/
function reportEvent(data, prefix = "discoursePlugin") {
if (!mixpanel) throw new Error("Mixpanel is not available");
console.log(mixpanel);
return new Promise((resolve, reject) => {
mixpanel.track(`${prefix}:${data.event}`, data.properties, (err) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/lib/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const KarmaStats = {
gitcoinHealthScore: 0,
};

const url = `${KarmaStats.url}/forum-user/${userAddress}/${daoName}`;
const url = `${KarmaStats.url}/forum-user/${userAddress}/${daoName}`.toLowerCase();
try {
const { data } = await fetch(url).then((res) => res.json());
this.profile = data ?? {};
Expand Down
5 changes: 0 additions & 5 deletions assets/javascripts/lib/voting-history/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@ const VotingHistory = {
);
}

const { daoIds } = ctx.SiteSettings;
console.log('before', daoIds, daoName)

const daoName = window.selectedDao;
const amount = this.shouldShowVotingHistory(ctx);
console.log(daoIds, daoName, amount);

// TODO fix this workaround by refactoring this code into components
this.daoIds = (await fetchDaoSnapshotAndOnChainIds(daoName));

console.log('after', daoIds, daoName)

let onChain = [];
if (this.daoIds.onChain?.length) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "karma-stats",
"version": "1.3.8-beta2",
"version": "1.4.0-beta1",
"repository": "https://github.com/show-karma/discourse-plugin",
"author": "Karma",
"license": "MIT",
Expand Down

0 comments on commit 980d36e

Please sign in to comment.