From 2d99da5245557780cab20066a7d6359dc12ccee7 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Mon, 5 Jun 2023 17:50:46 -0500 Subject: [PATCH] sync activity separately from regular sync --- src/components/Activity.tsx | 19 +- src/components/App.tsx | 14 +- src/components/layout/Button.tsx | 34 +-- src/components/layout/index.tsx | 16 +- src/components/waitlist/WaitlistAlreadyIn.tsx | 35 ++-- src/routes/Activity.tsx | 193 +++++++++++------- src/state/megaStore.tsx | 16 +- 7 files changed, 186 insertions(+), 141 deletions(-) diff --git a/src/components/Activity.tsx b/src/components/Activity.tsx index d83a8fa..32b5947 100644 --- a/src/components/Activity.tsx +++ b/src/components/Activity.tsx @@ -1,5 +1,5 @@ -import { LoadingSpinner, NiceP } from "./layout" -import { For, Match, Show, Switch, createSignal } from "solid-js"; +import { NiceP } from "./layout"; +import { For, Match, Show, Switch, createEffect, createSignal } from "solid-js"; import { useMegaStore } from "~/state/megaStore"; import { ActivityItem as MutinyActivity } from "@mutinywallet/mutiny-wasm"; import { ActivityItem, HackActivityType } from "./ActivityItem"; @@ -61,7 +61,7 @@ function UnifiedActivityItem(props: { } export function CombinedActivity(props: { limit?: number }) { - const [state, _actions] = useMegaStore(); + const [state, actions] = useMegaStore(); const [detailsOpen, setDetailsOpen] = createSignal(false); const [detailsKind, setDetailsKind] = createSignal(); @@ -75,6 +75,12 @@ export function CombinedActivity(props: { limit?: number }) { setDetailsOpen(true); } + createEffect(() => { + if (!state.wallet_loading && !state.is_syncing) { + actions.syncActivity(); + } + }); + return ( <> @@ -86,13 +92,8 @@ export function CombinedActivity(props: { limit?: number }) { /> - -
- -
-
-
+
Receive some sats to get started
diff --git a/src/components/App.tsx b/src/components/App.tsx index b5b54d6..c50b883 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -36,12 +36,14 @@ export default function App() { {/* View All */} - - View All - + 0}> + + View All + +

Bugs? Feedback?{" "} diff --git a/src/components/layout/Button.tsx b/src/components/layout/Button.tsx index f92e999..4bfa853 100644 --- a/src/components/layout/Button.tsx +++ b/src/components/layout/Button.tsx @@ -45,23 +45,23 @@ export const Button: ParentComponent = props => { const [local, attrs] = splitProps(props, ['children', 'intent', 'layout', 'class']) return ( - - ) + + ); } interface ButtonLinkProps extends JSX.ButtonHTMLAttributes, StyleProps { diff --git a/src/components/layout/index.tsx b/src/components/layout/index.tsx index cecbfe5..dc5ac8e 100644 --- a/src/components/layout/index.tsx +++ b/src/components/layout/index.tsx @@ -78,21 +78,19 @@ export const DefaultMain: ParentComponent = (props) => { export const FullscreenLoader = () => { return ( -

- -
+
+ +
); } export const MutinyWalletGuard: ParentComponent = (props) => { const [state, _] = useMegaStore(); return ( - }> - - {props.children} - - - ) + }> + {props.children} + + ); } export const LoadingSpinner = (props: { big?: boolean, wide?: boolean }) => { diff --git a/src/components/waitlist/WaitlistAlreadyIn.tsx b/src/components/waitlist/WaitlistAlreadyIn.tsx index 224d1db..6a4b4ea 100644 --- a/src/components/waitlist/WaitlistAlreadyIn.tsx +++ b/src/components/waitlist/WaitlistAlreadyIn.tsx @@ -35,20 +35,25 @@ export function WaitlistAlreadyIn() { const [posts] = createResource("", postsFetcher); return ( -
- - logo - -

You're on a list!

-

- We'll message you when Mutiny Wallet is ready. -

-
-

Recent Updates

-
}> - - -
- +
+ + logo + +

You're on a list!

+

We'll message you when Mutiny Wallet is ready.

+
+

Recent Updates

+ + +
+ } + > + + + +
); } diff --git a/src/routes/Activity.tsx b/src/routes/Activity.tsx index cafc490..68ddc4a 100644 --- a/src/routes/Activity.tsx +++ b/src/routes/Activity.tsx @@ -1,10 +1,19 @@ import { For, Show, createResource } from "solid-js"; import NavBar from "~/components/NavBar"; -import { Button, Card, DefaultMain, LargeHeader, NiceP, MutinyWalletGuard, SafeArea, VStack } from "~/components/layout"; +import { + Button, + Card, + DefaultMain, + LargeHeader, + NiceP, + MutinyWalletGuard, + SafeArea, + VStack +} from "~/components/layout"; import { BackLink } from "~/components/layout/BackLink"; import { CombinedActivity } from "~/components/Activity"; import { A } from "solid-start"; -import settings from '~/assets/icons/settings.svg'; +import settings from "~/assets/icons/settings.svg"; import { Tabs } from "@kobalte/core"; import { gradientsPerContact } from "~/utils/gradientHash"; import { ContactEditor } from "~/components/ContactEditor"; @@ -12,91 +21,117 @@ import { ContactFormValues, ContactViewer } from "~/components/ContactViewer"; import { useMegaStore } from "~/state/megaStore"; import { Contact } from "@mutinywallet/mutiny-wasm"; import { showToast } from "~/components/Toaster"; +import { LoadingShimmer } from "~/components/BalanceBox"; function ContactRow() { - const [state, _actions] = useMegaStore(); - const [contacts, { refetch }] = createResource(async () => { - const contacts = state.mutiny_wallet?.get_contacts(); - console.log(contacts) + const [state, _actions] = useMegaStore(); + const [contacts, { refetch }] = createResource(async () => { + const contacts = state.mutiny_wallet?.get_contacts(); + console.log(contacts); - // FIXME: this is just types shenanigans I believe - const c: Contact[] = [] - if (contacts) { - for (const contact in contacts) { - c.push(contacts[contact]) - } - } - return c || [] - }) - const [gradients] = createResource(contacts, gradientsPerContact); - - async function createContact(contact: ContactFormValues) { - // FIXME: npub not valid? other undefineds - const c = new Contact(contact.name, undefined, undefined, undefined); - await state.mutiny_wallet?.create_new_contact(c) - refetch(); + // FIXME: this is just types shenanigans I believe + const c: Contact[] = []; + if (contacts) { + for (const contact in contacts) { + c.push(contacts[contact]); + } } + return c || []; + }); + const [gradients] = createResource(contacts, gradientsPerContact); - // - async function saveContact(_contact: ContactFormValues) { - showToast(new Error("Unimplemented")) - // await editContact(contact) - refetch(); - } + async function createContact(contact: ContactFormValues) { + // FIXME: npub not valid? other undefineds + const c = new Contact(contact.name, undefined, undefined, undefined); + await state.mutiny_wallet?.create_new_contact(c); + refetch(); + } - return ( -
- - -
- - {(contact) => ( - - )} - -
-
+ // + async function saveContact(_contact: ContactFormValues) { + showToast(new Error("Unimplemented")); + // await editContact(contact) + refetch(); + } + + return ( +
+ + +
+ + {(contact) => ( + + )} +
- ) +
+
+ ); } -const TAB = "flex-1 inline-block px-8 py-4 text-lg font-semibold rounded-lg ui-selected:bg-white/10 bg-neutral-950 hover:bg-white/10" +const TAB = + "flex-1 inline-block px-8 py-4 text-lg font-semibold rounded-lg ui-selected:bg-white/10 bg-neutral-950 hover:bg-white/10"; export default function Activity() { - return ( - - - - - Settings}>Activity - - - - Mutiny - Nostr - {/* */} - - - {/* */} - -
- - - - - - - -
- Import your contacts from nostr to see who they're zapping. - -
-
-
- - - - - - ) -} \ No newline at end of file + const [state, _actions] = useMegaStore(); + return ( + + + + + + Settings + + } + > + Activity + + + + + + Mutiny + + + Nostr + + {/* */} + + + {/* */} + +
+ + }> + + + + + + + +
+ Import your contacts from nostr to see who they're zapping. + +
+
+
+ + + + + + ); +} diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index 1c0f29e..3e4b96d 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -33,7 +33,6 @@ export type MegaStore = [ wallet_loading: boolean; nwc_enabled: boolean; activity: MutinyActivity[]; - activity_has_loaded: boolean; }, { fetchUserStatus(): Promise; @@ -46,6 +45,7 @@ export type MegaStore = [ setHasBackedUp(): void; listTags(): Promise; setNwc(enabled: boolean): void; + syncActivity(): Promise; } ]; @@ -67,8 +67,7 @@ export const Provider: ParentComponent = (props) => { dismissed_restore_prompt: localStorage.getItem("dismissed_restore_prompt") === "true", wallet_loading: true, nwc_enabled: localStorage.getItem("nwc_enabled") === "true", - activity: [] as MutinyActivity[], - activity_has_loaded: false + activity: [] as MutinyActivity[] }); const actions = { @@ -135,14 +134,11 @@ export const Provider: ParentComponent = (props) => { setState({ is_syncing: true }); const newBalance = await state.mutiny_wallet?.get_balance(); const price = await state.mutiny_wallet?.get_bitcoin_price(); - const activity = await state.mutiny_wallet?.get_activity(); setState({ balance: newBalance, last_sync: Date.now(), price: price || 0 }); - setState("activity", reconcile(activity, { merge: true })); - setState({ activity_has_loaded: true }); } } catch (e) { console.error(e); @@ -150,6 +146,14 @@ export const Provider: ParentComponent = (props) => { setState({ is_syncing: false }); } }, + async syncActivity(): Promise { + try { + const activity = await state.mutiny_wallet?.get_activity(); + setState("activity", reconcile(activity, { merge: true })); + } catch (e) { + console.error(e); + } + }, setScanResult(scan_result: ParsedParams) { setState({ scan_result }); },