Skip to content

Commit

Permalink
Add error message for tor urls
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman authored and TonyGiorgio committed Mar 22, 2024
1 parent e1843e6 commit ee32e59
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions public/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@
"storage_label": "Storage",
"storage_caption": "Encrypted VSS backup service.",
"error_lsp": "That doesn't look like a URL",
"error_tor": "Tor URLs are not currently supported",
"save": "Save"
},
"nostr_contacts": {
Expand Down
62 changes: 56 additions & 6 deletions src/routes/settings/Servers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createForm, url } from "@modular-forms/solid";
import { createForm, custom, url } from "@modular-forms/solid";
import { createResource, Match, Suspense, Switch } from "solid-js";

import {
Expand All @@ -24,6 +24,26 @@ import {
} from "~/logic/mutinyWalletSetup";
import { eify } from "~/utils";

const validateNotTorUrl = async (value?: string) => {
if (!value) {
return false;
}

// if it is one of the default URLs, it's safe
// need this handling for self-hosting deployments
if (
value === import.meta.env.VITE_PROXY ||
value === import.meta.env.VITE_ESPLORA ||
value === import.meta.env.VITE_RGS ||
value === import.meta.env.VITE_LSP ||
value === import.meta.env.VITE_STORAGE
) {
return true;
}

return !value.includes(".onion");
};

function SettingsStringsEditor(props: {
initialSettings: MutinyWalletSettingStrings;
}) {
Expand Down Expand Up @@ -54,7 +74,13 @@ function SettingsStringsEditor(props: {
<div />
<Field
name="proxy"
validate={[url(i18n.t("settings.servers.error_proxy"))]}
validate={[
url(i18n.t("settings.servers.error_proxy")),
custom(
validateNotTorUrl,
i18n.t("settings.servers.error_tor")
)
]}
>
{(field, props) => (
<TextField
Expand All @@ -68,7 +94,13 @@ function SettingsStringsEditor(props: {
</Field>
<Field
name="esplora"
validate={[url(i18n.t("settings.servers.error_esplora"))]}
validate={[
url(i18n.t("settings.servers.error_esplora")),
custom(
validateNotTorUrl,
i18n.t("settings.servers.error_tor")
)
]}
>
{(field, props) => (
<TextField
Expand All @@ -82,7 +114,13 @@ function SettingsStringsEditor(props: {
</Field>
<Field
name="rgs"
validate={[url(i18n.t("settings.servers.error_rgs"))]}
validate={[
url(i18n.t("settings.servers.error_rgs")),
custom(
validateNotTorUrl,
i18n.t("settings.servers.error_tor")
)
]}
>
{(field, props) => (
<TextField
Expand All @@ -96,7 +134,13 @@ function SettingsStringsEditor(props: {
</Field>
<Field
name="lsp"
validate={[url(i18n.t("settings.servers.error_lsp"))]}
validate={[
url(i18n.t("settings.servers.error_lsp")),
custom(
validateNotTorUrl,
i18n.t("settings.servers.error_tor")
)
]}
>
{(field, props) => (
<TextField
Expand All @@ -110,7 +154,13 @@ function SettingsStringsEditor(props: {
</Field>
<Field
name="storage"
validate={[url(i18n.t("settings.servers.error_lsp"))]}
validate={[
url(i18n.t("settings.servers.error_lsp")),
custom(
validateNotTorUrl,
i18n.t("settings.servers.error_tor")
)
]}
>
{(field, props) => (
<TextField
Expand Down

0 comments on commit ee32e59

Please sign in to comment.