Skip to content

Commit

Permalink
refactor for no reason
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Jan 30, 2024
1 parent 80dd622 commit ea7179c
Showing 1 changed file with 45 additions and 37 deletions.
82 changes: 45 additions & 37 deletions src/routes/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/* refresh skip */

import { TagItem } from "@mutinywallet/mutiny-wasm";
import { useNavigate, useParams } from "@solidjs/router";
import {
cache,
createAsync,
revalidate,
useNavigate,
useParams
} from "@solidjs/router";
import {
createEffect,
createResource,
Expand Down Expand Up @@ -57,39 +63,44 @@ function SingleMessage(props: {
const network = state.mutiny_wallet?.get_network() || "signet";
const navigate = useNavigate();

const [parsed] = createResource(async () => {
const result = toParsedParams(props.dm.message, network);
const parsed = createAsync(
async () => {
const result = toParsedParams(props.dm.message, network);

if (!result.ok) {
return undefined;
}
if (!result.ok) {
return undefined;
}

if (result.value?.invoice) {
try {
const alreadyPaid = await state.mutiny_wallet?.get_invoice(
result.value.invoice
);
if (alreadyPaid?.paid) {
return {
type: "invoice",
status: "paid",
value: result.value.invoice,
amount: result.value.amount_sats
};
if (result.value?.invoice) {
try {
const alreadyPaid = await state.mutiny_wallet?.get_invoice(
result.value.invoice
);
if (alreadyPaid?.paid) {
return {
type: "invoice",
status: "paid",
value: result.value.invoice,
amount: result.value.amount_sats
};
}
} catch (e) {
// No invoice found, no worries
}
} catch (e) {
// No invoice found, no worries
}

return {
type: "invoice",
status: "unpaid",
from: props.dm.from,
value: result.value.invoice,
amount: result.value.amount_sats
};
return {
type: "invoice",
status: "unpaid",
from: props.dm.from,
value: result.value.invoice,
amount: result.value.amount_sats
};
}
},
{
initialValue: undefined
}
});
);

function navWithContactId() {
navigate("/send", {
Expand Down Expand Up @@ -178,8 +189,8 @@ export function Chat() {
const [messageValue, setMessageValue] = createSignal("");
const [sending, setSending] = createSignal(false);

const [contact] = createResource(async () => {
return await state.mutiny_wallet?.get_tag_item(params.id);
const contact = createAsync(async () => {
return state.mutiny_wallet?.get_tag_item(params.id);
});

const [convo, { refetch }] = createResource(
Expand Down Expand Up @@ -237,18 +248,15 @@ export function Chat() {
return b_time - a_time;
});

return combined as CombinedMessagesAndActivity[];
return combined.reverse() as CombinedMessagesAndActivity[];

// return combined as FakeDirectMessage[];
return [];
} catch (e) {
console.error("error getting convo:", e);
return undefined;
return [];
}
}
// {
// storage: createDeepSignal
// }
);

async function sendMessage() {
Expand Down Expand Up @@ -407,7 +415,7 @@ export function Chat() {
<Suspense>
<Show when={contact()}>
<Suspense fallback={<LoadingShimmer />}>
<For each={convo.latest?.reverse()}>
<For each={convo.latest}>
{(combined) => (
<>
<Show
Expand Down

0 comments on commit ea7179c

Please sign in to comment.