diff --git a/src/components/BalanceBox.tsx b/src/components/BalanceBox.tsx index a542aba..98fefec 100644 --- a/src/components/BalanceBox.tsx +++ b/src/components/BalanceBox.tsx @@ -1,5 +1,5 @@ import { A, useNavigate } from "@solidjs/router"; -import { createResource, Match, Show, Switch } from "solid-js"; +import { createResource, Match, Show, Suspense, Switch } from "solid-js"; import shuffle from "~/assets/icons/shuffle.svg"; import { @@ -56,18 +56,6 @@ export function BalanceBox(props: { loading?: boolean }) { const usableOnchain = () => (state.balance?.confirmed || 0n) + (state.balance?.unconfirmed || 0n); - async function fetchFederations() { - // Log the attempt to fetch federations - console.log("Attempting to fetch federations..."); - const result = await state.mutiny_wallet?.list_federations(); - console.log("Fetched federations:", result); - return result ?? []; - } - - const [federations, { refetch }] = createResource(fetchFederations, { - // storage: createDeepSignal - }); - return ( <> @@ -103,43 +91,11 @@ export function BalanceBox(props: { loading?: boolean }) { - - -
- }> - - -
- - {i18n.t("common.error_safe_mode")} - -
-
- -
-
- -
-
- -
-
-
-
-
+ + + + -
}>
@@ -201,3 +157,39 @@ export function BalanceBox(props: { loading?: boolean }) { ); } + +function FederationsBalance() { + const [state, _actions] = useMegaStore(); + + async function fetchFederations() { + const result = await state.mutiny_wallet?.list_federations(); + return result ?? []; + } + + const [federations] = createResource(fetchFederations); + + return ( + +
+ + +
+
+ +
+
+ +
+
+
+
+
+ ); +} diff --git a/src/i18n/en/translations.ts b/src/i18n/en/translations.ts index a2c57f0..c95507a 100644 --- a/src/i18n/en/translations.ts +++ b/src/i18n/en/translations.ts @@ -537,8 +537,11 @@ export default { title: "Manage Federations", federation_code_label: "Federation code", federation_code_required: "Federation code can't be blank", + federation_added_success: "Federation added successfully", add: "Add", - remove: "Remove" + remove: "Remove", + expires: "Expires", + federation_id: "Federation ID" }, gift: { give_sats_link: "Give sats as a gift", diff --git a/src/routes/settings/ManageFederations.tsx b/src/routes/settings/ManageFederations.tsx index c98da86..e96022b 100644 --- a/src/routes/settings/ManageFederations.tsx +++ b/src/routes/settings/ManageFederations.tsx @@ -18,34 +18,24 @@ import { } from "~/components"; import { useI18n } from "~/i18n/context"; import { useMegaStore } from "~/state/megaStore"; -import { eify } from "~/utils"; +import { eify, timeAgo } from "~/utils"; type FederationForm = { federation_code: string; }; -function fetchFederations() { - const [state, _actions] = useMegaStore(); - try { - // Log the attempt to fetch federations - console.log('Attempting to fetch federations...'); - const result = state.mutiny_wallet?.list_federations(); - console.log('Fetched federations:', result); - return result ?? []; - } catch (e) { - console.error('Error fetching federations:', e); - return []; - } -} +type MutinyFederationIdentity = { + federation_id: string; + federation_name: string; + welcome_message: string; + federation_expiry_timestamp: number; +}; -function AddFederationForm({ refetch }) { +function AddFederationForm(props: { refetch: () => void }) { const i18n = useI18n(); - const [state, actions] = useMegaStore(); + const [state, _actions] = useMegaStore(); const [error, setError] = createSignal(); const [success, setSuccess] = createSignal(""); - const [federationData, setFederationData] = createSignal({ federation_code: "" }); - const [isDirty, setIsDirty] = createSignal(false); - const [isValid, setIsValid] = createSignal(false); const [feedbackForm, { Form, Field }] = createForm({ initialValues: { @@ -53,52 +43,49 @@ function AddFederationForm({ refetch }) { } }); - const handleInputChange = (value) => { - setFederationData({ federation_code: value }); - setIsDirty(true); - validateForm(value); - }; - - const validateForm = (value) => { - const isValid = value.trim().length > 0; // Add more validation logic as needed - setIsValid(isValid); - }; - - -const handleSubmit: SubmitHandler = async (f: FederationForm) => { - try { - if (!isValid()) { - setError(new Error("Form is invalid")); - return; + const handleSubmit: SubmitHandler = async ( + f: FederationForm + ) => { + setSuccess(""); + setError(undefined); + try { + const federation_code = f.federation_code.trim(); + const newFederation = + await state.mutiny_wallet?.new_federation(federation_code); + console.log("New federation added:", newFederation); + setSuccess( + i18n.t("settings.manage_federations.federation_added_success") + ); + await props.refetch(); + } catch (e) { + console.error("Error submitting federation:", e); + setError(eify(e)); } - - const federation_code = federationData().federation_code.trim(); - const newFederation = await state.mutiny_wallet?.new_federation(federation_code); - console.log('New federation added:', newFederation); - setSuccess("Federation added successfully!"); - setFederationData({ federation_code: "" }); // Reset the form data - - // Now, refetch federations - console.log('Refetching federations...'); - await refetch(); - } catch (e) { - console.error('Error submitting federation:', e); - setError(eify(e)); - } -}; + }; return (
- + {(field, props) => ( handleInputChange(e.currentTarget.value)} + {...field} error={field.error} - label={i18n.t("settings.manage_federations.federation_code_label")} + label={i18n.t( + "settings.manage_federations.federation_code_label" + )} placeholder="fedi1..." + required /> )} @@ -110,7 +97,7 @@ const handleSubmit: SubmitHandler = async (f: FederationForm) => )} - +
No federations available.
@@ -162,16 +178,18 @@ function ListAndRemoveFederations({ federations, refetch }) { export function ManageFederations() { const i18n = useI18n(); - const [state, actions] = useMegaStore(); + const [state, _actions] = useMegaStore(); - const fetchFederations = async () => { + async function fetchFederations() { try { - return await state.mutiny_wallet?.list_federations() ?? []; + const result = + (await state.mutiny_wallet?.list_federations()) as MutinyFederationIdentity[]; + return result ?? []; } catch (e) { console.error(e); return []; } - }; + } const [federations, { refetch }] = createResource(fetchFederations); @@ -179,10 +197,18 @@ export function ManageFederations() { - - {i18n.t("settings.manage_federations.title")} - - + + + {i18n.t("settings.manage_federations.title")} + + +