From 648dad4126811aafe57af64b6ecc6347c2e0f525 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Wed, 25 Oct 2023 00:55:37 -0500 Subject: [PATCH] bolt12 --- package.json | 6 +++--- pnpm-lock.yaml | 12 ++++-------- src/logic/waila.ts | 4 +++- src/routes/Receive.tsx | 23 +++++++++++++++++++++-- src/routes/Send.tsx | 36 +++++++++++++++++++++++++++++++++++- src/state/megaStore.tsx | 1 + 6 files changed, 67 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index b1116e4b..ae7772a8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1ceb515c..8d0b83b3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,9 +1,5 @@ lockfileVersion: '6.0' -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false - importers: .: @@ -51,8 +47,8 @@ importers: specifier: 0.4.26 version: 0.4.26 '@mutinywallet/waila-wasm': - specifier: ^0.2.1 - version: 0.2.1 + specifier: 0.2.4 + version: 0.2.4 '@nostr-dev-kit/ndk': specifier: ^0.8.11 version: 0.8.11(eslint-import-resolver-typescript@2.7.1)(typescript@5.1.6) @@ -2523,8 +2519,8 @@ packages: resolution: {integrity: sha512-iPummhYwOKLvbeU/BJq2xQFNo0Worl47zxgX1Yn2ZFSgD0x4CYuB4C3cN0TEbnGvqEtHw/oAuDg5Ri/Li8wA/g==} dev: false - /@mutinywallet/waila-wasm@0.2.1: - resolution: {integrity: sha512-D//LCPB+dUOkmVWXLR4IA7tR/3odIoGhbwSiWBAlxqclegZMfWIdGdupYf9Yc16H18l/1cR3MXKvVwUkfSsj5g==} + /@mutinywallet/waila-wasm@0.2.4: + resolution: {integrity: sha512-wd4+Pht5GFP7jHFYA6T6Q9lZFOKfAFjEW2n6HPa6cqOK+SFbUTbrDn4GHwLQm6vDvQ48m0rV08CkyFvGFCWiOw==} dev: false /@ndelangen/get-tarball@3.0.9: diff --git a/src/logic/waila.ts b/src/logic/waila.ts index 01329f64..b345c3c4 100644 --- a/src/logic/waila.ts +++ b/src/logic/waila.ts @@ -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; @@ -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, diff --git a/src/routes/Receive.tsx b/src/routes/Receive.tsx index 931c9e79..995c3b0c 100644 --- a/src/routes/Receive.tsx +++ b/src/routes/Receive.tsx @@ -118,6 +118,7 @@ export default function Receive() { const [amount, setAmount] = createSignal(""); const [receiveState, setReceiveState] = createSignal("edit"); const [bip21Raw, setBip21Raw] = createSignal(); + const [bolt12, setBolt12] = createSignal(""); const [unified, setUnified] = createSignal(""); const [shouldShowAmountEditor, setShouldShowAmountEditor] = createSignal(true); @@ -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" } ]; @@ -170,6 +176,8 @@ export default function Receive() { return bip21Raw()?.invoice ?? ""; } else if (flavor() === "onchain") { return bip21Raw()?.address ?? ""; + } else if (flavor() === "bolt12") { + return bolt12() ?? ""; } } }); @@ -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); } diff --git a/src/routes/Send.tsx b/src/routes/Send.tsx index 7b7b7690..322b8a5c 100644 --- a/src/routes/Send.tsx +++ b/src/routes/Send.tsx @@ -175,6 +175,7 @@ function DestinationShower(props: { description?: string; address?: string; invoice?: MutinyInvoice; + offer?: string; nodePubkey?: string; lnurl?: string; clearAll: () => void; @@ -187,6 +188,9 @@ function DestinationShower(props: { + + + @@ -213,6 +217,7 @@ export default function Send() { // These can only be derived from the "destination" signal const [invoice, setInvoice] = createSignal(); + const [offer, setOffer] = createSignal(); const [nodePubkey, setNodePubkey] = createSignal(); const [lnurlp, setLnurlp] = createSignal(); const [address, setAddress] = createSignal(); @@ -236,6 +241,7 @@ export default function Send() { setIsAmtEditable(true); setSource("lightning"); setInvoice(undefined); + setOffer(undefined); setAddress(undefined); setDescription(undefined); setNodePubkey(undefined); @@ -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); @@ -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) || ""; @@ -576,7 +607,7 @@ export default function Send() { } > @@ -657,6 +688,7 @@ export default function Send() { when={ address() || invoice() || + offer() || nodePubkey() || lnurlp() } @@ -672,6 +704,7 @@ export default function Send() { source={source()} description={description()} invoice={invoice()} + offer={offer()} address={address()} nodePubkey={nodePubkey()} lnurl={lnurlp()} @@ -720,6 +753,7 @@ export default function Send() { when={ address() || invoice() || + offer() || nodePubkey() || lnurlp() } diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index edfaec67..ead3886a 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -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 ) {