Skip to content

Commit

Permalink
Ad some NWC logging
Browse files Browse the repository at this point in the history
  • Loading branch information
moysa committed Feb 3, 2025
1 parent ca67212 commit f6e8b3b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/components/Note/NoteFooter/ArticleFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useToastContext } from '../../Toaster/Toaster';
import { useIntl } from '@cookbook/solid-intl';

import { truncateNumber } from '../../../lib/notifications';
import { canUserReceiveZaps, zapArticle } from '../../../lib/zap';
import { canUserReceiveZaps, lastZapError, zapArticle } from '../../../lib/zap';
import { useSettingsContext } from '../../../contexts/SettingsContext';

import zapMD from '../../../assets/lottie/zap_md_2.json';
Expand Down Expand Up @@ -326,6 +326,12 @@ const ArticleFooter: Component<{
});

return;
} else {
app?.actions.openConfirmModal({
title: "Failed to zap",
description: lastZapError,
confirmLabel: "ok",
})
}

props.customZapInfo.onFail({
Expand Down
8 changes: 7 additions & 1 deletion src/components/Note/NoteFooter/NoteFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useToastContext } from '../../Toaster/Toaster';
import { useIntl } from '@cookbook/solid-intl';

import { truncateNumber } from '../../../lib/notifications';
import { canUserReceiveZaps, zapNote } from '../../../lib/zap';
import { canUserReceiveZaps, lastZapError, zapNote } from '../../../lib/zap';
import { useSettingsContext } from '../../../contexts/SettingsContext';

import zapMD from '../../../assets/lottie/zap_md_2.json';
Expand Down Expand Up @@ -346,6 +346,12 @@ const NoteFooter: Component<{
});

return;
} else {
app?.actions.openConfirmModal({
title: "Failed to zap",
description: lastZapError,
confirmLabel: "ok",
})
}

props.customZapInfo && props.customZapInfo.onFail({
Expand Down
5 changes: 4 additions & 1 deletion src/lib/zap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { decrypt, enableWebLn, encrypt, sendPayment, signEvent } from "./nostrAP
import { decodeNWCUri } from "./wallet";
import { hexToBytes } from "../utils";

export let lastZapError: string = "";

export const zapOverNWC = async (pubkey: string, nwcEnc: string, invoice: string) => {
const nwc = await decrypt(pubkey, nwcEnc);

Expand Down Expand Up @@ -71,8 +73,9 @@ export const zapOverNWC = async (pubkey: string, nwcEnc: string, invoice: string
}
result = await Promise.any(promises);
}
catch (e) {
catch (e: any) {
logError('Failed NWC payment init: ', e);
lastZapError = e;
result = false;
}

Expand Down
23 changes: 17 additions & 6 deletions src/pages/Settings/NostrWalletConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ const NostrWalletConnect: Component = () => {

const active = loadNWCActive(account.publicKey);
if (active) {
if (active[0] === 'primal') {
connectToPrimalWallet();
}
else {
connectToNWCWallet(active[0], active[1]);
}
applyActiveWallet(active);
}
});

Expand All @@ -63,6 +58,22 @@ const NostrWalletConnect: Component = () => {
}
})

const applyActiveWallet = (wallet: string[]) => {
if (!account?.publicKey) return;

const pubkey = account.publicKey;

const [walletName, enc] = wallet;

const active = loadNWCActive(pubkey);

if (active && active.length > 0 && active[0] !== walletName) {
setWalletStatus(active[0], 'active');
}

setWalletStatus(walletName, () => 'connected');
}

const checkActiveWallet = (pubkey: string) => {
const walletSocket = new WebSocket('wss://wallet.primal.net/v1');

Expand Down

0 comments on commit f6e8b3b

Please sign in to comment.