Skip to content

Commit 0c8f1b0

Browse files
committed
display paid amount on claim page
1 parent 96243ed commit 0c8f1b0

File tree

6 files changed

+56
-37
lines changed

6 files changed

+56
-37
lines changed

lib/algora/bounties/schemas/claim.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defmodule Algora.Bounties.Claim do
1515
belongs_to :source, Ticket
1616
belongs_to :target, Ticket, null: false
1717
belongs_to :user, Algora.Accounts.User, null: false
18-
# has_one :transaction, Algora.Payments.Transaction
18+
has_many :transactions, Algora.Payments.Transaction
1919

2020
timestamps()
2121
end

lib/algora/payments/schemas/transaction.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule Algora.Payments.Transaction do
3535
belongs_to :contract, Contract
3636
belongs_to :original_contract, Contract
3737
belongs_to :user, Algora.Accounts.User
38-
# belongs_to :claim, Algora.Bounties.Claim
38+
belongs_to :claim, Algora.Bounties.Claim
3939
belongs_to :bounty, Algora.Bounties.Bounty
4040
belongs_to :tip, Algora.Bounties.Tip
4141
belongs_to :linked_transaction, Algora.Payments.Transaction

lib/algora_web/components/ui/stat_card.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ defmodule AlgoraWeb.Components.UI.StatCard do
2424

2525
defp stat_card_content(assigns) do
2626
~H"""
27-
<div class="group/card relative rounded-lg border bg-card text-card-foreground transition-colors duration-75 hover:bg-accent">
27+
<div class={
28+
classes([
29+
"group/card relative rounded-lg border bg-card text-card-foreground transition-colors duration-75",
30+
@href && "hover:bg-accent"
31+
])
32+
}>
2833
<div class="flex flex-row items-center justify-between space-y-0 p-6 pb-2">
2934
<h3 class="text-sm font-medium tracking-tight">{@title}</h3>
3035
<.icon :if={@icon} name={@icon} class="h-6 w-6 text-muted-foreground" />
3136
</div>
3237
<div class="p-6 pt-0">
33-
<div class="text-2xl font-bold">{@value}</div>
38+
<div class="text-2xl font-bold font-display">{@value}</div>
3439
<p :if={@subtext} class="text-xs text-muted-foreground">{@subtext}</p>
3540
</div>
3641
</div>

lib/algora_web/live/claim_live.ex

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@ defmodule AlgoraWeb.ClaimLive do
1616
|> Repo.all()
1717
|> Repo.preload([
1818
:user,
19+
:transactions,
1920
source: [repository: [:user]],
2021
target: [repository: [:user], bounties: [:owner]]
2122
])
2223

2324
[primary_claim | _] = claims
2425

25-
{:ok, prize_pool} = primary_claim.target.bounties |> Enum.map(& &1.amount) |> Money.sum()
26+
prize_pool =
27+
primary_claim.target.bounties
28+
|> Enum.map(& &1.amount)
29+
|> Enum.reduce(Money.zero(:USD, no_fraction_if_integer: true), &Money.add!(&1, &2))
30+
31+
total_paid =
32+
primary_claim.transactions
33+
|> Enum.filter(&(&1.type == :debit and &1.status == :succeeded))
34+
|> Enum.map(& &1.net_amount)
35+
|> Enum.reduce(Money.zero(:USD, no_fraction_if_integer: true), &Money.add!(&1, &2))
2636

2737
source_body_html =
2838
with token when is_binary(token) <- Github.TokenPool.get_token(),
@@ -41,6 +51,7 @@ defmodule AlgoraWeb.ClaimLive do
4151
|> assign(:source, primary_claim.source)
4252
|> assign(:bounties, primary_claim.target.bounties)
4353
|> assign(:prize_pool, prize_pool)
54+
|> assign(:total_paid, total_paid)
4455
|> assign(:source_body_html, source_body_html)}
4556
end
4657

@@ -49,36 +60,37 @@ defmodule AlgoraWeb.ClaimLive do
4960
~H"""
5061
<div class="container mx-auto py-8 px-4">
5162
<div class="space-y-8">
52-
<%!-- Header with target issue and prize pool --%>
5363
<.header class="mb-8">
54-
<div class="flex items-center gap-4">
55-
<.avatar class="h-16 w-16 rounded-full">
56-
<.avatar_image src={@source.repository.user.avatar_url} />
57-
<.avatar_fallback>
58-
{String.first(@source.repository.user.provider_login)}
59-
</.avatar_fallback>
60-
</.avatar>
61-
<div class="space-y-2">
62-
<.link href={@target.url} class="text-xl font-semibold hover:underline" target="_blank">
63-
{@target.title}
64-
</.link>
65-
<div class="text-sm text-muted-foreground">
66-
{@source.repository.user.provider_login}/{@source.repository.name}#{@source.number}
64+
<div class="grid gap-8 md:grid-cols-[2fr_1fr]">
65+
<div class="flex items-center gap-4">
66+
<.avatar class="h-16 w-16 rounded-full">
67+
<.avatar_image src={@source.repository.user.avatar_url} />
68+
<.avatar_fallback>
69+
{String.first(@source.repository.user.provider_login)}
70+
</.avatar_fallback>
71+
</.avatar>
72+
<div class="space-y-2">
73+
<.link
74+
href={@target.url}
75+
class="text-xl font-semibold hover:underline"
76+
target="_blank"
77+
>
78+
{@target.title}
79+
</.link>
80+
<div class="text-sm text-muted-foreground">
81+
{@source.repository.user.provider_login}/{@source.repository.name}#{@source.number}
82+
</div>
6783
</div>
6884
</div>
69-
</div>
70-
<:actions>
71-
<div class="mt-4 text-2xl font-bold text-success font-display">
72-
{Money.to_string!(@prize_pool)}
85+
<div class="mt-4 grid grid-cols-2 gap-8">
86+
<.stat_card title="Total Paid" value={Money.to_string!(@total_paid)} />
87+
<.stat_card title="Prize Pool" value={Money.to_string!(@prize_pool)} />
7388
</div>
74-
</:actions>
89+
</div>
7590
</.header>
7691
77-
<%!-- New grid layout with different column widths --%>
7892
<div class="grid gap-8 md:grid-cols-[2fr_1fr]">
79-
<%!-- Combined Claim Details Card --%>
8093
<div class="space-y-8">
81-
<%!-- Claimer Info --%>
8294
<.card>
8395
<.card_header>
8496
<div class="grid grid-cols-1 sm:grid-cols-3">
@@ -119,16 +131,11 @@ defmodule AlgoraWeb.ClaimLive do
119131
</.card>
120132
</div>
121133
122-
<%!-- Right Column: Claim Metadata + Sponsors --%>
123134
<div class="space-y-8">
124-
<%!-- Claim Metadata Card --%>
125135
<.card>
126136
<.card_header>
127137
<.card_title>
128-
<div class="flex items-center gap-2">
129-
<.icon name="tabler-info-circle" class="h-5 w-5 text-muted-foreground" />
130-
Claim Info
131-
</div>
138+
Claim
132139
</.card_title>
133140
</.card_header>
134141
<.card_content>
@@ -149,13 +156,10 @@ defmodule AlgoraWeb.ClaimLive do
149156
</.card_content>
150157
</.card>
151158
152-
<%!-- Sponsors Card --%>
153159
<.card>
154160
<.card_header>
155161
<.card_title>
156-
<div class="flex items-center gap-2">
157-
<.icon name="tabler-users" class="h-5 w-5 text-muted-foreground" /> Sponsors
158-
</div>
162+
Sponsors
159163
</.card_title>
160164
</.card_header>
161165
<.card_content>

