fix(zap): add timeout and hide loading when done
This commit is contained in:
parent
b41676e4a9
commit
670b981b05
@ -21,6 +21,7 @@ import {
|
|||||||
getZapAmount,
|
getZapAmount,
|
||||||
log,
|
log,
|
||||||
LogType,
|
LogType,
|
||||||
|
timeout,
|
||||||
unformatNumber
|
unformatNumber
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { LoadingSpinner } from './LoadingSpinner'
|
import { LoadingSpinner } from './LoadingSpinner'
|
||||||
@ -303,12 +304,15 @@ export const ZapPopUp = ({
|
|||||||
|
|
||||||
if (!receiverMetadata?.pubkey) {
|
if (!receiverMetadata?.pubkey) {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
toast.error('pubkey is missing in receiver metadata!')
|
toast.error('Pubkey is missing in receiver metadata!')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the receiver's read relays.
|
// Find the receiver's read relays.
|
||||||
const receiverRelays = await getRelayListForUser(receiver, ndk)
|
const receiverRelays = await Promise.race([
|
||||||
|
getRelayListForUser(receiver, ndk),
|
||||||
|
timeout(2000)
|
||||||
|
])
|
||||||
.then((ndkRelayList) => {
|
.then((ndkRelayList) => {
|
||||||
if (ndkRelayList) return ndkRelayList.readRelayUrls
|
if (ndkRelayList) return ndkRelayList.readRelayUrls
|
||||||
return [] // Return an empty array if ndkRelayList is undefined
|
return [] // Return an empty array if ndkRelayList is undefined
|
||||||
@ -554,7 +558,7 @@ export const ZapSplit = ({
|
|||||||
const generatePaymentInvoices = async () => {
|
const generatePaymentInvoices = async () => {
|
||||||
if (!amount) return null
|
if (!amount) return null
|
||||||
|
|
||||||
let userHexKey: string
|
let userHexKey: string | undefined
|
||||||
|
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setLoadingSpinnerDesc('Getting user pubkey')
|
setLoadingSpinnerDesc('Getting user pubkey')
|
||||||
@ -562,7 +566,11 @@ export const ZapSplit = ({
|
|||||||
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 {
|
||||||
|
try {
|
||||||
userHexKey = (await window.nostr?.getPublicKey()) as string
|
userHexKey = (await window.nostr?.getPublicKey()) as string
|
||||||
|
} catch (error) {
|
||||||
|
log(true, LogType.Error, `Could not get pubkey`, error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userHexKey) {
|
if (!userHexKey) {
|
||||||
@ -620,7 +628,11 @@ export const ZapSplit = ({
|
|||||||
|
|
||||||
if (adminShare > 0 && admin?.pubkey && admin?.lud16) {
|
if (adminShare > 0 && admin?.pubkey && admin?.lud16) {
|
||||||
// Find the receiver's read relays.
|
// Find the receiver's read relays.
|
||||||
const adminRelays = await getRelayListForUser(admin.pubkey as string, ndk)
|
// TODO: NDK should have native timeout in a future release
|
||||||
|
const adminRelays = await Promise.race([
|
||||||
|
getRelayListForUser(admin.pubkey as string, ndk),
|
||||||
|
timeout(2000)
|
||||||
|
])
|
||||||
.then((ndkRelayList) => {
|
.then((ndkRelayList) => {
|
||||||
if (ndkRelayList) return ndkRelayList.readRelayUrls
|
if (ndkRelayList) return ndkRelayList.readRelayUrls
|
||||||
return [] // Return an empty array if ndkRelayList is undefined
|
return [] // Return an empty array if ndkRelayList is undefined
|
||||||
@ -721,6 +733,8 @@ export const ZapSplit = ({
|
|||||||
toast.warn('Webln is not present. Use QR code to send zap.')
|
toast.warn('Webln is not present. Use QR code to send zap.')
|
||||||
setInvoices(paymentInvoices)
|
setInvoices(paymentInvoices)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeInvoice = (key: string) => {
|
const removeInvoice = (key: string) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user