diff --git a/public/i18n/en.json b/public/i18n/en.json index 888852d5..e0772bf7 100644 --- a/public/i18n/en.json +++ b/public/i18n/en.json @@ -378,7 +378,10 @@ "confirm_delete": "Are you sure you want to delete this connection?", "budget": "Budget", "resets_every": "Resets every", - "resubscribe_date": "Resubscribe on" + "resubscribe_date": "Resubscribe on", + "disable_connection": "Disable", + "disabled": "This subscription is disabled. Currently you can't re-enable subscriptions, but we're working to fix that. Check back soon!", + "disable_connection_confirm": "Are you sure you want to disable your subscription? Currently subscriptions can't be re-enabled, we're working to fix that." }, "emergency_kit": { "title": "Emergency Kit", diff --git a/src/components/NWCEditor.tsx b/src/components/NWCEditor.tsx index df34a59f..9b7b6302 100644 --- a/src/components/NWCEditor.tsx +++ b/src/components/NWCEditor.tsx @@ -6,13 +6,16 @@ import { SubmitHandler } from "@modular-forms/solid"; import { BudgetPeriod, NwcProfile, TagItem } from "@mutinywallet/mutiny-wasm"; +import { createAsync } from "@solidjs/router"; import { + createEffect, createMemo, createResource, For, Match, ResourceFetcher, Show, + Suspense, Switch } from "solid-js"; @@ -112,7 +115,7 @@ export function NWCEditor(props: { const formMode = createMemo(() => { const mode: "createnwa" | "createnwc" | "editnwc" = nwa() ? "createnwa" - : props.initialProfileIndex + : typeof props.initialProfileIndex === "number" ? "editnwc" : "createnwc"; return mode; @@ -173,7 +176,7 @@ export function NWCEditor(props: { NwcProfile | undefined > = async (index, _last) => { console.log("fetching nwc profile", index); - if (!index) return undefined; + if (typeof index !== "number") return undefined; try { const profile: NwcProfile | undefined = @@ -212,7 +215,8 @@ export function NWCEditor(props: { async function saveConnection(f: BudgetForm) { let newProfile: NwcProfile | undefined = undefined; - if (!f.profileIndex) throw new Error("No profile index!"); + if (typeof f.profileIndex !== "number") + throw new Error("No profile index!"); if (!f.auto_approve || f.budget_amount === "0") { newProfile = await sw.set_nwc_profile_require_approval( f.profileIndex @@ -259,11 +263,33 @@ export function NWCEditor(props: { } } + // TODO: refactor nwc editor so we don't need to do this + const initialBudget = createAsync(async () => { + if (profile()?.tag === "Subscription") { + try { + const plans = await sw.get_subscription_plans(); + if (plans.length) { + const returnValue = plans[0].amount_sat.toString() || "0"; + return returnValue; + } else { + return "0"; + } + } catch (e) { + console.error(e); + return "0"; + } + } + if (profile()?.budget_amount) { + return profile()?.budget_amount?.toString() || "0"; + } + return "0"; + }); + return ( {/* FIXME: not getting the contact rn */} - - - - {JSON.stringify(contact(), null, 2)} + + + + + {JSON.stringify(contact(), null, 2)} + + + + - - + ); } function NWCEditorForm(props: { - initialValues: BudgetForm; + values: BudgetForm; formMode: FormMode; budgetMode: BudgetMode; onSave: (f: BudgetForm) => Promise; @@ -339,7 +370,7 @@ function NWCEditorForm(props: { const i18n = useI18n(); const [budgetForm, { Form, Field }] = createForm({ - initialValues: props.initialValues, + initialValues: props.values, validate: (values) => { const errors: Record = {}; if (values.auto_approve && values.budget_amount === "0") { @@ -351,14 +382,20 @@ function NWCEditorForm(props: { } }); + createEffect(() => { + if (props.values) { + setValue(budgetForm, "budget_amount", props.values.budget_amount); + } + }); + const handleFormSubmit: SubmitHandler = async ( f: BudgetForm ) => { // If this throws the message will be caught by the form await props.onSave({ ...f, - profileIndex: props.initialValues.profileIndex, - nwaString: props.initialValues.nwaString + profileIndex: props.values.profileIndex, + nwaString: props.values.nwaString }); }; @@ -373,9 +410,7 @@ function NWCEditorForm(props: { > {(field, fieldProps) => ( - - {i18n.t("settings.connections.edit_budget")} - + + {i18n.t("settings.connections.disabled")} + + } + > + + {i18n.t("settings.connections.edit_budget")} + + - - {i18n.t("settings.connections.delete_connection")} - + + + {props.profile.tag === "Subscription" + ? i18n.t("settings.connections.disable_connection") + : i18n.t("settings.connections.delete_connection")} + + setConfirmOpen(false)} > - {i18n.t("settings.connections.confirm_delete")} + {props.profile.tag === "Subscription" + ? i18n.t("settings.connections.disable_connection_confirm") + : i18n.t("settings.connections.confirm_delete")} ); @@ -223,8 +238,10 @@ function Nwc() { const [profileToOpen, setProfileToOpen] = createSignal(); function editProfile(profile: NwcProfile) { - setProfileToOpen(profile.index); - setDialogOpen(true); + if (profile && typeof profile.index === "number") { + setProfileToOpen(profile.index); + setDialogOpen(true); + } } function createProfile() { @@ -277,7 +294,7 @@ function Nwc() { {(profile) => (
{JSON.stringify(contact(), null, 2)}