Skip to content

Commit

Permalink
auto refresh pending nwc
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul authored and AnthonyRonning committed Jul 12, 2023
1 parent b2d9208 commit 3f36d5a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ export default function App() {
<ReloadPrompt />
</Show>
<BalanceBox loading={state.wallet_loading} />
<Show when={!state.wallet_loading}>
<PendingNwc />
</Show>
<Suspense>
<Show when={!state.wallet_loading}>
<PendingNwc />
</Show>
</Suspense>
<Card title="Activity">
<div class="p-1" />
<VStack>
Expand Down
18 changes: 16 additions & 2 deletions src/components/PendingNwc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ActivityAmount } from "./ActivityItem";
import { InfoBox } from "./InfoBox";
import eify from "~/utils/eify";
import { A } from "solid-start";
import { createDeepSignal } from "~/utils/deepSignal";

type PendingItem = {
id: string;
Expand All @@ -32,7 +33,7 @@ export function PendingNwc() {

const [error, setError] = createSignal<Error>();

const [pendingRequests, { refetch }] = createResource(async () => {
async function fetchPendingRequests() {
const profiles: NwcProfile[] =
await state.mutiny_wallet?.get_nwc_profiles();

Expand All @@ -53,7 +54,13 @@ export function PendingNwc() {
}
}
return pendingItems;
});
}

const [pendingRequests, { refetch }] = createResource(
fetchPendingRequests,
// Create deepsignal so we don't get flicker on refresh
{ storage: createDeepSignal }
);

const [paying, setPaying] = createSignal<string>("");

Expand Down Expand Up @@ -93,6 +100,13 @@ export function PendingNwc() {
}
});

createEffect(() => {
// Refetch on the sync interval
if (!state.is_syncing) {
refetch();
}
});

return (
<Show when={pendingRequests() && pendingRequests()!.length > 0}>
<Card title="Pending Requests">
Expand Down

0 comments on commit 3f36d5a

Please sign in to comment.