|
1 | 1 | /* refresh skip */
|
2 | 2 |
|
3 | 3 | 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"; |
5 | 11 | import {
|
6 | 12 | createEffect,
|
7 | 13 | createResource,
|
@@ -57,39 +63,44 @@ function SingleMessage(props: {
|
57 | 63 | const network = state.mutiny_wallet?.get_network() || "signet";
|
58 | 64 | const navigate = useNavigate();
|
59 | 65 |
|
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); |
62 | 69 |
|
63 |
| - if (!result.ok) { |
64 |
| - return undefined; |
65 |
| - } |
| 70 | + if (!result.ok) { |
| 71 | + return undefined; |
| 72 | + } |
66 | 73 |
|
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 |
79 | 89 | }
|
80 |
| - } catch (e) { |
81 |
| - // No invoice found, no worries |
82 |
| - } |
83 | 90 |
|
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 |
91 | 102 | }
|
92 |
| - }); |
| 103 | + ); |
93 | 104 |
|
94 | 105 | function navWithContactId() {
|
95 | 106 | navigate("/send", {
|
@@ -178,8 +189,8 @@ export function Chat() {
|
178 | 189 | const [messageValue, setMessageValue] = createSignal("");
|
179 | 190 | const [sending, setSending] = createSignal(false);
|
180 | 191 |
|
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); |
183 | 194 | });
|
184 | 195 |
|
185 | 196 | const [convo, { refetch }] = createResource(
|
@@ -237,18 +248,15 @@ export function Chat() {
|
237 | 248 | return b_time - a_time;
|
238 | 249 | });
|
239 | 250 |
|
240 |
| - return combined as CombinedMessagesAndActivity[]; |
| 251 | + return combined.reverse() as CombinedMessagesAndActivity[]; |
241 | 252 |
|
242 | 253 | // return combined as FakeDirectMessage[];
|
243 | 254 | return [];
|
244 | 255 | } catch (e) {
|
245 | 256 | console.error("error getting convo:", e);
|
246 |
| - return undefined; |
| 257 | + return []; |
247 | 258 | }
|
248 | 259 | }
|
249 |
| - // { |
250 |
| - // storage: createDeepSignal |
251 |
| - // } |
252 | 260 | );
|
253 | 261 |
|
254 | 262 | async function sendMessage() {
|
@@ -407,7 +415,7 @@ export function Chat() {
|
407 | 415 | <Suspense>
|
408 | 416 | <Show when={contact()}>
|
409 | 417 | <Suspense fallback={<LoadingShimmer />}>
|
410 |
| - <For each={convo.latest?.reverse()}> |
| 418 | + <For each={convo.latest}> |
411 | 419 | {(combined) => (
|
412 | 420 | <>
|
413 | 421 | <Show
|
|
0 commit comments