Skip to content

Commit ee945e2

Browse files
committed
in midst of implementing reward_bounty
1 parent e0efa61 commit ee945e2

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,37 @@ defmodule Algora.Bounties do
270270
end)
271271
end
272272

273+
@spec reward_bounty(
274+
%{
275+
creator: User.t(),
276+
owner: User.t(),
277+
recipient: User.t(),
278+
amount: Money.t(),
279+
bounty_id: String.t(),
280+
claim_id: String.t()
281+
},
282+
opts :: [ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()}]
283+
) ::
284+
{:ok, String.t()} | {:error, atom()}
285+
def reward_bounty(
286+
%{creator: creator, owner: owner, recipient: recipient, amount: amount, bounty_id: bounty_id, claim_id: claim_id},
287+
opts \\ []
288+
) do
289+
# TODO: handle bounty splits
290+
create_payment_session(
291+
%{
292+
creator: creator,
293+
owner: owner,
294+
recipient: recipient,
295+
amount: amount,
296+
description: "Bounty payment for OSS contributions"
297+
},
298+
ticket_ref: opts[:ticket_ref],
299+
bounty_id: bounty_id,
300+
claim_id: claim_id
301+
)
302+
end
303+
273304
@spec create_payment_session(
274305
%{creator: User.t(), owner: User.t(), recipient: User.t(), amount: Money.t(), description: String.t()},
275306
opts :: [

lib/algora_web/live/claim_live.ex

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,37 @@ defmodule AlgoraWeb.ClaimLive do
115115
end
116116
end
117117

118+
@impl true
119+
def handle_event("reward_bounty", _params, socket) do
120+
claim = socket.assigns.primary_claim
121+
122+
# TODO: use the correct bounty
123+
bounty = hd(claim.target.bounties)
124+
125+
case Algora.Bounties.reward_bounty(
126+
%{
127+
# TODO: handle unauthenticated user
128+
creator: socket.assigns.current_user,
129+
owner: bounty.owner,
130+
recipient: claim.user,
131+
amount: bounty.amount,
132+
bounty_id: bounty.id,
133+
claim_id: claim.id
134+
},
135+
ticket_ref: %{
136+
owner: claim.target.repository.user.provider_login,
137+
repo: claim.target.repository.name,
138+
number: claim.target.number
139+
}
140+
) do
141+
{:ok, session_url} ->
142+
{:noreply, redirect(socket, external: session_url)}
143+
144+
{:error, _reason} ->
145+
{:noreply, put_flash(socket, :error, "Failed to create payment session. Please try again later.")}
146+
end
147+
end
148+
118149
@impl true
119150
def render(assigns) do
120151
~H"""
@@ -159,7 +190,7 @@ defmodule AlgoraWeb.ClaimLive do
159190
<.card_title>
160191
Claim
161192
</.card_title>
162-
<.button>
193+
<.button phx-click="reward_bounty">
163194
Reward bounty
164195
</.button>
165196
</div>

0 commit comments

Comments
 (0)