Skip to content

Commit

Permalink
make sure lightning address is lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul authored and TonyGiorgio committed Apr 8, 2024
1 parent bffe3a8 commit 58a91df
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/components/layout/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type TextFieldProps = {
required?: boolean;
multiline?: boolean;
disabled?: boolean;
autoCapitalize?: string;
ref: (element: HTMLInputElement | HTMLTextAreaElement) => void;
onInput: JSX.EventHandler<
HTMLInputElement | HTMLTextAreaElement,
Expand All @@ -32,7 +33,8 @@ export function TextField(props: TextFieldProps) {
"ref",
"onInput",
"onChange",
"onBlur"
"onBlur",
"autoCapitalize"
]);
return (
<KTextField.Root
Expand All @@ -51,18 +53,22 @@ export function TextField(props: TextFieldProps) {
<Show
when={props.multiline}
fallback={
// @ts-expect-error autocapitalize isn't in the props for some reason
<KTextField.Input
{...fieldProps}
type={props.type}
class="w-full rounded-lg bg-white/10 p-2 placeholder-m-grey-400 disabled:text-m-grey-400"
/>
}
>
<KTextField.TextArea
{...fieldProps}
autoResize
class="w-full rounded-lg bg-white/10 p-2 placeholder-neutral-400"
/>
{
// @ts-expect-error autocapitalize isn't in the props for some reason
<KTextField.TextArea
{...fieldProps}
autoResize
class="w-full rounded-lg bg-white/10 p-2 placeholder-neutral-400"
/>
}
</Show>
<KTextField.ErrorMessage class="text-sm text-m-red">
{props.error}
Expand Down
5 changes: 3 additions & 2 deletions src/routes/Feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BackPop,
Button,
ButtonLink,
DefaultMain,
LargeHeader,
NiceP,
TextField,
Expand Down Expand Up @@ -172,7 +173,7 @@ export function Feedback() {
const setupError = state?.setupError || undefined;

return (
<VStack>
<DefaultMain>
<BackPop default="/" />
<Switch>
<Match when={submitted()}>
Expand Down Expand Up @@ -209,6 +210,6 @@ export function Feedback() {
<Show when={!setupError}>
<NavBar activeTab="send" />
</Show>
</VStack>
</DefaultMain>
);
}
20 changes: 17 additions & 3 deletions src/routes/settings/LightningAddress.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Capacitor } from "@capacitor/core";
import {
createForm,
custom,
required,
reset,
SubmitHandler
Expand Down Expand Up @@ -40,6 +41,12 @@ type HermesForm = {
name: string;
};

const validateLowerCase = (value?: string) => {
if (!value) return false;
const valid = /^[a-z0-9-_.]+$/;
return valid.test(value);
};

// todo(paul) put this somewhere else
function HermesForm(props: { onSubmit: (name: string) => void }) {
const [state, _] = useMegaStore();
Expand All @@ -62,7 +69,7 @@ function HermesForm(props: { onSubmit: (name: string) => void }) {
setSuccess("");
setError(undefined);
try {
const name = f.name.trim();
const name = f.name.trim().toLowerCase();
const available =
await state.mutiny_wallet?.check_available_lnurl_name(name);
if (!available) {
Expand Down Expand Up @@ -91,19 +98,26 @@ function HermesForm(props: { onSubmit: (name: string) => void }) {
return (
<Form onSubmit={handleSubmit}>
<VStack>
<Field name="name" validate={[required("Must not be empty")]}>
<Field
name="name"
validate={[
required("Must not be empty"),
custom(validateLowerCase, "Address must be lowercase")
]}
>
{(field, props) => (
<div class="flex w-full flex-1 gap-2">
<div class="flex-1">
<TextField
{...props}
{...field}
autoCapitalize="none"
error={field.error}
label={"Nym"}
required
/>
</div>
<div class="flex-0 self-end pb-2 text-2xl text-m-grey-350">
<div class="flex-0 self-start pt-8 text-2xl text-m-grey-350">
@{hermesDomain}
</div>
</div>
Expand Down

0 comments on commit 58a91df

Please sign in to comment.