Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 3bcb3f6

Browse files
committed
lsp switcher dropdown
1 parent 8fcebfa commit 3bcb3f6

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

public/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@
545545
"storage_caption": "Encrypted VSS backup service.",
546546
"error_lsp": "That doesn't look like a URL",
547547
"error_tor": "Tor URLs are not currently supported",
548-
"save": "Save"
548+
"save": "Save",
549+
"error_lsp_change_failed": "Unable to change LSP. Maybe you have open channels?"
549550
},
550551
"nostr_contacts": {
551552
"title": "Sync Nostr Contacts",

src/routes/settings/Servers.tsx

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createForm, custom, url } from "@modular-forms/solid";
2-
import { createResource, Match, Suspense, Switch } from "solid-js";
2+
import { createResource, For, Match, Suspense, Switch } from "solid-js";
33

44
import {
55
BackLink,
@@ -13,14 +13,16 @@ import {
1313
NiceP,
1414
showToast,
1515
SimpleErrorDisplay,
16-
TextField
16+
TextField,
17+
TinyText
1718
} from "~/components";
1819
import { useI18n } from "~/i18n/context";
1920
import {
2021
getSettings,
2122
MutinyWalletSettingStrings,
2223
setSettings
2324
} from "~/logic/mutinyWalletSetup";
25+
import { useMegaStore } from "~/state/megaStore";
2426
import { eify } from "~/utils";
2527

2628
const validateNotTorUrl = async (value?: string) => {
@@ -46,6 +48,7 @@ const validateNotTorUrl = async (value?: string) => {
4648
function SettingsStringsEditor(props: {
4749
initialSettings: MutinyWalletSettingStrings;
4850
}) {
51+
const [_state, _actions, sw] = useMegaStore();
4952
const i18n = useI18n();
5053
const [settingsForm, { Form, Field }] =
5154
createForm<MutinyWalletSettingStrings>({
@@ -54,15 +57,66 @@ function SettingsStringsEditor(props: {
5457

5558
async function handleSubmit(values: MutinyWalletSettingStrings) {
5659
try {
60+
if (values.lsp !== props.initialSettings.lsp) {
61+
await sw.change_lsp(
62+
values.lsp ? values.lsp : undefined,
63+
undefined,
64+
undefined
65+
);
66+
}
67+
5768
await setSettings(values);
5869
window.location.reload();
5970
} catch (e) {
6071
console.error(e);
61-
showToast(eify(e));
72+
const err = eify(e);
73+
if (err.message === "Failed to make a request to the LSP.") {
74+
showToast(
75+
new Error(
76+
i18n.t("settings.servers.error_lsp_change_failed")
77+
)
78+
);
79+
} else {
80+
showToast(eify(e));
81+
}
6282
}
63-
console.log(values);
6483
}
6584

85+
const MAINNET_LSP_OPTIONS = [
86+
{
87+
value: "https://0conf.lnolymp.us",
88+
label: "Olympus by Zeus"
89+
},
90+
{
91+
value: "https://lsp.voltageapi.com",
92+
label: "Flow 2.0 by Voltage"
93+
},
94+
{
95+
value: "",
96+
label: "None"
97+
}
98+
];
99+
100+
const SIGNET_LSP_OPTIONS = [
101+
{
102+
value: "https://mutinynet-flow.lnolymp.us",
103+
label: "Olympus by Zeus"
104+
},
105+
{
106+
value: "https://signet-lsp.mutinywallet.com",
107+
label: "Flow 2.0 by Voltage"
108+
},
109+
{
110+
value: "",
111+
label: "None"
112+
}
113+
];
114+
115+
const LSP_OPTIONS =
116+
props.initialSettings.network === "signet"
117+
? SIGNET_LSP_OPTIONS
118+
: MAINNET_LSP_OPTIONS;
119+
66120
return (
67121
<Card title={i18n.t("settings.servers.title")}>
68122
<Form onSubmit={handleSubmit} class="flex flex-col gap-4">
@@ -71,6 +125,42 @@ function SettingsStringsEditor(props: {
71125
{i18n.t("settings.servers.link")}
72126
</ExternalLink>
73127
<div />
128+
129+
<Field
130+
name="lsp"
131+
validate={[url(i18n.t("settings.servers.error_lsp"))]}
132+
>
133+
{(field, props) => (
134+
<div class="flex flex-col gap-2">
135+
<label
136+
class="text-sm font-semibold uppercase"
137+
for="lsp"
138+
id="lsp"
139+
>
140+
{i18n.t("settings.servers.lsp_label")}
141+
</label>
142+
<select
143+
{...props}
144+
value={field.value}
145+
class="w-full rounded-lg bg-m-grey-750 py-2 pl-4 pr-12 text-base font-normal text-white"
146+
>
147+
<For each={LSP_OPTIONS}>
148+
{({ value, label }) => (
149+
<option
150+
selected={field.value === value}
151+
value={value}
152+
>
153+
{label}
154+
</option>
155+
)}
156+
</For>
157+
</select>
158+
<TinyText>
159+
{i18n.t("settings.servers.lsp_caption")}
160+
</TinyText>
161+
</div>
162+
)}
163+
</Field>
74164
<Field
75165
name="proxy"
76166
validate={[

0 commit comments

Comments
 (0)