auto refresh pending nwc

This commit is contained in:
Paul Miller
2023-07-12 12:39:35 -05:00
committed by Tony Giorgio
parent b2d9208a58
commit 3f36d5a475
2 changed files with 21 additions and 5 deletions

View File

@@ -68,9 +68,11 @@ export default function App() {
<ReloadPrompt /> <ReloadPrompt />
</Show> </Show>
<BalanceBox loading={state.wallet_loading} /> <BalanceBox loading={state.wallet_loading} />
<Show when={!state.wallet_loading}> <Suspense>
<PendingNwc /> <Show when={!state.wallet_loading}>
</Show> <PendingNwc />
</Show>
</Suspense>
<Card title="Activity"> <Card title="Activity">
<div class="p-1" /> <div class="p-1" />
<VStack> <VStack>

View File

@@ -19,6 +19,7 @@ import { ActivityAmount } from "./ActivityItem";
import { InfoBox } from "./InfoBox"; import { InfoBox } from "./InfoBox";
import eify from "~/utils/eify"; import eify from "~/utils/eify";
import { A } from "solid-start"; import { A } from "solid-start";
import { createDeepSignal } from "~/utils/deepSignal";
type PendingItem = { type PendingItem = {
id: string; id: string;
@@ -32,7 +33,7 @@ export function PendingNwc() {
const [error, setError] = createSignal<Error>(); const [error, setError] = createSignal<Error>();
const [pendingRequests, { refetch }] = createResource(async () => { async function fetchPendingRequests() {
const profiles: NwcProfile[] = const profiles: NwcProfile[] =
await state.mutiny_wallet?.get_nwc_profiles(); await state.mutiny_wallet?.get_nwc_profiles();
@@ -53,7 +54,13 @@ export function PendingNwc() {
} }
} }
return pendingItems; return pendingItems;
}); }
const [pendingRequests, { refetch }] = createResource(
fetchPendingRequests,
// Create deepsignal so we don't get flicker on refresh
{ storage: createDeepSignal }
);
const [paying, setPaying] = createSignal<string>(""); const [paying, setPaying] = createSignal<string>("");
@@ -93,6 +100,13 @@ export function PendingNwc() {
} }
}); });
createEffect(() => {
// Refetch on the sync interval
if (!state.is_syncing) {
refetch();
}
});
return ( return (
<Show when={pendingRequests() && pendingRequests()!.length > 0}> <Show when={pendingRequests() && pendingRequests()!.length > 0}>
<Card title="Pending Requests"> <Card title="Pending Requests">