Skip to content

Commit bf2cc50

Browse files
committed
display bounties, tips, contracts separately along with the total amount awarded
1 parent 387ee93 commit bf2cc50

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -779,39 +779,42 @@ defmodule Algora.Bounties do
779779
where: u.id == ^org_id,
780780
where: b.status == :open
781781

782-
rewarded_bounties_query =
783-
from b in Bounty,
784-
join: u in assoc(b, :owner),
785-
where: u.id == ^org_id,
786-
where: b.status == :paid
787-
788-
rewarded_users_query =
782+
rewards_query =
789783
from t in Transaction,
790784
where: t.type == :credit,
791785
where: t.status == :succeeded,
792786
join: lt in assoc(t, :linked_transaction),
793787
where: lt.type == :debit,
794788
where: lt.status == :succeeded,
795-
where: lt.user_id == ^org_id,
796-
distinct: :user_id
789+
where: lt.user_id == ^org_id
790+
791+
rewarded_bounties_query = distinct(rewards_query, :bounty_id)
792+
rewarded_tips_query = distinct(rewards_query, :tip_id)
793+
rewarded_contracts_query = distinct(rewards_query, :contract_id)
794+
rewarded_users_query = distinct(rewards_query, :user_id)
797795

796+
# TODO: this is not correct, we need to get the users who have received rewards only in the last month
798797
rewarded_users_last_month_query =
799798
where(rewarded_users_query, [t], t.succeeded_at >= fragment("NOW() - INTERVAL '1 month'"))
800799

801800
members_query = Member.filter_by_org_id(Member, org_id)
802801
open_bounties = Repo.aggregate(open_bounties_query, :count, :id)
803802
open_bounties_amount = Repo.aggregate(open_bounties_query, :sum, :amount) || zero_money
804-
total_awarded = Repo.aggregate(rewarded_bounties_query, :sum, :amount) || zero_money
805-
completed_bounties = Repo.aggregate(rewarded_bounties_query, :count, :id)
803+
total_awarded_amount = Repo.aggregate(rewards_query, :sum, :net_amount) || zero_money
804+
rewarded_bounties_count = Repo.aggregate(rewarded_bounties_query, :count, :id)
805+
rewarded_tips_count = Repo.aggregate(rewarded_tips_query, :count, :id)
806+
rewarded_contracts_count = Repo.aggregate(rewarded_contracts_query, :count, :id)
806807
solvers_count_last_month = Repo.aggregate(rewarded_users_last_month_query, :count, :user_id)
807808
solvers_count = Repo.aggregate(rewarded_users_query, :count, :user_id)
808809
members_count = Repo.aggregate(members_query, :count, :id)
809810

810811
%{
811812
open_bounties_amount: open_bounties_amount,
812813
open_bounties_count: open_bounties,
813-
total_awarded: total_awarded,
814-
completed_bounties_count: completed_bounties,
814+
total_awarded_amount: total_awarded_amount,
815+
rewarded_bounties_count: rewarded_bounties_count,
816+
rewarded_tips_count: rewarded_tips_count,
817+
rewarded_contracts_count: rewarded_contracts_count,
815818
solvers_count: solvers_count,
816819
solvers_diff: solvers_count - solvers_count_last_month,
817820
members_count: members_count

lib/algora_web/live/org/dashboard_public_live.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ defmodule AlgoraWeb.Org.DashboardPublicLive do
8484
/>
8585
<.stat_card
8686
title="Total Awarded"
87-
value={Money.to_string!(@stats.total_awarded)}
88-
subtext={"#{@stats.completed_bounties_count} bounties"}
87+
value={Money.to_string!(@stats.total_awarded_amount)}
88+
subtext={"#{@stats.rewarded_bounties_count} #{ngettext("bounty", "bounties", @stats.rewarded_bounties_count)} / #{@stats.rewarded_tips_count} #{ngettext("tip", "tips", @stats.rewarded_tips_count)} / #{@stats.rewarded_contracts_count} #{ngettext("contract", "contracts", @stats.rewarded_contracts_count)}"}
8989
navigate={~p"/org/#{@org.handle}/bounties?status=completed"}
9090
icon="tabler-gift"
9191
/>

0 commit comments

Comments
 (0)