fix(pubkey): handle error thrown by canceling pubkey fetch

This commit is contained in:
en 2025-01-27 13:20:44 +01:00
parent 02897ea72a
commit b41676e4a9
9 changed files with 66 additions and 21 deletions

View File

@ -383,7 +383,12 @@ const FollowButton = ({ pubkey }: FollowButtonProps) => {
if (userState.auth && userState.user?.pubkey) {
return userState.user.pubkey as string
} 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,
getTagValue,
getZapAmount,
log,
LogType,
unformatNumber
} from '../utils'
import { LoadingSpinner } from './LoadingSpinner'
@ -268,7 +270,7 @@ export const ZapPopUp = ({
const generatePaymentRequest =
useCallback(async (): Promise<PaymentRequest | null> => {
let userHexKey: string
let userHexKey: string | undefined
setIsLoading(true)
setLoadingSpinnerDesc('Getting user pubkey')
@ -276,7 +278,11 @@ export const ZapPopUp = ({
if (userState.auth && userState.user?.pubkey) {
userHexKey = userState.user.pubkey as string
} 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) {
@ -285,7 +291,7 @@ export const ZapPopUp = ({
return null
}
setLoadingSpinnerDesc('finding receiver metadata')
setLoadingSpinnerDesc('Finding receiver metadata')
const receiverMetadata = await findMetadata(receiver)

View File

@ -78,12 +78,16 @@ export const Comments = ({ addressable, setCommentCount }: Props) => {
const handleSubmit = async (content: string): Promise<boolean> => {
if (content === '') return false
let pubkey: string
let pubkey: string | undefined
if (userState.auth && userState.user?.pubkey) {
pubkey = userState.user.pubkey as string
} 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) {

View File

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

View File

@ -70,12 +70,16 @@ export const useReactions = (params: UseReactionsParams) => {
}, [reactionEvents, userState])
const getPubkey = async () => {
let hexPubkey: string
let hexPubkey: string | undefined
if (userState.auth && userState.user?.pubkey) {
hexPubkey = userState.user.pubkey as string
} 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) {

View File

@ -33,11 +33,15 @@ export const blogRouteAction =
}
const userState = store.getState().user
let hexPubkey: string
let hexPubkey: string | undefined
if (userState.auth && userState.user?.pubkey) {
hexPubkey = userState.user.pubkey as string
} 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) {

View File

@ -43,11 +43,15 @@ export const modRouteAction =
}
const userState = store.getState().user
let hexPubkey: string
let hexPubkey: string | undefined
if (userState.auth && userState.user?.pubkey) {
hexPubkey = userState.user.pubkey as string
} 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) {

View File

@ -30,6 +30,8 @@ import {
copyTextToClipboard,
DEFAULT_FILTER_OPTIONS,
extractBlogCardDetails,
log,
LogType,
now,
npubToHex,
scrollIntoView,
@ -72,7 +74,7 @@ export const ProfilePage = () => {
return
}
let userHexKey: string
let userHexKey: string | undefined
setIsLoading(true)
setLoadingSpinnerDesc('Getting user pubkey')
@ -80,7 +82,11 @@ export const ProfilePage = () => {
if (userState.auth && userState.user?.pubkey) {
userHexKey = userState.user.pubkey as string
} 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) {
@ -512,11 +518,15 @@ const ReportUserPopup = ({
setIsLoading(true)
setLoadingSpinnerDesc('Getting user pubkey')
let userHexKey: string
let userHexKey: string | undefined
if (userState.auth && userState.user?.pubkey) {
userHexKey = userState.user.pubkey as string
} 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) {

View File

@ -55,12 +55,16 @@ export const PreferencesSetting = () => {
const handleSave = async () => {
setIsSaving(true)
let hexPubkey: string
let hexPubkey: string | undefined
if (user?.pubkey) {
hexPubkey = user.pubkey as string
} 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) {