Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
"@capacitor/clipboard": "^5.0.6",
"@capacitor/core": "^5.2.2",
"@capacitor/filesystem": "^5.1.4",
"@capacitor/share": "^5.0.6",
"@capacitor/haptics": "^5.0.6",
"@capacitor/share": "^5.0.6",
"@capacitor/toast": "^5.0.6",
"@kobalte/core": "^0.9.8",
"@kobalte/tailwindcss": "^0.5.0",
"@modular-forms/solid": "^0.18.1",
"@mutinywallet/barcode-scanner": "5.0.0-beta.3",
"@mutinywallet/mutiny-wasm": "0.4.26",
"@mutinywallet/waila-wasm": "^0.2.1",
"@mutinywallet/mutiny-wasm": "^0.4.25",
"@mutinywallet/waila-wasm": "0.2.4",
"@nostr-dev-kit/ndk": "^0.8.11",
"@solid-primitives/upload": "^0.0.111",
"@solid-primitives/websocket": "^1.1.0",
Expand Down
12 changes: 4 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/logic/waila.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import initWaila, { PaymentParams } from "@mutinywallet/waila-wasm";

import { Result } from "~/utils";

// Make sure we've initialzied waila before we try to use it
// Make sure we've initialized waila before we try to use it
await initWaila();

export type ParsedParams = {
address?: string;
invoice?: string;
offer?: string;
amount_sats?: bigint;
network?: string;
memo?: string;
Expand Down Expand Up @@ -50,6 +51,7 @@ export function toParsedParams(
value: {
address: params.address,
invoice: params.invoice,
offer: params.offer,
amount_sats: params.amount_sats,
network,
memo: params.memo,
Expand Down
23 changes: 21 additions & 2 deletions src/routes/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default function Receive() {
const [amount, setAmount] = createSignal("");
const [receiveState, setReceiveState] = createSignal<ReceiveState>("edit");
const [bip21Raw, setBip21Raw] = createSignal<MutinyBip21RawMaterials>();
const [bolt12, setBolt12] = createSignal("");
const [unified, setUnified] = createSignal("");
const [shouldShowAmountEditor, setShouldShowAmountEditor] =
createSignal(true);
Expand Down Expand Up @@ -157,6 +158,11 @@ export default function Receive() {
value: "onchain",
label: i18n.t("receive.onchain_label"),
caption: i18n.t("receive.onchain_caption")
},
{
value: "bolt12",
label: "Bolt12",
caption: "Try the future of Lightning payments"
}
];

Expand All @@ -170,6 +176,8 @@ export default function Receive() {
return bip21Raw()?.invoice ?? "";
} else if (flavor() === "onchain") {
return bip21Raw()?.address ?? "";
} else if (flavor() === "bolt12") {
return bolt12() ?? "";
}
}
});
Expand Down Expand Up @@ -336,11 +344,22 @@ export default function Receive() {
}
}

function selectFlavor(flavor: string) {
async function selectFlavor(flavor: string) {
setFlavor(flavor as ReceiveFlavor);
if (rememberChoice()) {
if (rememberChoice() && flavor !== "bolt12") {
actions.setPreferredInvoiceType(flavor as ReceiveFlavor);
}
if (flavor === "bolt12") {
const nodes = await state.mutiny_wallet?.list_nodes();
const firstNode = (nodes[0] as string) || "";
const offer = await state.mutiny_wallet?.create_offer(firstNode, amount(), [])
if (offer) {
setBolt12(offer);
} else {
console.log("error creating offer");
}
}

setMethodChooserOpen(false);
}

Expand Down
36 changes: 35 additions & 1 deletion src/routes/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function DestinationShower(props: {
description?: string;
address?: string;
invoice?: MutinyInvoice;
offer?: string;
nodePubkey?: string;
lnurl?: string;
clearAll: () => void;
Expand All @@ -187,6 +188,9 @@ function DestinationShower(props: {
<Match when={props.invoice && props.source === "lightning"}>
<StringShower text={props.invoice?.bolt11 || ""} />
</Match>
<Match when={props.offer && props.source === "lightning"}>
<StringShower text={props.offer || ""} />
</Match>
<Match when={props.nodePubkey && props.source === "lightning"}>
<StringShower text={props.nodePubkey || ""} />
</Match>
Expand All @@ -213,6 +217,7 @@ export default function Send() {

// These can only be derived from the "destination" signal
const [invoice, setInvoice] = createSignal<MutinyInvoice>();
const [offer, setOffer] = createSignal<string>();
const [nodePubkey, setNodePubkey] = createSignal<string>();
const [lnurlp, setLnurlp] = createSignal<string>();
const [address, setAddress] = createSignal<string>();
Expand All @@ -236,6 +241,7 @@ export default function Send() {
setIsAmtEditable(true);
setSource("lightning");
setInvoice(undefined);
setOffer(undefined);
setAddress(undefined);
setDescription(undefined);
setNodePubkey(undefined);
Expand Down Expand Up @@ -346,6 +352,13 @@ export default function Send() {
setInvoice(invoice);
setSource("lightning");
});
} else if (source.offer) {
if (source.amount_sats) {
setAmountSats(source.amount_sats)
setIsAmtEditable(false);
}
setOffer(source.offer);
setSource("lightning");
} else if (source.node_pubkey) {
setAmountSats(source.amount_sats || 0n);
setNodePubkey(source.node_pubkey);
Expand Down Expand Up @@ -489,6 +502,24 @@ export default function Send() {
sentDetails.amount = amountSats();
sentDetails.fee_estimate = payment?.fees_paid || 0;
}
} else if (source() === "lightning" && offer()) {
const nodes = await state.mutiny_wallet?.list_nodes();
const firstNode = (nodes[0] as string) || "";
const payment = await state.mutiny_wallet?.pay_offer(
firstNode,
offer()!,
amountSats(),
undefined,
undefined, // todo add optional payer message
tags
);

if (!payment?.paid) {
throw new Error(i18n.t("send.error_keysend"));
} else {
sentDetails.amount = amountSats();
sentDetails.fee_estimate = payment?.fees_paid || 0;
}
} else if (source() === "lightning" && nodePubkey()) {
const nodes = await state.mutiny_wallet?.list_nodes();
const firstNode = (nodes[0] as string) || "";
Expand Down Expand Up @@ -576,7 +607,7 @@ export default function Send() {
<DefaultMain>
<Show
when={
address() || invoice() || nodePubkey() || lnurlp()
address() || invoice() || offer() || nodePubkey() || lnurlp()
}
fallback={<BackLink />}
>
Expand Down Expand Up @@ -657,6 +688,7 @@ export default function Send() {
when={
address() ||
invoice() ||
offer() ||
nodePubkey() ||
lnurlp()
}
Expand All @@ -672,6 +704,7 @@ export default function Send() {
source={source()}
description={description()}
invoice={invoice()}
offer={offer()}
address={address()}
nodePubkey={nodePubkey()}
lnurl={lnurlp()}
Expand Down Expand Up @@ -720,6 +753,7 @@ export default function Send() {
when={
address() ||
invoice() ||
offer() ||
nodePubkey() ||
lnurlp()
}
Expand Down
1 change: 1 addition & 0 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export const Provider: ParentComponent = (props) => {
if (
result.value?.address ||
result.value?.invoice ||
result.value?.offer ||
result.value?.node_pubkey ||
result.value?.lnurl
) {
Expand Down