Browse Source

Split zaps

imwald
Nuša Pukšič 2 months ago
parent
commit
795570cee9
  1. 3
      assets/styles/03-components/zaps.css
  2. 23
      src/Service/NostrSigner.php
  3. 10
      src/Twig/Components/Molecules/ZapButton.php

3
assets/styles/03-components/zaps.css

@ -1,6 +1,3 @@
.zap-button-component {
margin: var(--spacing-2) 0;
}
.zap-modal-overlay { .zap-modal-overlay {
position: fixed; position: fixed;
top: 0; top: 0;

23
src/Service/NostrSigner.php

@ -59,6 +59,7 @@ class NostrSigner
* @param string $lnurl The LNURL or callback URL * @param string $lnurl The LNURL or callback URL
* @param string $comment Optional comment/note * @param string $comment Optional comment/note
* @param array $relays Optional list of relays * @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 * @return string JSON-encoded signed zap request
*/ */
public function buildZapRequest( public function buildZapRequest(
@ -66,7 +67,8 @@ class NostrSigner
int $amountMillisats, int $amountMillisats,
string $lnurl, string $lnurl,
string $comment = '', string $comment = '',
array $relays = [] array $relays = [],
array $zapSplits = []
): string { ): string {
$tags = [ $tags = [
['p', $recipientPubkey], ['p', $recipientPubkey],
@ -79,6 +81,25 @@ class NostrSigner
$tags[] = ['relays', $relay]; $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); return $this->signEphemeral(9734, $tags, $comment);
} }
} }

10
src/Twig/Components/Molecules/ZapButton.php

@ -34,6 +34,13 @@ final class ZapButton
#[LiveProp] #[LiveProp]
public ?string $recipientLud06 = null; public ?string $recipientLud06 = null;
/**
* Zap splits configuration
* Array of ['recipient' => hex pubkey, 'relay' => url, 'weight' => int]
*/
#[LiveProp]
public array $zapSplits = [];
// UI state props (internal) // UI state props (internal)
#[LiveProp(writable: true)] #[LiveProp(writable: true)]
public bool $open = false; public bool $open = false;
@ -156,7 +163,8 @@ final class ZapButton
amountMillisats: $amountMillisats, amountMillisats: $amountMillisats,
lnurl: $lnurlInfo->bech32 ?? ($this->recipientLud16 ?? $this->recipientLud06 ?? ''), lnurl: $lnurlInfo->bech32 ?? ($this->recipientLud16 ?? $this->recipientLud06 ?? ''),
comment: $this->comment, 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 // URL-encode the zap request for the callback

Loading…
Cancel
Save