Skip to content

Commit

Permalink
bolt12
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Oct 25, 2023
1 parent 57df13a commit 766bf81
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 17 deletions.
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.25",
"@mutinywallet/waila-wasm": "^0.2.1",
"@mutinywallet/mutiny-wasm": "^0.4.24",
"@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
24 changes: 12 additions & 12 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
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

0 comments on commit 766bf81

Please sign in to comment.