Skip to content

Commit

Permalink
multi lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Dec 21, 2023
1 parent a823015 commit 1f7e580
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 5 deletions.
123 changes: 122 additions & 1 deletion src/components/KitchenSink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Collapsible, TextField } from "@kobalte/core";
import { createForm, url } from "@modular-forms/solid";
import { MutinyChannel, MutinyPeer } from "@mutinywallet/mutiny-wasm";
import {
createResource,
Expand All @@ -14,18 +15,25 @@ import {
Button,
ConfirmDialog,
ExternalLink,
TextField as FTextField,
Hr,
InnerCard,
MiniStringShower,
ResetRouter,
Restart,
ResyncOnchain,
showToast,
SimpleErrorDisplay,
ToggleHodl,
VStack
} from "~/components";
import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import {
getSettings,
MutinyWalletSettingStrings,
Network,
setSettings
} from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import { eify, mempoolTxUrl } from "~/utils";

Expand Down Expand Up @@ -439,9 +447,122 @@ function ListNodes() {
);
}

function LSPS(props: { initialSettings: MutinyWalletSettingStrings }) {
const i18n = useI18n();
const [state, _] = useMegaStore();
const [lspSettingsForm, { Form, Field }] =
createForm<MutinyWalletSettingStrings>({
validate: (values) => {
const errors: Record<string, string> = {};
if (
values.lsp &&
(values.lsps_connection_string || values.lsps_token)
) {
errors.lsp = i18n.t("settings.servers.lsps_valid_error");
}
return errors;
},
initialValues: props.initialSettings
});

async function handleSubmit(values: MutinyWalletSettingStrings) {
console.log("values", values);
try {
await state.mutiny_wallet?.change_lsp(
values.lsp ? values.lsp : undefined,
values.lsps_connection_string
? values.lsps_connection_string
: undefined,
values.lsps_token ? values.lsps_token : undefined
);
await setSettings(values);
window.location.reload();
} catch (e) {
console.error("Error changing lsp:", e);
showToast(eify(e));
}
console.log(values);
}

return (
<InnerCard>
<Form onSubmit={handleSubmit} class="flex flex-col gap-4">
<Field
name="lsp"
validate={[url(i18n.t("settings.servers.error_lsp"))]}
>
{(field, props) => (
<FTextField
{...props}
value={field.value}
error={field.error}
label={i18n.t("settings.servers.lsp_label")}
caption={i18n.t("settings.servers.lsp_caption")}
/>
)}
</Field>
<Field name="lsps_connection_string">
{(field, props) => (
<FTextField
{...props}
value={field.value}
error={field.error}
label={i18n.t(
"settings.servers.lsps_connection_string_label"
)}
caption={i18n.t(
"settings.servers.lsps_connection_string_caption"
)}
/>
)}
</Field>
<Field name="lsps_token">
{(field, props) => (
<FTextField
{...props}
value={field.value}
error={field.error}
label={i18n.t("settings.servers.lsps_token_label")}
caption={i18n.t(
"settings.servers.lsps_token_caption"
)}
/>
)}
</Field>
<Button
type="submit"
disabled={!lspSettingsForm.dirty}
intent="blue"
>
{i18n.t("settings.servers.save")}
</Button>
</Form>
</InnerCard>
);
}

function AsyncLSPSEditor() {
const [settings] = createResource<MutinyWalletSettingStrings>(getSettings);

return (
<Switch>
<Match when={settings.error}>
<SimpleErrorDisplay error={settings.error} />
</Match>
<Match when={settings.latest}>
<LSPS initialSettings={settings()!} />
</Match>
</Switch>
);
}

export function KitchenSink() {
return (
<>
<Suspense>
<AsyncLSPSEditor />
</Suspense>
<Hr />
<ListNodes />
<Hr />
<PeersList />
Expand Down
11 changes: 11 additions & 0 deletions src/i18n/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,17 @@ export default {
lsp_label: "LSP",
lsp_caption:
"Lightning Service Provider. Automatically opens channels to you for inbound liquidity. Also wraps invoices for privacy.",
lsps_connection_string_label: "LSPS Connection String",
lsps_connection_string_caption:
"Lightning Service Provider. Automatically opens channels to you for inbound liquidity. Using LSP specification.",
error_lsps_connection_string:
"That doesn't look like node connection string",
lsps_token_label: "LSPS Token",
lsps_token_caption:
"LSPS Token. Used to identify what wallet is connecting to the LSP",
lsps_valid_error:
"You can either have just an LSP set or LSPS Connection String and LSPS Token set, not both.",
error_lsps_token: "That doesn't look like a valid token",
storage_label: "Storage",
storage_caption: "Encrypted VSS backup service.",
error_lsp: "That doesn't look like a URL",
Expand Down
25 changes: 21 additions & 4 deletions src/logic/mutinyWalletSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type MutinyWalletSettingStrings = {
esplora?: string;
rgs?: string;
lsp?: string;
lsps_connection_string?: string;
lsps_token?: string;
auth?: string;
subscriptions?: string;
storage?: string;
Expand Down Expand Up @@ -43,6 +45,16 @@ const SETTINGS_KEYS = [
storageKey: "USER_SETTINGS_lsp",
default: import.meta.env.VITE_LSP
},
{
name: "lsps_connection_string",
storageKey: "USER_SETTINGS_lsps_connection_string",
default: import.meta.env.VITE_LSPS_CONNECTION_STRING
},
{
name: "lsps_token",
storageKey: "USER_SETTINGS_lsps_token",
default: import.meta.env.VITE_LSPS_TOKEN
},
{
name: "auth",
storageKey: "USER_SETTINGS_auth",
Expand Down Expand Up @@ -229,6 +241,8 @@ export async function setupMutinyWallet(
esplora,
rgs,
lsp,
lsps_connection_string,
lsps_token,
auth,
subscriptions,
storage,
Expand All @@ -241,13 +255,18 @@ export async function setupMutinyWallet(
console.log("Using esplora address", esplora);
console.log("Using rgs address", rgs);
console.log("Using lsp address", lsp);
console.log("Using lsp connection string", lsps_connection_string);
console.log("Using lsp token", lsps_token);
console.log("Using auth address", auth);
console.log("Using subscriptions address", subscriptions);
console.log("Using storage address", storage);
console.log("Using scorer address", scorer);
console.log(safeMode ? "Safe mode enabled" : "Safe mode disabled");
console.log(shouldZapHodl ? "Hodl zaps enabled" : "Hodl zaps disabled");

// Only use lsps if there's no lsp set
const shouldUseLSPS = !lsp && lsps_connection_string && lsps_token;

const mutinyWallet = await new MutinyWallet(
// Password
password ? password : undefined,
Expand All @@ -258,10 +277,8 @@ export async function setupMutinyWallet(
esplora,
rgs,
lsp,
// LSPS connection string
undefined,
// LSPS token
undefined,
shouldUseLSPS ? lsps_connection_string : undefined,
shouldUseLSPS ? lsps_token : undefined,
auth,
subscriptions,
storage,
Expand Down

0 comments on commit 1f7e580

Please sign in to comment.