From 69f9ba57f640454f68e8dce78b8cf8ca1882b59e Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Wed, 8 May 2024 18:23:47 -0500 Subject: [PATCH 1/3] Show disabled NWCs again --- src/routes/settings/Connections.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/settings/Connections.tsx b/src/routes/settings/Connections.tsx index 79b82e63..06d3ff99 100644 --- a/src/routes/settings/Connections.tsx +++ b/src/routes/settings/Connections.tsx @@ -277,7 +277,7 @@ function Nwc() { {(profile) => ( Date: Thu, 9 May 2024 09:53:57 -0500 Subject: [PATCH 2/3] fix profile index bugs --- src/components/NWCEditor.tsx | 40 +++++++++++++++++++++++------ src/routes/settings/Connections.tsx | 8 +++--- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/components/NWCEditor.tsx b/src/components/NWCEditor.tsx index df34a59f..27766603 100644 --- a/src/components/NWCEditor.tsx +++ b/src/components/NWCEditor.tsx @@ -6,6 +6,7 @@ import { SubmitHandler } from "@modular-forms/solid"; import { BudgetPeriod, NwcProfile, TagItem } from "@mutinywallet/mutiny-wasm"; +import { createAsync } from "@solidjs/router"; import { createMemo, createResource, @@ -112,7 +113,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 +174,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 +213,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,6 +261,27 @@ export function NWCEditor(props: { } } + const planDetails = createAsync(async () => { + try { + const plans = await sw.get_subscription_plans(); + if (plans.length) { + return plans[0]; + } + } catch (e) { + console.error(e); + } + }); + + const initialBudget = createMemo(() => { + if (profile()?.tag === "Subscription" && planDetails()) { + return planDetails()?.amount_sat.toString() || "16000"; + } + if (profile()?.budget_amount) { + return profile()?.budget_amount?.toString() || "0"; + } + return "0"; + }); + return ( @@ -308,12 +331,13 @@ export function NWCEditor(props: { initialValues={{ connection_name: profile()?.name ?? "", auto_approve: !profile()?.require_approval, - budget_amount: - profile()?.budget_amount?.toString() ?? "0", + budget_amount: initialBudget(), interval: - (profile() - ?.budget_period as BudgetForm["interval"]) ?? - "Day", + profile()?.tag === "Subscription" + ? "Month" + : (profile()?.budget_period?.toString() as BudgetForm["interval"]) || + "Day", + profileIndex: profile()?.index }} formMode={formMode()} diff --git a/src/routes/settings/Connections.tsx b/src/routes/settings/Connections.tsx index 06d3ff99..a1b5a17f 100644 --- a/src/routes/settings/Connections.tsx +++ b/src/routes/settings/Connections.tsx @@ -223,8 +223,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() { @@ -294,7 +296,7 @@ function Nwc() { open={dialogOpen()} setOpen={handleToggleOpen} title={ - profileToOpen() + typeof profileToOpen() === "number" ? i18n.t("settings.connections.edit_connection") : i18n.t("settings.connections.add_connection") } From e88e65284f0c7e4df7bb4a3c3a167a06d2eb09f9 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 9 May 2024 10:53:32 -0500 Subject: [PATCH 3/3] fix budget enable / disable for subscriptions, better disable descriptions --- public/i18n/en.json | 5 +- src/components/NWCEditor.tsx | 107 +++++++++++++++------------- src/routes/settings/Connections.tsx | 29 ++++++-- 3 files changed, 85 insertions(+), 56 deletions(-) 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 27766603..9b7b6302 100644 --- a/src/components/NWCEditor.tsx +++ b/src/components/NWCEditor.tsx @@ -8,12 +8,14 @@ import { 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"; @@ -261,20 +263,21 @@ export function NWCEditor(props: { } } - const planDetails = createAsync(async () => { - try { - const plans = await sw.get_subscription_plans(); - if (plans.length) { - return plans[0]; + // 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"; } - } catch (e) { - console.error(e); - } - }); - - const initialBudget = createMemo(() => { - if (profile()?.tag === "Subscription" && planDetails()) { - return planDetails()?.amount_sat.toString() || "16000"; } if (profile()?.budget_amount) { return profile()?.budget_amount?.toString() || "0"; @@ -286,7 +289,7 @@ export function NWCEditor(props: { {/* 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; @@ -363,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") { @@ -375,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 }); }; @@ -397,9 +410,7 @@ function NWCEditorForm(props: { > {(field, fieldProps) => ( - + + {i18n.t("settings.connections.disabled")} + + } + > + + - + + + 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")} );