Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit ea7179c

Browse files
committed
refactor for no reason
1 parent 80dd622 commit ea7179c

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

src/routes/Chat.tsx

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/* refresh skip */
22

33
import { TagItem } from "@mutinywallet/mutiny-wasm";
4-
import { useNavigate, useParams } from "@solidjs/router";
4+
import {
5+
cache,
6+
createAsync,
7+
revalidate,
8+
useNavigate,
9+
useParams
10+
} from "@solidjs/router";
511
import {
612
createEffect,
713
createResource,
@@ -57,39 +63,44 @@ function SingleMessage(props: {
5763
const network = state.mutiny_wallet?.get_network() || "signet";
5864
const navigate = useNavigate();
5965

60-
const [parsed] = createResource(async () => {
61-
const result = toParsedParams(props.dm.message, network);
66+
const parsed = createAsync(
67+
async () => {
68+
const result = toParsedParams(props.dm.message, network);
6269

63-
if (!result.ok) {
64-
return undefined;
65-
}
70+
if (!result.ok) {
71+
return undefined;
72+
}
6673

67-
if (result.value?.invoice) {
68-
try {
69-
const alreadyPaid = await state.mutiny_wallet?.get_invoice(
70-
result.value.invoice
71-
);
72-
if (alreadyPaid?.paid) {
73-
return {
74-
type: "invoice",
75-
status: "paid",
76-
value: result.value.invoice,
77-
amount: result.value.amount_sats
78-
};
74+
if (result.value?.invoice) {
75+
try {
76+
const alreadyPaid = await state.mutiny_wallet?.get_invoice(
77+
result.value.invoice
78+
);
79+
if (alreadyPaid?.paid) {
80+
return {
81+
type: "invoice",
82+
status: "paid",
83+
value: result.value.invoice,
84+
amount: result.value.amount_sats
85+
};
86+
}
87+
} catch (e) {
88+
// No invoice found, no worries
7989
}
80-
} catch (e) {
81-
// No invoice found, no worries
82-
}
8390

84-
return {
85-
type: "invoice",
86-
status: "unpaid",
87-
from: props.dm.from,
88-
value: result.value.invoice,
89-
amount: result.value.amount_sats
90-
};
91+
return {
92+
type: "invoice",
93+
status: "unpaid",
94+
from: props.dm.from,
95+
value: result.value.invoice,
96+
amount: result.value.amount_sats
97+
};
98+
}
99+
},
100+
{
101+
initialValue: undefined
91102
}
92-
});
103+
);
93104

94105
function navWithContactId() {
95106
navigate("/send", {
@@ -178,8 +189,8 @@ export function Chat() {
178189
const [messageValue, setMessageValue] = createSignal("");
179190
const [sending, setSending] = createSignal(false);
180191

181-
const [contact] = createResource(async () => {
182-
return await state.mutiny_wallet?.get_tag_item(params.id);
192+
const contact = createAsync(async () => {
193+
return state.mutiny_wallet?.get_tag_item(params.id);
183194
});
184195

185196
const [convo, { refetch }] = createResource(
@@ -237,18 +248,15 @@ export function Chat() {
237248
return b_time - a_time;
238249
});
239250

240-
return combined as CombinedMessagesAndActivity[];
251+
return combined.reverse() as CombinedMessagesAndActivity[];
241252

242253
// return combined as FakeDirectMessage[];
243254
return [];
244255
} catch (e) {
245256
console.error("error getting convo:", e);
246-
return undefined;
257+
return [];
247258
}
248259
}
249-
// {
250-
// storage: createDeepSignal
251-
// }
252260
);
253261

254262
async function sendMessage() {
@@ -407,7 +415,7 @@ export function Chat() {
407415
<Suspense>
408416
<Show when={contact()}>
409417
<Suspense fallback={<LoadingShimmer />}>
410-
<For each={convo.latest?.reverse()}>
418+
<For each={convo.latest}>
411419
{(combined) => (
412420
<>
413421
<Show

0 commit comments

Comments
 (0)