Skip to content

Commit 605b576

Browse files
committed
fix miscellanea
1 parent 9c62bbe commit 605b576

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ defmodule Algora.Bounties do
256256
Repo.transact(fn ->
257257
with {:ok, tip} <- Repo.insert(changeset) do
258258
create_payment_session(
259-
%{creator: creator, amount: amount, description: "Tip payment for OSS contributions"},
259+
%{owner: owner, amount: amount, description: "Tip payment for OSS contributions"},
260260
ticket_ref: opts[:ticket_ref],
261261
tip_id: tip.id,
262262
recipient: recipient
@@ -267,17 +267,17 @@ defmodule Algora.Bounties do
267267

268268
@spec reward_bounty(
269269
%{
270-
creator: User.t(),
270+
owner: User.t(),
271271
amount: Money.t(),
272272
bounty_id: String.t(),
273273
claims: [Claim.t()]
274274
},
275275
opts :: [ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()}]
276276
) ::
277277
{:ok, String.t()} | {:error, atom()}
278-
def reward_bounty(%{creator: creator, amount: amount, bounty_id: bounty_id, claims: claims}, opts \\ []) do
278+
def reward_bounty(%{owner: owner, amount: amount, bounty_id: bounty_id, claims: claims}, opts \\ []) do
279279
create_payment_session(
280-
%{creator: creator, amount: amount, description: "Bounty payment for OSS contributions"},
280+
%{owner: owner, amount: amount, description: "Bounty payment for OSS contributions"},
281281
ticket_ref: opts[:ticket_ref],
282282
bounty_id: bounty_id,
283283
claims: claims
@@ -341,7 +341,7 @@ defmodule Algora.Bounties do
341341
end
342342

343343
@spec create_payment_session(
344-
%{creator: User.t(), amount: Money.t(), description: String.t()},
344+
%{owner: User.t(), amount: Money.t(), description: String.t()},
345345
opts :: [
346346
ticket_ref: %{owner: String.t(), repo: String.t(), number: integer()},
347347
tip_id: String.t(),
@@ -351,7 +351,7 @@ defmodule Algora.Bounties do
351351
]
352352
) ::
353353
{:ok, String.t()} | {:error, atom()}
354-
def create_payment_session(%{creator: creator, amount: amount, description: description}, opts \\ []) do
354+
def create_payment_session(%{owner: owner, amount: amount, description: description}, opts \\ []) do
355355
tx_group_id = Nanoid.generate()
356356

357357
line_items =
@@ -370,7 +370,7 @@ defmodule Algora.Bounties do
370370
tip_id: opts[:tip_id],
371371
bounty_id: opts[:bounty_id],
372372
claim_id: nil,
373-
user_id: creator.id,
373+
user_id: owner.id,
374374
gross_amount: gross_amount,
375375
net_amount: amount,
376376
total_fee: Money.sub!(gross_amount, amount),
@@ -383,7 +383,7 @@ defmodule Algora.Bounties do
383383
tip_id: opts[:tip_id],
384384
bounty_id: opts[:bounty_id],
385385
amount: amount,
386-
creator_id: creator.id,
386+
creator_id: owner.id,
387387
group_id: tx_group_id
388388
}),
389389
{:ok, session} <-

lib/algora_web/live/claim_live.ex

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ defmodule AlgoraWeb.ClaimLive do
174174
end
175175

176176
@impl true
177+
def handle_params(_params, _url, %{assigns: %{current_user: nil}} = socket) do
178+
{:noreply, socket}
179+
end
180+
177181
def handle_params(%{"context" => context_id}, _url, socket) do
178182
{:noreply, socket |> assign_selected_context(context_id) |> assign_line_items()}
179183
end
@@ -203,6 +207,15 @@ defmodule AlgoraWeb.ClaimLive do
203207
|> assign_line_items()}
204208
end
205209

210+
def handle_event("split_bounty", _params, socket) do
211+
# TODO: Implement split bounty
212+
Logger.error(
213+
"Attempt to split bounty #{socket.assigns.target.repository.user.provider_login}/#{socket.assigns.target.repository.name}#{socket.assigns.target.number}"
214+
)
215+
216+
{:noreply, socket}
217+
end
218+
206219
def handle_event("pay_with_stripe", %{"reward_bounty_form" => params}, socket) do
207220
changeset = RewardBountyForm.changeset(%RewardBountyForm{}, params)
208221

@@ -267,7 +280,7 @@ defmodule AlgoraWeb.ClaimLive do
267280
Bounties.create_bounty(%{
268281
creator: socket.assigns.current_user,
269282
owner: socket.assigns.selected_context,
270-
amount: data.amount,
283+
amount: Money.new!(:USD, data.amount),
271284
ticket_ref: ticket_ref(socket)
272285
})
273286

@@ -281,7 +294,7 @@ defmodule AlgoraWeb.ClaimLive do
281294

282295
Bounties.reward_bounty(
283296
%{
284-
creator: socket.assigns.current_user,
297+
owner: socket.assigns.selected_context,
285298
amount: final_amount,
286299
bounty_id: bounty.id,
287300
claims: socket.assigns.claims
@@ -383,7 +396,8 @@ defmodule AlgoraWeb.ClaimLive do
383396
<.card_title>
384397
Authors
385398
</.card_title>
386-
<.button variant="secondary">
399+
<!-- TODO: hide if user is not an admin -->
400+
<.button variant="secondary" phx-click="split_bounty">
387401
Split bounty
388402
</.button>
389403
</div>
@@ -497,7 +511,7 @@ defmodule AlgoraWeb.ClaimLive do
497511
</div>
498512
</div>
499513
</div>
500-
<.drawer show={@show_reward_bounty_modal} on_cancel="close_drawer">
514+
<.drawer :if={@current_user} show={@show_reward_bounty_modal} on_cancel="close_drawer">
501515
<.drawer_header>
502516
<.drawer_title>Reward Bounty</.drawer_title>
503517
<.drawer_description>
@@ -519,27 +533,18 @@ defmodule AlgoraWeb.ClaimLive do
519533
<.card_content>
520534
<div class="space-y-4">
521535
<%= if Enum.empty?(@available_bounties) do %>
522-
<div class="flex flex-col gap-4">
523-
<.alert variant="destructive">
524-
<.alert_title>No bounties available</.alert_title>
525-
<.alert_description>
526-
You don't have any bounties available. Would you like to create one?
527-
</.alert_description>
528-
</.alert>
529-
530-
<.input
531-
label="Amount"
532-
icon="tabler-currency-dollar"
533-
field={@reward_bounty_form[:amount]}
534-
/>
535-
</div>
536-
<% else %>
537-
<.input
538-
label="Amount"
539-
icon="tabler-currency-dollar"
540-
field={@reward_bounty_form[:amount]}
541-
/>
536+
<.alert variant="destructive">
537+
<.alert_title>No bounties available</.alert_title>
538+
<.alert_description>
539+
You didn't post a bounty for this issue. Would you like to create one now?
540+
</.alert_description>
541+
</.alert>
542542
<% end %>
543+
<.input
544+
label="Amount"
545+
icon="tabler-currency-dollar"
546+
field={@reward_bounty_form[:amount]}
547+
/>
543548
544549
<div>
545550
<.label>On behalf of</.label>

0 commit comments

Comments
 (0)