mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-05 07:14:25 +01:00
decode node pubkeys
This commit is contained in:
@@ -13,6 +13,7 @@ export type ParsedParams = {
|
||||
amount_sats?: bigint;
|
||||
network?: string;
|
||||
memo?: string;
|
||||
node_pubkey?: string;
|
||||
}
|
||||
|
||||
export function toParsedParams(str: string, ourNetwork: string): Result<ParsedParams> {
|
||||
@@ -24,16 +25,23 @@ export function toParsedParams(str: string, ourNetwork: string): Result<ParsedPa
|
||||
return { ok: false, error: new Error("Invalid payment request") }
|
||||
}
|
||||
|
||||
console.log("params:", params.node_pubkey)
|
||||
console.log("params network:", params.network)
|
||||
console.log("our network:", ourNetwork)
|
||||
|
||||
|
||||
|
||||
// TODO: "testnet" and "signet" are encoded the same I guess?
|
||||
if (params.network === "testnet" || params.network === "signet") {
|
||||
if (ourNetwork === "signet") {
|
||||
// noop
|
||||
}
|
||||
} else if (params.network !== ourNetwork) {
|
||||
return { ok: false, error: new Error(`Destination is for ${params.network} but you're on ${ourNetwork}`) }
|
||||
if (params.node_pubkey) {
|
||||
// noop
|
||||
} else {
|
||||
return { ok: false, error: new Error(`Destination is for ${params.network} but you're on ${ourNetwork}`) }
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -42,7 +50,8 @@ export function toParsedParams(str: string, ourNetwork: string): Result<ParsedPa
|
||||
invoice: params.invoice,
|
||||
amount_sats: params.amount_sats,
|
||||
network: params.network,
|
||||
memo: params.memo
|
||||
memo: params.memo,
|
||||
node_pubkey: params.node_pubkey,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +93,7 @@ export default function Scanner() {
|
||||
showToast(result.error);
|
||||
return;
|
||||
} else {
|
||||
if (result.value?.address || result.value?.invoice) {
|
||||
if (result.value?.address || result.value?.invoice || result.value?.node_pubkey) {
|
||||
actions.setScanResult(result.value);
|
||||
navigate("/send")
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ export default function Send() {
|
||||
|
||||
// These can only be derived from the "destination" signal
|
||||
const [invoice, setInvoice] = createSignal<MutinyInvoice>();
|
||||
const [nodePubkey, setNodePubkey] = createSignal<string>();
|
||||
const [address, setAddress] = createSignal<string>();
|
||||
const [description, setDescription] = createSignal<string>();
|
||||
|
||||
@@ -78,7 +79,11 @@ export default function Send() {
|
||||
if (source.address) setAddress(source.address)
|
||||
if (source.memo) setDescription(source.memo);
|
||||
|
||||
if (source.invoice) {
|
||||
if (source.node_pubkey) {
|
||||
setAmountSats(source.amount_sats || 0n);
|
||||
setNodePubkey(source.node_pubkey);
|
||||
setSource("lightning")
|
||||
} else if (source.invoice) {
|
||||
state.node_manager?.decode_invoice(source.invoice).then(invoice => {
|
||||
if (invoice?.amount_sats) setAmountSats(invoice.amount_sats);
|
||||
setInvoice(invoice)
|
||||
@@ -104,7 +109,7 @@ export default function Send() {
|
||||
showToast(result.error);
|
||||
return;
|
||||
} else {
|
||||
if (result.value?.address || result.value?.invoice) {
|
||||
if (result.value?.address || result.value?.invoice || result.value?.node_pubkey) {
|
||||
setDestination(result.value);
|
||||
// Important! we need to clear the scan result once we've used it
|
||||
actions.setScanResult(undefined);
|
||||
@@ -146,6 +151,12 @@ export default function Send() {
|
||||
await state.node_manager?.pay_invoice(firstNode, bolt11, amountSats());
|
||||
sentDetails.amount = amountSats();
|
||||
}
|
||||
} else if (source() === "lightning" && nodePubkey()) {
|
||||
const nodes = await state.node_manager?.list_nodes();
|
||||
const firstNode = nodes[0] as string || ""
|
||||
const invoice = await state.node_manager?.keysend(firstNode, nodePubkey()!, amountSats());
|
||||
console.log(invoice?.value)
|
||||
sentDetails.amount = amountSats();
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const txid = await state.node_manager?.send_to_address(address()!, amountSats());
|
||||
@@ -165,6 +176,10 @@ export default function Send() {
|
||||
}
|
||||
}
|
||||
|
||||
const sendButtonDisabled = createMemo(() => {
|
||||
return !destination() || sending() || amountSats() === 0n;
|
||||
})
|
||||
|
||||
return (
|
||||
<NodeManagerGuard>
|
||||
<SafeArea>
|
||||
@@ -188,7 +203,7 @@ export default function Send() {
|
||||
</dt>
|
||||
<dd>
|
||||
<Switch>
|
||||
<Match when={address() || invoice()}>
|
||||
<Match when={address() || invoice() || nodePubkey()}>
|
||||
<div class="flex gap-2 items-center">
|
||||
<Show when={address() && source() === "onchain"}>
|
||||
<code class="truncate text-sm break-all">{"Address: "} {address()}
|
||||
@@ -206,6 +221,11 @@ export default function Send() {
|
||||
</Show>
|
||||
</code>
|
||||
</Show>
|
||||
<Show when={nodePubkey() && source() === "lightning"}>
|
||||
<code class="truncate text-sm break-all">{"Node Pubkey: "} {nodePubkey()}
|
||||
|
||||
</code>
|
||||
</Show>
|
||||
<Button class="flex-0" intent="glowy" layout="xs" onClick={clearAll}>Clear</Button>
|
||||
</div>
|
||||
<div class="my-8 flex gap-4 w-full items-center justify-around">
|
||||
@@ -263,7 +283,7 @@ export default function Send() {
|
||||
</Show>
|
||||
</dl>
|
||||
<Show when={destination()}>
|
||||
<Button disabled={!destination() || sending()} intent="blue" onClick={handleSend} loading={sending()}>{sending() ? "Sending..." : "Confirm Send"}</Button>
|
||||
<Button disabled={sendButtonDisabled()} intent="blue" onClick={handleSend} loading={sending()}>{sending() ? "Sending..." : "Confirm Send"}</Button>
|
||||
</Show>
|
||||
</DefaultMain>
|
||||
<NavBar activeTab="send" />
|
||||
|
||||
Reference in New Issue
Block a user