priv/repo/migrations/20250112164132_recreate_claims.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ defmodule Algora.Repo.Migrations.RecreateClaims do
2020
timestamps()
2121
end
2222

23+
alter table(:transactions) do
24+
add :claim_id, references(:claims, on_delete: :nothing)
25+
end
26+
2327
create unique_index(:claims, [:group_id, :user_id])
2428
create index(:claims, [:source_id])
2529
create index(:claims, [:target_id])
@@ -33,6 +37,10 @@ defmodule Algora.Repo.Migrations.RecreateClaims do
3337
drop index(:claims, [:user_id])
3438
drop table(:claims)
3539

40+
alter table(:transactions) do
41+
remove :claim_id
42+
end
43+
3644
create table(:claims) do
3745
add :provider, :string
3846
add :provider_id, :string

priv/repo/seeds.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ for {repo_name, issues} <- repos do
558558
id: debit_id,
559559
linked_transaction_id: credit_id,
560560
bounty_id: bounty.id,
561+
claim_id: claim.id,
561562
type: :debit,
562563
status: :succeeded,
563564
net_amount: Money.mult!(amount, share),
@@ -569,6 +570,7 @@ for {repo_name, issues} <- repos do
569570
id: credit_id,
570571
linked_transaction_id: debit_id,
571572
bounty_id: bounty.id,
573+
claim_id: claim.id,
572574
type: :credit,
573575
status: :succeeded,
574576
net_amount: Money.mult!(amount, share),

0 commit comments

Comments
 (0)