diff --git a/src/components/Internal/Zap.tsx b/src/components/Internal/Zap.tsx index 0c5cb7a..474d908 100644 --- a/src/components/Internal/Zap.tsx +++ b/src/components/Internal/Zap.tsx @@ -1,3 +1,4 @@ +import { Dots } from 'components/Spinner' import { ZapSplit } from 'components/Zap' import { useAppSelector, @@ -8,7 +9,7 @@ import { import { useState } from 'react' import { toast } from 'react-toastify' import { Addressable } from 'types' -import { abbreviateNumber } from 'utils' +import { abbreviateNumber, log, LogType } from 'utils' type ZapProps = { addressable: Addressable @@ -16,15 +17,25 @@ type ZapProps = { export const Zap = ({ addressable }: ZapProps) => { const [isOpen, setIsOpen] = useState(false) + const [isLoading, setIsLoading] = useState(true) + const [isAvailable, setIsAvailable] = useState(false) const [totalZappedAmount, setTotalZappedAmount] = useState(0) const [hasZapped, setHasZapped] = useState(false) const userState = useAppSelector((state) => state.user) - const { getTotalZapAmount } = useNDKContext() + const { getTotalZapAmount, findMetadata } = useNDKContext() useBodyScrollDisable(isOpen) useDidMount(() => { + findMetadata(addressable.author) + .then((res) => { + setIsAvailable(typeof res?.lud16 !== 'undefined' && res.lud16 !== '') + }) + .catch((err) => { + log(true, LogType.Error, err.message || err) + }) + getTotalZapAmount( addressable.author, addressable.id, @@ -38,8 +49,14 @@ export const Zap = ({ addressable }: ZapProps) => { .catch((err) => { toast.error(err.message || err) }) + .finally(() => { + setIsLoading(false) + }) }) + // Hide button if the author hasn't set lud16 + if (!isAvailable) return null + return ( <>
- {abbreviateNumber(totalZappedAmount)}
+ {isLoading ?