fix: use support$ instead of getInfo() for wallet connection

wallet.getInfo() sends an NWC request that can timeout if the wallet
service is slow. Instead, use wallet.getSupport() which returns the
already-cached support$ value (no network request needed).

- getInfo() is now optional - used only for alias/network
- getBalance() was already optional
- Connection succeeds as long as support$ emits

https://claude.ai/code/session_018fU3rYmjFPEKz3ot1itLZL
This commit is contained in:
Claude
2026-01-30 10:51:15 +00:00
parent 4f7248298b
commit 3b21ce509c
2 changed files with 29 additions and 29 deletions

View File

@@ -59,19 +59,29 @@ export default function ConnectWalletDialog({
// This waits for the wallet to be ready (support$ must emit)
const wallet = await createWalletFromURI(connectionString);
// Get wallet info (wallet is already ready at this point)
const info = await wallet.getInfo();
// Get support info from the already-emitted support$ (no network request needed)
const support = await wallet.getSupport();
// Get initial balance
// Try to get extended info (alias, network) but don't fail if it times out
let alias: string | undefined;
let network: string | undefined;
try {
const info = await wallet.getInfo();
alias = info.alias;
network = info.network;
} catch (err) {
console.warn("[NWC] Failed to get extended wallet info:", err);
// Continue without alias/network - they're optional
}
// Get initial balance (also optional)
let balance: number | undefined;
try {
const balanceResult = await wallet.getBalance();
balance = balanceResult.balance;
// Update the observable immediately so WalletViewer shows correct balance
balance$.next(balance);
} catch (err) {
console.warn("[NWC] Failed to get balance:", err);
// Balance is optional, continue anyway
}
// Get connection details from the wallet instance
@@ -85,10 +95,10 @@ export default function ConnectWalletDialog({
lud16: serialized.lud16,
balance,
info: {
alias: info.alias,
network: info.network,
methods: info.methods,
notifications: info.notifications,
alias,
network,
methods: support?.methods ?? [],
notifications: support?.notifications,
},
});
@@ -99,10 +109,10 @@ export default function ConnectWalletDialog({
// Update info
updateNWCInfo({
alias: info.alias,
network: info.network,
methods: info.methods,
notifications: info.notifications,
alias,
network,
methods: support?.methods ?? [],
notifications: support?.notifications,
});
// Show success toast

View File

@@ -11,7 +11,7 @@
* - Shows feed render of zapped event
*/
import { useState, useMemo, useEffect, useRef } from "react";
import { useState, useMemo, useRef } from "react";
import { toast } from "sonner";
import {
Zap,
@@ -118,17 +118,7 @@ export function ZapWindow({
const activeAccount = accountManager.active;
const canSign = !!activeAccount?.signer;
const { wallet, payInvoice, refreshBalance, getInfo } = useWallet();
// Fetch wallet info
const [walletInfo, setWalletInfo] = useState<any>(null);
useEffect(() => {
if (wallet) {
getInfo()
.then((info) => setWalletInfo(info))
.catch((error) => console.error("Failed to get wallet info:", error));
}
}, [wallet, getInfo]);
const { wallet, walletMethods, payInvoice, refreshBalance } = useWallet();
// Cache LNURL data for recipient's Lightning address
const { data: lnurlData } = useLnurlCache(recipientProfile?.lud16);
@@ -400,7 +390,7 @@ export function ZapWindow({
setInvoice(invoiceText);
// Step 5: Pay or show QR code
if (useWallet && wallet && walletInfo?.methods.includes("pay_invoice")) {
if (useWallet && wallet && walletMethods.includes("pay_invoice")) {
// Pay with NWC wallet with timeout
setIsPayingWithWallet(true);
try {
@@ -568,7 +558,7 @@ export function ZapWindow({
{/* Retry with wallet button if payment failed/timed out */}
{paymentTimedOut &&
wallet &&
walletInfo?.methods.includes("pay_invoice") && (
walletMethods.includes("pay_invoice") && (
<Button
onClick={handleRetryWallet}
disabled={isProcessing}
@@ -718,7 +708,7 @@ export function ZapWindow({
isPaid
? onClose?.()
: handleZap(
wallet && walletInfo?.methods.includes("pay_invoice"),
!!(wallet && walletMethods.includes("pay_invoice")),
)
}
disabled={
@@ -741,7 +731,7 @@ export function ZapWindow({
<CheckCircle2 className="size-4 mr-2" />
Done
</>
) : wallet && walletInfo?.methods.includes("pay_invoice") ? (
) : wallet && walletMethods.includes("pay_invoice") ? (
<>
<Wallet className="size-4 mr-2" />
Pay with Wallet (