mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
A static client can't fetch LNURL hosts that omit CORS headers, so zaps to those creators fail. Add a browser-side reachability probe (checkLightningAddressZappable) and surface it on both sides: the creator is warned at wallet-connect time if their own address isn't browser- zappable, and the zapper sees a heads-up when opening a non-reachable creator's zap dialog. Also fix encrypted settings restore: the "already offered" flag was per-pubkey, so once storage was offered the wallet note was never offered later. Track it per-item so the wallet is offered independently. Zappability check extracted to walletZappabilityCheck.js for the size cap. Co-Authored-By: Claude Opus 4.8 <[email protected]>
64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
import { checkLightningAddressZappable } from "../../payments/lnurl.js";
|
|
import { devLogger } from "../../utils/logger.js";
|
|
|
|
// Warn the creator if their OWN receiving Lightning address can't be reached from
|
|
// a browser (so people can't zap them on bitvid). Best-effort, non-blocking; runs
|
|
// after a successful wallet save. The probe is the exact fetch a zapper's browser
|
|
// would make, so a failure here means a failure for everyone. `controller` is the
|
|
// ProfileWalletController (provides mainController + updateWalletStatus).
|
|
export async function runWalletZappabilityCheck(controller, pubkey) {
|
|
try {
|
|
const main = controller?.mainController;
|
|
const entry =
|
|
typeof main?.getProfileCacheEntry === "function"
|
|
? main.getProfileCacheEntry(pubkey)
|
|
: null;
|
|
const profile = entry?.profile || null;
|
|
// No cached profile -> can't determine; don't guess (avoid a false warning).
|
|
if (!profile) {
|
|
return;
|
|
}
|
|
|
|
const address =
|
|
(typeof profile.lud16 === "string" && profile.lud16.trim()) ||
|
|
(typeof profile.lud06 === "string" && profile.lud06.trim()) ||
|
|
"";
|
|
|
|
if (!address) {
|
|
controller.updateWalletStatus(
|
|
"Wallet saved. Tip: add a Lightning address to your Nostr profile so people can zap you on bitvid.",
|
|
"info",
|
|
);
|
|
return;
|
|
}
|
|
|
|
const result = await checkLightningAddressZappable(address);
|
|
if (!result.ok) {
|
|
const message =
|
|
`Heads up: your Lightning address (${address}) can't be reached from a browser ` +
|
|
"— its host may be offline or blocking browser requests (no CORS). People may " +
|
|
"not be able to zap you on bitvid. A host with proper CORS support (e.g. Alby, " +
|
|
"Coinos, Wallet of Satoshi) fixes this.";
|
|
controller.updateWalletStatus(message, "error");
|
|
main.showError(message);
|
|
return;
|
|
}
|
|
|
|
if (result.reason === "no-nostr") {
|
|
controller.updateWalletStatus(
|
|
`Your Lightning address (${address}) is reachable, but its host doesn't advertise ` +
|
|
"Nostr zaps — payments may work without a zap receipt.",
|
|
"info",
|
|
);
|
|
return;
|
|
}
|
|
|
|
controller.updateWalletStatus(
|
|
`Wallet saved. Your Lightning address (${address}) is reachable — people can zap you on bitvid.`,
|
|
"success",
|
|
);
|
|
} catch (error) {
|
|
devLogger.warn("[ProfileModal] Lightning zappability check failed:", error);
|
|
}
|
|
}
|