Files
bitvid/tests/zap-shared-state.test.mjs
T
thePR0M3TH3ANandClaude Opus 4.8 c5589a1514 zap: fix NWC connection, dialog UX, and receipt reporting/discovery
- NWC connection was fully broken: parseNwcUri passed a hex secret to
  nostr-tools getPublicKey (needs Uint8Array) and threw. Convert hex->bytes.
- A successful zap was shown as a red error when the kind-9735 receipt
  couldn't be validated. The NWC preimage already proves payment, so a
  paid-but-unconfirmed share is now a success-with-note, not a failure.
- Receipt discovery: query by the reliably-indexed #e/#a/#p tags instead of
  #bolt11 (which most relays don't index), and poll a few times since the
  receipt is published shortly after payment.
- In-flight "Sending..." status no longer mis-toned as a warning; success
  path fully resets the form; an in-flight-open click no longer cancels the
  open (which made the popover need many clicks); fee fallback verified
  no-bypass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-23 14:53:38 -04:00

40 lines
1.7 KiB
JavaScript

import assert from "node:assert/strict";
const sharedStateModule = await import("../js/payments/zapSharedState.js");
const feeModule = await import("../js/payments/platformFee.js");
const { calculateZapShares } = sharedStateModule;
const { resolvePlatformFeePercent, getDefaultPlatformFeePercent } = feeModule;
(function testCalculateZapSharesSupportsRatioOverride() {
const result = calculateZapShares(35, "70/30");
assert.equal(result.total, 35);
assert.equal(result.platformShare, 10);
assert.equal(result.creatorShare, 25);
assert.equal(result.feePercent, 30);
})();
(function testCalculateZapSharesHandlesPercentStrings() {
const result = calculateZapShares(200, "30% ");
assert.equal(result.platformShare, 60);
assert.equal(result.creatorShare, 140);
assert.equal(result.feePercent, 30);
})();
(function testResolvePlatformFeePercentFallsBackToDefault() {
// An UNPARSEABLE override must fall back to the configured platform default
// (getDefaultPlatformFeePercent), NOT to 0. Falling back to 0 would let a
// garbage override silently DISABLE the platform fee (a bypass). Assert the
// contract against the configured default rather than a hard-coded number so
// the test stays correct if PLATFORM_FEE_PERCENT changes.
const expected = getDefaultPlatformFeePercent();
const percent = resolvePlatformFeePercent("not-a-number");
assert.equal(percent, expected);
// Sanity: with the platform fee configured (>0), the fallback must be non-zero
// (i.e. a junk override cannot zero out the fee).
assert.ok(expected > 0, "platform fee default should be configured > 0");
assert.ok(percent > 0, "junk override must not disable the platform fee");
})();
console.log("zap-shared-state tests passed");