Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require 21k+ sats budget for alby connection card #749

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions frontend/src/components/BudgetAmountSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,44 @@ import { budgetOptions } from "src/types";
function BudgetAmountSelect({
value,
onChange,
minAmount,
}: {
value: number;
onChange: (value: number) => void;
minAmount?: number;
}) {
const [customBudget, setCustomBudget] = React.useState(
value ? !Object.values(budgetOptions).includes(value) : false
);
return (
<>
<div className="grid grid-cols-2 md:grid-cols-5 gap-2 text-xs mb-4">
{Object.keys(budgetOptions).map((budget) => {
return (
<div
key={budget}
onClick={() => {
setCustomBudget(false);
onChange(budgetOptions[budget]);
}}
className={cn(
"cursor-pointer rounded text-nowrap border-2 text-center p-4 slashed-zero",
!customBudget && value == budgetOptions[budget]
? "border-primary"
: "border-muted"
)}
>
{`${budget} ${budgetOptions[budget] ? " sats" : ""}`}
</div>
);
})}
{Object.keys(budgetOptions)
.filter(
(budget) =>
!minAmount ||
!budgetOptions[budget] ||
budgetOptions[budget] > minAmount
)
.map((budget) => {
return (
<div
key={budget}
onClick={() => {
setCustomBudget(false);
onChange(budgetOptions[budget]);
}}
className={cn(
"cursor-pointer rounded text-nowrap border-2 text-center p-4 slashed-zero",
!customBudget && value == budgetOptions[budget]
? "border-primary"
: "border-muted"
)}
>
{`${budget} ${budgetOptions[budget] ? " sats" : ""}`}
</div>
);
})}
<div
onClick={() => {
setCustomBudget(true);
Expand All @@ -60,7 +69,7 @@ function BudgetAmountSelect({
type="number"
required
autoFocus
min={1}
min={minAmount || 1}
value={value || ""}
onChange={(e) => {
onChange(parseInt(e.target.value));
Expand Down
78 changes: 43 additions & 35 deletions frontend/src/components/connections/AlbyConnectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Link2Icon,
ZapIcon,
} from "lucide-react";
import { useState } from "react";
import { FormEvent, useState } from "react";
import { Link } from "react-router-dom";

import BudgetAmountSelect from "src/components/BudgetAmountSelect";
Expand Down Expand Up @@ -47,6 +47,12 @@ function AlbyConnectionCard({ connection }: { connection?: App }) {
const [budgetRenewal, setBudgetRenewal] =
useState<BudgetRenewalType>("monthly");

function onSubmit(e: FormEvent) {
e.preventDefault();

linkAccount(maxAmount, budgetRenewal);
}

return (
<Card>
<CardHeader>
Expand Down Expand Up @@ -86,40 +92,42 @@ function AlbyConnectionCard({ connection }: { connection?: App }) {
</LoadingButton>
</DialogTrigger>
<DialogContent>
<DialogHeader>Link to Alby Account</DialogHeader>
<DialogDescription className="flex flex-col gap-4">
After you link your account, your lightning address and
every app you access through your Alby Account will handle
payments via the Hub.
<img
src="/images/illustrations/alby-account-dark.svg"
className="w-full hidden dark:block"
/>
<img
src="/images/illustrations/alby-account-light.svg"
className="w-full dark:hidden"
/>
You can add a budget that will restrict how much can be
spent from the Hub with your Alby Account.
</DialogDescription>
<div>
<BudgetRenewalSelect
value={budgetRenewal}
onChange={setBudgetRenewal}
/>
<BudgetAmountSelect
value={maxAmount}
onChange={setMaxAmount}
/>
</div>
<DialogFooter>
<LoadingButton
onClick={() => linkAccount(maxAmount, budgetRenewal)}
loading={loading}
>
Link to Alby Account
</LoadingButton>
</DialogFooter>
<form onSubmit={onSubmit}>
<DialogHeader>Link to Alby Account</DialogHeader>
<DialogDescription className="flex flex-col gap-4">
After you link your account, your lightning address and
every app you access through your Alby Account will
handle payments via the Hub.
<img
src="/images/illustrations/alby-account-dark.svg"
className="w-full hidden dark:block"
/>
<img
src="/images/illustrations/alby-account-light.svg"
className="w-full dark:hidden"
/>
You can add a budget that will restrict how much can be
spent from the Hub with your Alby Account.
</DialogDescription>
<div>
rolznz marked this conversation as resolved.
Show resolved Hide resolved
<BudgetRenewalSelect
value={budgetRenewal}
onChange={setBudgetRenewal}
/>
<BudgetAmountSelect
value={maxAmount}
onChange={setMaxAmount}
minAmount={
25000 /* the minimum should be a bit more than the Alby monthly fee */
}
/>
</div>
<DialogFooter>
<LoadingButton loading={loading}>
Link to Alby Account
</LoadingButton>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
) : linkStatus === LinkStatus.ThisNode ? (
Expand Down
Loading