mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-02-10 08:44:20 +01:00
cleanup and refactor
This commit is contained in:
committed by
Tony Giorgio
parent
9c630a9468
commit
6dcdbae4bc
@@ -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 (
|
||||
<>
|
||||
<FancyCard>
|
||||
@@ -103,43 +91,11 @@ export function BalanceBox(props: { loading?: boolean }) {
|
||||
</Match>
|
||||
</Switch>
|
||||
</Show>
|
||||
|
||||
<Show when={federations.latest && federations().length}>
|
||||
<hr class="my-2 border-m-grey-750" />
|
||||
<Show when={!props.loading} fallback={<LoadingShimmer />}>
|
||||
<Switch>
|
||||
<Match when={state.safe_mode}>
|
||||
<div class="flex flex-col gap-1">
|
||||
<InfoBox accent="red">
|
||||
{i18n.t("common.error_safe_mode")}
|
||||
</InfoBox>
|
||||
</div>
|
||||
</Match>
|
||||
<Match when={true}>
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="text-2xl">
|
||||
<AmountSats
|
||||
amountSats={
|
||||
state.balance?.federation || 0
|
||||
}
|
||||
icon="community"
|
||||
denominationSize="lg"
|
||||
/>
|
||||
</div>
|
||||
<div class="text-lg text-white/70">
|
||||
<AmountFiat
|
||||
amountSats={
|
||||
state.balance?.federation || 0n
|
||||
}
|
||||
denominationSize="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Match>
|
||||
</Switch>
|
||||
</Show>
|
||||
<Show when={!props.loading && !state.safe_mode}>
|
||||
<Suspense>
|
||||
<FederationsBalance />
|
||||
</Suspense>
|
||||
</Show>
|
||||
|
||||
<hr class="my-2 border-m-grey-750" />
|
||||
<Show when={!props.loading} fallback={<LoadingShimmer />}>
|
||||
<div class="flex justify-between">
|
||||
@@ -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 (
|
||||
<Show when={federations() && federations().length}>
|
||||
<hr class="my-2 border-m-grey-750" />
|
||||
<Switch>
|
||||
<Match when={true}>
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="text-2xl">
|
||||
<AmountSats
|
||||
amountSats={state.balance?.federation || 0}
|
||||
icon="community"
|
||||
denominationSize="lg"
|
||||
/>
|
||||
</div>
|
||||
<div class="text-lg text-white/70">
|
||||
<AmountFiat
|
||||
amountSats={state.balance?.federation || 0n}
|
||||
denominationSize="sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Match>
|
||||
</Switch>
|
||||
</Show>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user