Skip to content

Commit

Permalink
Display individual fedimint balances
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jan 22, 2024
1 parent d9ada68 commit c680ab2
Showing 1 changed file with 63 additions and 5 deletions.
68 changes: 63 additions & 5 deletions src/routes/settings/ManageFederations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import {
SubmitHandler
} from "@modular-forms/solid";
import { useSearchParams } from "@solidjs/router";
import { createSignal, For, onMount, Show } from "solid-js";
import {
createResource,
createSignal,
For,
Match,
onMount,
Show,
Suspense,
Switch
} from "solid-js";

import {
AmountSats,
BackLink,
Button,
ConfirmDialog,
Expand Down Expand Up @@ -130,7 +140,10 @@ function AddFederationForm() {
);
}

function FederationListItem(props: { fed: MutinyFederationIdentity }) {
function FederationListItem(props: {
fed: MutinyFederationIdentity;
balance?: bigint;
}) {
const i18n = useI18n();
const [state, actions] = useMegaStore();

Expand Down Expand Up @@ -165,6 +178,16 @@ function FederationListItem(props: { fed: MutinyFederationIdentity }) {
<Show when={props.fed.welcome_message}>
<p>{props.fed.welcome_message}</p>
</Show>
<Show when={props.balance !== undefined}>
<KeyValue
key={i18n.t("activity.transaction_details.balance")}
>
<AmountSats
amountSats={props.balance}
denominationSize={"sm"}
/>
</KeyValue>
</Show>
<Show when={props.fed.federation_expiry_timestamp}>
<KeyValue
key={i18n.t("settings.manage_federations.expires")}
Expand Down Expand Up @@ -201,6 +224,17 @@ export function ManageFederations() {
const i18n = useI18n();
const [state, _actions] = useMegaStore();

const [balances] = createResource(async () => {
try {
const balances =
await state.mutiny_wallet?.get_federation_balances();
return balances?.balances || [];
} catch (e) {
console.error(e);
return [];
}
});

return (
<MutinyWalletGuard>
<SafeArea>
Expand All @@ -220,9 +254,33 @@ export function ManageFederations() {
</NiceP>
<AddFederationForm />
<VStack>
<For each={state.federations ?? []}>
{(fed) => <FederationListItem fed={fed} />}
</For>
<Suspense>
<Switch>
<Match when={balances()}>
<For each={state.federations ?? []}>
{(fed) => (
<FederationListItem
fed={fed}
balance={
balances()?.find(
(b) =>
b.identity_federation_id ===
fed.federation_id
)?.balance
}
/>
)}
</For>
</Match>
<Match when={true}>
<For each={state.federations ?? []}>
{(fed) => (
<FederationListItem fed={fed} />
)}
</For>
</Match>
</Switch>
</Suspense>
</VStack>
</DefaultMain>
<NavBar activeTab="settings" />
Expand Down

0 comments on commit c680ab2

Please sign in to comment.