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

Commit 780ef12

Browse files
committed
requests
1 parent de3bdef commit 780ef12

File tree

7 files changed

+169
-9
lines changed

7 files changed

+169
-9
lines changed

src/components/layout/Misc.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ export const LargeHeader: ParentComponent<{
208208
}> = (props) => {
209209
return (
210210
<header
211-
class="mb-2 mt-4 flex w-full items-center justify-between"
211+
class="mb-2 mt-2 flex w-full items-center justify-between"
212212
classList={{
213213
"justify-between": !props.centered,
214214
"justify-center": props.centered
215215
}}
216216
>
217217
<h1
218-
class="text-3xl font-semibold"
218+
class="text-2xl font-semibold"
219219
classList={{
220220
"text-center": props.centered
221221
}}

src/i18n/en/translations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export default {
4747
error_ln_address_missing: "New contacts need a lightning address",
4848
npub: "Nostr Npub"
4949
},
50+
request: {
51+
request_bitcoin: "Request Bitcoin",
52+
request: "Request"
53+
},
5054
receive: {
5155
receive_bitcoin: "Receive Bitcoin",
5256
edit: "Edit",

src/router.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
OldMain,
2424
Profile,
2525
Receive,
26+
RequestRoute,
2627
Scanner,
2728
Search,
2829
Send,
@@ -135,6 +136,7 @@ export function Router() {
135136
<Route path="/feedback" component={Feedback} />
136137
<Route path="/gift" component={GiftReceive} />
137138
<Route path="/receive" component={Receive} />
139+
<Route path="/request/:id" component={RequestRoute} />
138140
<Route path="/scanner" component={Scanner} />
139141
<Route path="/send" component={Send} />
140142
<Route path="/swap" component={Swap} />

src/routes/Chat.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export function Chat() {
195195
const activity = await state.mutiny_wallet?.get_label_activity(
196196
params.id
197197
);
198+
console.log("activity", activity);
198199
const convo = await state.mutiny_wallet?.get_dm_conversation(
199200
// Mutinynet npub, for testing
200201
// "npub1qf8e8cvfp60ywrah984zgsn8veggcrsv2cvttdr47tgz05ypf5yszwx308",
@@ -218,8 +219,6 @@ export function Chat() {
218219
}))
219220
];
220221

221-
console.log("combined presort", combined);
222-
223222
combined.sort((a, b) => {
224223
const a_date =
225224
a.kind === "message"
@@ -232,8 +231,6 @@ export function Chat() {
232231
return b_date - a_date;
233232
});
234233

235-
console.log("combined sorted", combined);
236-
237234
return combined as CombinedMessagesAndActivity[];
238235

239236
// return combined as FakeDirectMessage[];
@@ -293,7 +290,6 @@ export function Chat() {
293290
});
294291

295292
function sendToContact(contact?: TagItem) {
296-
console.log("contact:", contact);
297293
if (!contact) return;
298294
const address = contact.ln_address || contact.lnurl;
299295
if (address) {
@@ -315,6 +311,15 @@ export function Chat() {
315311
}
316312
}
317313

314+
function requestFromContact(contact?: TagItem) {
315+
if (!contact) return;
316+
navigate("/request/" + contact.id, {
317+
state: {
318+
previous: "/chat/" + params.id
319+
}
320+
});
321+
}
322+
318323
const navigate = useNavigate();
319324

320325
function navWithContactId() {
@@ -437,7 +442,11 @@ export function Chat() {
437442
height={"24px"}
438443
/>
439444
</button>
440-
<button>
445+
<button
446+
onClick={() =>
447+
requestFromContact(contact()!)
448+
}
449+
>
441450
<img
442451
src={receive}
443452
width={"24px"}

src/routes/Request.tsx

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/* @refresh skip */
2+
3+
import { useNavigate, useParams } from "@solidjs/router";
4+
import { createResource, createSignal, Suspense } from "solid-js";
5+
6+
import {
7+
AmountEditable,
8+
BackButton,
9+
Button,
10+
DefaultMain,
11+
LabelCircle,
12+
LargeHeader,
13+
MutinyWalletGuard,
14+
NavBar,
15+
ReceiveWarnings,
16+
showToast,
17+
SimpleInput,
18+
VStack
19+
} from "~/components";
20+
import { useI18n } from "~/i18n/context";
21+
import { useMegaStore } from "~/state/megaStore";
22+
import { eify } from "~/utils";
23+
24+
import { DestinationItem } from "./Send";
25+
26+
export function RequestRoute() {
27+
const [state, actions] = useMegaStore();
28+
const navigate = useNavigate();
29+
const i18n = useI18n();
30+
31+
const params = useParams();
32+
33+
const [amount, setAmount] = createSignal<bigint>(0n);
34+
const [whatForInput, setWhatForInput] = createSignal("");
35+
36+
const [loading, setLoading] = createSignal(false);
37+
38+
function handleBack() {}
39+
40+
async function handleSubmit() {
41+
setLoading(true);
42+
console.log("requesting", amount(), whatForInput());
43+
try {
44+
const npub = contact()?.npub;
45+
if (!npub) throw new Error("Contact doesn't have a npub");
46+
47+
const tags = params.id ? [params.id] : [];
48+
49+
if (whatForInput()) {
50+
tags.push(whatForInput().trim());
51+
}
52+
53+
const raw = await state.mutiny_wallet?.create_bip21(amount(), tags);
54+
55+
if (!raw || !raw.invoice)
56+
throw new Error("Invoice creation failed");
57+
58+
await state.mutiny_wallet?.send_dm(npub, raw.invoice);
59+
60+
navigate("/chat/" + params.id);
61+
} catch (e) {
62+
console.error(e);
63+
showToast(eify(e));
64+
}
65+
setLoading(false);
66+
}
67+
68+
async function getContact(id: string) {
69+
console.log("fetching contact", id);
70+
try {
71+
const contact = state.mutiny_wallet?.get_tag_item(id);
72+
console.log("fetching contact", contact);
73+
// This shouldn't happen
74+
if (!contact) throw new Error("Contact not found");
75+
return contact;
76+
} catch (e) {
77+
console.error(e);
78+
showToast(eify(e));
79+
}
80+
}
81+
82+
const [contact] = createResource(() => params.id, getContact);
83+
84+
return (
85+
<MutinyWalletGuard>
86+
<DefaultMain>
87+
<BackButton onClick={handleBack} showOnDesktop />
88+
<LargeHeader>{i18n.t("request.request_bitcoin")}</LargeHeader>
89+
<Suspense>
90+
<DestinationItem
91+
title={contact()?.name || ""}
92+
value={contact()?.ln_address}
93+
icon={
94+
<LabelCircle
95+
name={contact()?.name || ""}
96+
image_url={contact()?.image_url}
97+
contact
98+
label={false}
99+
/>
100+
}
101+
/>
102+
</Suspense>
103+
<div class="flex-1" />
104+
<VStack>
105+
<AmountEditable
106+
initialAmountSats={amount() || "0"}
107+
setAmountSats={setAmount}
108+
onSubmit={handleSubmit}
109+
/>
110+
<ReceiveWarnings amountSats={amount() || "0"} />
111+
</VStack>
112+
<div class="flex-1" />
113+
<VStack>
114+
<form
115+
onSubmit={async (e) => {
116+
e.preventDefault();
117+
if (amount() > BigInt(0)) {
118+
await handleSubmit();
119+
}
120+
}}
121+
>
122+
<SimpleInput
123+
type="text"
124+
value={whatForInput()}
125+
placeholder={i18n.t("receive.what_for")}
126+
onInput={(e) =>
127+
setWhatForInput(e.currentTarget.value)
128+
}
129+
/>
130+
</form>
131+
<Button
132+
disabled={!amount()}
133+
intent="green"
134+
onClick={handleSubmit}
135+
loading={loading()}
136+
>
137+
{i18n.t("request.request")}
138+
</Button>
139+
</VStack>
140+
</DefaultMain>
141+
<NavBar activeTab="receive" />
142+
</MutinyWalletGuard>
143+
);
144+
}

src/routes/Send.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function DestinationShower(props: {
185185
);
186186
}
187187

188-
function DestinationItem(props: {
188+
export function DestinationItem(props: {
189189
title: string;
190190
value: JSX.Element;
191191
icon: JSX.Element;

src/routes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * from "./Profile";
1313
export * from "./Chat";
1414
export * from "./Setup";
1515
export * from "./NewProfile";
16+
export * from "./Request";

0 commit comments

Comments
 (0)