From 795570cee950fe07625a58cb999a2145709b4f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Thu, 6 Nov 2025 15:15:00 +0100 Subject: [PATCH] Split zaps --- assets/styles/03-components/zaps.css | 3 --- src/Service/NostrSigner.php | 23 ++++++++++++++++++++- src/Twig/Components/Molecules/ZapButton.php | 10 ++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/assets/styles/03-components/zaps.css b/assets/styles/03-components/zaps.css index 999eeea..f24feb4 100644 --- a/assets/styles/03-components/zaps.css +++ b/assets/styles/03-components/zaps.css @@ -1,6 +1,3 @@ -.zap-button-component { - margin: var(--spacing-2) 0; -} .zap-modal-overlay { position: fixed; top: 0; diff --git a/src/Service/NostrSigner.php b/src/Service/NostrSigner.php index d361b6e..9ccafb3 100644 --- a/src/Service/NostrSigner.php +++ b/src/Service/NostrSigner.php @@ -59,6 +59,7 @@ class NostrSigner * @param string $lnurl The LNURL or callback URL * @param string $comment Optional comment/note * @param array $relays Optional list of relays + * @param array $zapSplits Optional zap splits configuration [['recipient' => hex, 'relay' => url, 'weight' => int]] * @return string JSON-encoded signed zap request */ public function buildZapRequest( @@ -66,7 +67,8 @@ class NostrSigner int $amountMillisats, string $lnurl, string $comment = '', - array $relays = [] + array $relays = [], + array $zapSplits = [] ): string { $tags = [ ['p', $recipientPubkey], @@ -79,6 +81,25 @@ class NostrSigner $tags[] = ['relays', $relay]; } + // Add zap splits if provided (NIP-57) + foreach ($zapSplits as $split) { + $zapTag = ['zap', $split['recipient']]; + + // Add relay if specified + if (!empty($split['relay'])) { + $zapTag[] = $split['relay']; + } else { + $zapTag[] = ''; // placeholder for relay position + } + + // Add weight if specified + if (!empty($split['weight'])) { + $zapTag[] = (string) $split['weight']; + } + + $tags[] = $zapTag; + } + return $this->signEphemeral(9734, $tags, $comment); } } diff --git a/src/Twig/Components/Molecules/ZapButton.php b/src/Twig/Components/Molecules/ZapButton.php index 89f319d..547cec0 100644 --- a/src/Twig/Components/Molecules/ZapButton.php +++ b/src/Twig/Components/Molecules/ZapButton.php @@ -34,6 +34,13 @@ final class ZapButton #[LiveProp] public ?string $recipientLud06 = null; + /** + * Zap splits configuration + * Array of ['recipient' => hex pubkey, 'relay' => url, 'weight' => int] + */ + #[LiveProp] + public array $zapSplits = []; + // UI state props (internal) #[LiveProp(writable: true)] public bool $open = false; @@ -156,7 +163,8 @@ final class ZapButton amountMillisats: $amountMillisats, lnurl: $lnurlInfo->bech32 ?? ($this->recipientLud16 ?? $this->recipientLud06 ?? ''), comment: $this->comment, - relays: [] // Optional: could add user's preferred relays + relays: [], // Optional: could add user's preferred relays + zapSplits: $this->zapSplits ); // URL-encode the zap request for the callback