Fix stuck zap tip and add pubkey fetch error handling #206

Merged
enes merged 2 commits from issues/205-zap-tipping-broken into staging 2025-01-27 13:42:28 +00:00
9 changed files with 66 additions and 21 deletions
Showing only changes of commit b41676e4a9 - Show all commits

View File

@ -383,7 +383,12 @@ const FollowButton = ({ pubkey }: FollowButtonProps) => {
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
return userState.user.pubkey as string return userState.user.pubkey as string
} else { } else {
return (await window.nostr?.getPublicKey()) as string try {
return (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
return null
}
} }
} }

View File

@ -19,6 +19,8 @@ import {
formatNumber, formatNumber,
getTagValue, getTagValue,
getZapAmount, getZapAmount,
log,
LogType,
unformatNumber unformatNumber
} from '../utils' } from '../utils'
import { LoadingSpinner } from './LoadingSpinner' import { LoadingSpinner } from './LoadingSpinner'
@ -268,7 +270,7 @@ export const ZapPopUp = ({
const generatePaymentRequest = const generatePaymentRequest =
useCallback(async (): Promise<PaymentRequest | null> => { useCallback(async (): Promise<PaymentRequest | null> => {
let userHexKey: string let userHexKey: string | undefined
setIsLoading(true) setIsLoading(true)
setLoadingSpinnerDesc('Getting user pubkey') setLoadingSpinnerDesc('Getting user pubkey')
@ -276,7 +278,11 @@ export const ZapPopUp = ({
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
userHexKey = userState.user.pubkey as string userHexKey = userState.user.pubkey as string
} else { } else {
userHexKey = (await window.nostr?.getPublicKey()) as string try {
userHexKey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!userHexKey) { if (!userHexKey) {
@ -285,7 +291,7 @@ export const ZapPopUp = ({
return null return null
} }
setLoadingSpinnerDesc('finding receiver metadata') setLoadingSpinnerDesc('Finding receiver metadata')
const receiverMetadata = await findMetadata(receiver) const receiverMetadata = await findMetadata(receiver)

View File

@ -78,12 +78,16 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
const handleSubmit = async (content: string): Promise<boolean> => { const handleSubmit = async (content: string): Promise<boolean> => {
if (content === '') return false if (content === '') return false
let pubkey: string let pubkey: string | undefined
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
pubkey = userState.user.pubkey as string pubkey = userState.user.pubkey as string
} else { } else {
pubkey = (await window.nostr?.getPublicKey()) as string try {
pubkey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!pubkey) { if (!pubkey) {

View File

@ -2,7 +2,7 @@ import axios, { isAxiosError } from 'axios'
import { NostrEvent, NDKKind } from '@nostr-dev-kit/ndk' import { NostrEvent, NDKKind } from '@nostr-dev-kit/ndk'
import { type MediaOperations } from '.' import { type MediaOperations } from '.'
import { store } from 'store' import { store } from 'store'
import { now } from 'utils' import { log, LogType, now } from 'utils'
import { BaseError, handleError } from 'types' import { BaseError, handleError } from 'types'
// https://github.com/quentintaranpino/nostrcheck-server/blob/main/DOCS.md#media-post // https://github.com/quentintaranpino/nostrcheck-server/blob/main/DOCS.md#media-post
@ -124,12 +124,16 @@ export class NostrCheckServer implements MediaOperations {
try { try {
const url = `${this.#url}${this.#media}` const url = `${this.#url}${this.#media}`
let hexPubkey: string let hexPubkey: string | undefined
const userState = store.getState().user const userState = store.getState().user
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
hexPubkey = userState.user.pubkey as string hexPubkey = userState.user.pubkey as string
} else { } else {
hexPubkey = (await window.nostr?.getPublicKey()) as string try {
hexPubkey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!hexPubkey) { if (!hexPubkey) {

View File

@ -70,12 +70,16 @@ export const useReactions = (params: UseReactionsParams) => {
}, [reactionEvents, userState]) }, [reactionEvents, userState])
const getPubkey = async () => { const getPubkey = async () => {
let hexPubkey: string let hexPubkey: string | undefined
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
hexPubkey = userState.user.pubkey as string hexPubkey = userState.user.pubkey as string
} else { } else {
hexPubkey = (await window.nostr?.getPublicKey()) as string try {
hexPubkey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!hexPubkey) { if (!hexPubkey) {

View File

@ -33,11 +33,15 @@ export const blogRouteAction =
} }
const userState = store.getState().user const userState = store.getState().user
let hexPubkey: string let hexPubkey: string | undefined
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
hexPubkey = userState.user.pubkey as string hexPubkey = userState.user.pubkey as string
} else { } else {
hexPubkey = (await window.nostr?.getPublicKey()) as string try {
hexPubkey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!hexPubkey) { if (!hexPubkey) {

View File

@ -43,11 +43,15 @@ export const modRouteAction =
} }
const userState = store.getState().user const userState = store.getState().user
let hexPubkey: string let hexPubkey: string | undefined
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
hexPubkey = userState.user.pubkey as string hexPubkey = userState.user.pubkey as string
} else { } else {
hexPubkey = (await window.nostr?.getPublicKey()) as string try {
hexPubkey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!hexPubkey) { if (!hexPubkey) {

View File

@ -30,6 +30,8 @@ import {
copyTextToClipboard, copyTextToClipboard,
DEFAULT_FILTER_OPTIONS, DEFAULT_FILTER_OPTIONS,
extractBlogCardDetails, extractBlogCardDetails,
log,
LogType,
now, now,
npubToHex, npubToHex,
scrollIntoView, scrollIntoView,
@ -72,7 +74,7 @@ export const ProfilePage = () => {
return return
} }
let userHexKey: string let userHexKey: string | undefined
setIsLoading(true) setIsLoading(true)
setLoadingSpinnerDesc('Getting user pubkey') setLoadingSpinnerDesc('Getting user pubkey')
@ -80,7 +82,11 @@ export const ProfilePage = () => {
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
userHexKey = userState.user.pubkey as string userHexKey = userState.user.pubkey as string
} else { } else {
userHexKey = (await window.nostr?.getPublicKey()) as string try {
userHexKey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!userHexKey) { if (!userHexKey) {
@ -512,11 +518,15 @@ const ReportUserPopup = ({
setIsLoading(true) setIsLoading(true)
setLoadingSpinnerDesc('Getting user pubkey') setLoadingSpinnerDesc('Getting user pubkey')
let userHexKey: string let userHexKey: string | undefined
if (userState.auth && userState.user?.pubkey) { if (userState.auth && userState.user?.pubkey) {
userHexKey = userState.user.pubkey as string userHexKey = userState.user.pubkey as string
} else { } else {
userHexKey = (await window.nostr?.getPublicKey()) as string try {
userHexKey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!userHexKey) { if (!userHexKey) {

View File

@ -55,12 +55,16 @@ export const PreferencesSetting = () => {
const handleSave = async () => { const handleSave = async () => {
setIsSaving(true) setIsSaving(true)
let hexPubkey: string let hexPubkey: string | undefined
if (user?.pubkey) { if (user?.pubkey) {
hexPubkey = user.pubkey as string hexPubkey = user.pubkey as string
} else { } else {
hexPubkey = (await window.nostr?.getPublicKey()) as string try {
hexPubkey = (await window.nostr?.getPublicKey()) as string
} catch (error) {
log(true, LogType.Error, `Could not get pubkey`, error)
}
} }
if (!hexPubkey) { if (!hexPubkey) {