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

feat: improve LNURL ux #2152

Merged
merged 3 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 19 additions & 29 deletions src/app/components/SatButtons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,29 @@ import Button from "../Button";
type Props = {
onClick: (amount: string) => void;
disabled?: boolean;
min?: number;
max?: number;
};

function SatButtons({ onClick, disabled }: Props) {
function SatButtons({ onClick, disabled, min, max }: Props) {
const sizes = [1000, 5000, 10000, 25000];

return (
<div className="flex gap-2">
<Button
icon={<SatoshiV2Icon className="w-4 h-4" />}
label="1k ⚡"
onClick={() => onClick("1000")}
fullWidth
disabled={disabled}
/>
<Button
icon={<SatoshiV2Icon className="w-4 h-4" />}
label="5k ⚡"
onClick={() => onClick("5000")}
fullWidth
disabled={disabled}
/>
<Button
icon={<SatoshiV2Icon className="w-4 h-4" />}
label="10k ⚡"
onClick={() => onClick("10000")}
fullWidth
disabled={disabled}
/>
<Button
icon={<SatoshiV2Icon className="w-4 h-4" />}
label="25k ⚡"
onClick={() => onClick("25000")}
fullWidth
disabled={disabled}
/>
{sizes.map((size) => (
<Button
key={size}
icon={<SatoshiV2Icon className="w-4 h-4" />}
label={size / 1000 + "k"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the head of Emoji is removing the ⚡️ emojis here?

onClick={() => onClick(size.toString())}
fullWidth
disabled={
disabled ||
(min != undefined && min > size) ||
(max != undefined && max < size)
}
/>
))}
</div>
);
}
Expand Down
21 changes: 15 additions & 6 deletions src/app/components/form/DualCurrencyField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useEffect, useRef } from "react";
import { classNames } from "~/app/utils";

import { RangeLabel } from "./rangeLabel";

export type Props = {
suffix?: string;
endAdornment?: React.ReactNode;
Expand Down Expand Up @@ -75,12 +77,19 @@ export default function DualCurrencyField({

return (
<div className="relative block m-0">
<label
htmlFor={id}
className="block font-medium text-gray-800 dark:text-white"
>
{label}
</label>
<div className="flex justify-between items-center w-full">
<label
htmlFor={id}
className="font-medium text-gray-800 dark:text-white"
>
{label}
</label>
{(min || max) && (
<span className="text-xs font-normal">
<RangeLabel min={min} max={max} /> sats
</span>
)}
</div>

<div
className={classNames(
Expand Down
19 changes: 19 additions & 0 deletions src/app/components/form/DualCurrencyField/rangeLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useTranslation } from "react-i18next";

type RangeLabelProps = {
min?: number | string | undefined;
max?: number | string | undefined;
};
export function RangeLabel({ min, max }: RangeLabelProps) {
const { t } = useTranslation("common");

if (min && max) {
return <>{t("range.between", { min, max })}</>;
} else if (min) {
return <>{t("range.greaterThan", { min })}</>;
} else if (max) {
return <>{t("range.lessThan", { max })}</>;
} else {
return null;
}
}
2 changes: 2 additions & 0 deletions src/app/screens/LNURLPay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ function LNURLPay() {
fiatValue={fiatValue}
/>
<SatButtons
min={Math.floor(+details.minSendable / 1000)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is minSendable always available? undefined / 1000 = NaN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think min / max are required fields for LNURL responses. Other components on this form use those value the same way:

https://github.com/getAlby/lightning-browser-extension/pull/2152/files#diff-0ae7727e94b1752f52e903368c32a80af0ae7d22e7d4d4e17bb6b7219fe7a076R415-R416

max={Math.floor(+details.maxSendable / 1000)}
onClick={setValueSat}
disabled={loadingConfirm}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,11 @@
"errors": {
"connection_failed": "Connection failed",
"payment_failed": "Payment Failed"
},
"range": {
"between": "between {{min}} and {{max}}",
"lessThan": "< {{max}}",
"greaterThan": "> {{min}}"
}
},
"components": {
Expand Down