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/nextui inputs #795

Merged
merged 9 commits into from
Dec 4, 2024
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
72 changes: 0 additions & 72 deletions src/components/InputField.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/components/Toggle.tsx

This file was deleted.

53 changes: 0 additions & 53 deletions src/components/__tests__/InputField.test.tsx

This file was deleted.

16 changes: 12 additions & 4 deletions src/pages/Home/OpenChannelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
ConfirmModal,
type Props as ConfirmModalProps,
} from "@/components/ConfirmModal";
import InputField from "@/components/InputField";
import { checkError } from "@/utils/checkError";
import { convertMSatToSat, stringToNumber } from "@/utils/format";
import { instance } from "@/utils/interceptor";
import { Input } from "@nextui-org/react";
import { ChangeEvent, useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -75,13 +75,21 @@ export default function OpenChannelModal({ balance, disclosure }: Props) {
<AvailableBalance balance={convertedBalance!} />

<fieldset className="flex w-full flex-col gap-4">
<InputField
<Input
className="w-full"
classNames={{
inputWrapper:
"bg-tertiary group-data-[focus=true]:bg-tertiary group-data-[hover=true]:bg-tertiary",
}}
type="text"
label={t("home.node_uri")}
isInvalid={!!errors.nodeUri}
errorMessage={errors.nodeUri?.message}
{...register("nodeUri", {
required: t("forms.validation.node_uri.required"),
})}
label={t("home.node_uri")}
errorMessage={errors.nodeUri}
/>

<AmountInput
amount={amount}
errorMessage={errors.fundingAmount}
Expand Down
12 changes: 10 additions & 2 deletions src/pages/Home/ReceiveModal/ReceiveLN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Alert } from "@/components/Alert";
import AmountInput from "@/components/AmountInput";
import { Button } from "@/components/Button";
import { ConfirmModal } from "@/components/ConfirmModal";
import InputField from "@/components/InputField";
import { stringToNumber } from "@/utils/format";
import { Input } from "@nextui-org/react";
import type { ChangeEvent, FC } from "react";
import { useState } from "react";
import type { SubmitHandler } from "react-hook-form";
Expand Down Expand Up @@ -65,7 +65,15 @@ const ReceiveLN: FC<Props> = ({ isLoading, error, onSubmitHandler }) => {
/>

<div className="mt-2 flex flex-col justify-center">
<InputField
<Input
className="w-full"
classNames={{
inputWrapper:
"bg-tertiary group-data-[focus=true]:bg-tertiary group-data-[hover=true]:bg-tertiary",
}}
type="text"
isInvalid={!!errors.commentInput}
errorMessage={errors.commentInput?.message}
{...register("commentInput", {
onChange: commentChangeHandler,
})}
Expand Down
19 changes: 13 additions & 6 deletions src/pages/Home/SendModal/SendLN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Alert } from "@/components/Alert";
import AvailableBalance from "@/components/AvailableBalance";
import { Button } from "@/components/Button";
import { ConfirmModal } from "@/components/ConfirmModal";
import InputField from "@/components/InputField";
import { convertMSatToSat } from "@/utils/format";
import { Input } from "@nextui-org/react";
import { FC, useState } from "react";
import type { SubmitHandler } from "react-hook-form";
import { useForm } from "react-hook-form";
Expand Down Expand Up @@ -60,18 +60,25 @@ const SendLn: FC<Props> = ({
<ConfirmModal.Body>
<AvailableBalance balance={convertedBalance!} />

<InputField
<Input
className="w-full"
classNames={{
inputWrapper:
"bg-tertiary group-data-[focus=true]:bg-tertiary group-data-[hover=true]:bg-tertiary",
}}
type="text"
isInvalid={!!errors.invoice}
errorMessage={errors.invoice?.message}
label={t("wallet.invoice")}
placeholder="lnbc..."
disabled={isLoading}
{...register("invoice", {
required: t("forms.validation.lnInvoice.required"),
pattern: {
value: /^(lnbc|lntb)\w+/i,
message: t("forms.validation.lnInvoice.patternMismatch"),
},
})}
label={t("wallet.invoice")}
errorMessage={errors.invoice}
placeholder="lnbc..."
disabled={isLoading}
/>

{error && <Alert color="danger">{error}</Alert>}
Expand Down
47 changes: 33 additions & 14 deletions src/pages/Home/SendModal/SendOnChain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import AmountInput from "@/components/AmountInput";
import AvailableBalance from "@/components/AvailableBalance";
import { Button } from "@/components/Button";
import { ConfirmModal } from "@/components/ConfirmModal";
import InputField from "@/components/InputField";
import { stringToNumber } from "@/utils/format";
import { Checkbox } from "@nextui-org/checkbox";
import { Input } from "@nextui-org/react";
import { ChangeEvent, FC, useState } from "react";
import type { SubmitHandler } from "react-hook-form";
import { useForm } from "react-hook-form";
Expand Down Expand Up @@ -67,7 +68,12 @@ const SendOnChain: FC<Props> = ({ balance, onConfirm, confirmData }) => {

<fieldset className="flex flex-col items-center justify-center text-center">
<div className="w-full py-1">
<InputField
<Input
className="w-full"
classNames={{
inputWrapper:
"bg-tertiary group-data-[focus=true]:bg-tertiary group-data-[hover=true]:bg-tertiary",
}}
{...register("address", {
required: t("forms.validation.chainAddress.required"),
pattern: {
Expand All @@ -77,7 +83,8 @@ const SendOnChain: FC<Props> = ({ balance, onConfirm, confirmData }) => {
})}
placeholder="bc1..."
label={t("wallet.address")}
errorMessage={errors.address}
isInvalid={!!errors.address}
errorMessage={errors.address?.message}
/>
</div>

Expand Down Expand Up @@ -106,28 +113,40 @@ const SendOnChain: FC<Props> = ({ balance, onConfirm, confirmData }) => {
)}

<div className="flex w-full justify-start gap-2 pb-1">
<InputField
{...register("spendAll", {})}
label={t("tx.spend_all")}
errorMessage={errors.spendAll}
type="checkbox"
/>
<Checkbox {...register("spendAll", {})}>
{t("tx.spend_all")}
</Checkbox>
</div>

<div className="w-full py-1">
<InputField
<Input
classNames={{
inputWrapper:
"bg-tertiary group-data-[focus=true]:bg-tertiary group-data-[hover=true]:bg-tertiary",
}}
{...register("fee", {
required: t("forms.validation.chainFee.required"),
})}
label={t("tx.fee")}
errorMessage={errors.fee}
inputRightAddon="sat / vByte"
isInvalid={!!errors.fee}
errorMessage={errors.fee?.message}
type="number"
endContent={
<div className="pointer-events-none flex items-center">
<span className="whitespace-nowrap text-small text-default-400">
sat / vByte
</span>
</div>
}
/>
</div>

<div className="w-full py-1">
<InputField
<Input
classNames={{
inputWrapper:
"bg-tertiary group-data-[focus=true]:bg-tertiary group-data-[hover=true]:bg-tertiary",
}}
{...register("comment")}
label={t("tx.comment")}
placeholder={t("tx.comment_placeholder")}
Expand All @@ -137,7 +156,7 @@ const SendOnChain: FC<Props> = ({ balance, onConfirm, confirmData }) => {
</ConfirmModal.Body>

<ConfirmModal.Footer>
<Button color="primary" type="submit" disabled={!isValid}>
<Button color="primary" type="submit" isDisabled={!isValid}>
{t("wallet.confirm")}
</Button>
</ConfirmModal.Footer>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home/SendModal/__tests__/SendModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("SendModal", () => {
});
const addressInput = screen.getByLabelText("wallet.invoice");
await user.type(addressInput, "bla");
expect(addressInput).toHaveClass("input-error");
expect(addressInput).toHaveAttribute("aria-invalid", "true");
expect(sendBtn).toBeDisabled();
});

Expand Down Expand Up @@ -119,7 +119,7 @@ describe("SendModal", () => {
it("should show error on wrong addrees input", async () => {
const addressInput = await screen.findByLabelText("wallet.address");
await user.type(addressInput, "bccccccc");
expect(addressInput).toHaveClass("input-error");
expect(addressInput).toHaveAttribute("aria-invalid", "true");
});

it("should format amount correctly", async () => {
Expand Down
Loading