fix(zap): hide split button if author has no ln address
All checks were successful
Release to Staging / build_and_release (push) Successful in 59s
All checks were successful
Release to Staging / build_and_release (push) Successful in 59s
Fixes #183
This commit is contained in:
parent
425f4f9cd4
commit
177d2fb2ac
@ -1,3 +1,4 @@
|
|||||||
|
import { Dots } from 'components/Spinner'
|
||||||
import { ZapSplit } from 'components/Zap'
|
import { ZapSplit } from 'components/Zap'
|
||||||
import {
|
import {
|
||||||
useAppSelector,
|
useAppSelector,
|
||||||
@ -8,7 +9,7 @@ import {
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { Addressable } from 'types'
|
import { Addressable } from 'types'
|
||||||
import { abbreviateNumber } from 'utils'
|
import { abbreviateNumber, log, LogType } from 'utils'
|
||||||
|
|
||||||
type ZapProps = {
|
type ZapProps = {
|
||||||
addressable: Addressable
|
addressable: Addressable
|
||||||
@ -16,15 +17,25 @@ type ZapProps = {
|
|||||||
|
|
||||||
export const Zap = ({ addressable }: ZapProps) => {
|
export const Zap = ({ addressable }: ZapProps) => {
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
|
const [isAvailable, setIsAvailable] = useState(false)
|
||||||
const [totalZappedAmount, setTotalZappedAmount] = useState(0)
|
const [totalZappedAmount, setTotalZappedAmount] = useState(0)
|
||||||
const [hasZapped, setHasZapped] = useState(false)
|
const [hasZapped, setHasZapped] = useState(false)
|
||||||
|
|
||||||
const userState = useAppSelector((state) => state.user)
|
const userState = useAppSelector((state) => state.user)
|
||||||
const { getTotalZapAmount } = useNDKContext()
|
const { getTotalZapAmount, findMetadata } = useNDKContext()
|
||||||
|
|
||||||
useBodyScrollDisable(isOpen)
|
useBodyScrollDisable(isOpen)
|
||||||
|
|
||||||
useDidMount(() => {
|
useDidMount(() => {
|
||||||
|
findMetadata(addressable.author)
|
||||||
|
.then((res) => {
|
||||||
|
setIsAvailable(typeof res?.lud16 !== 'undefined' && res.lud16 !== '')
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
log(true, LogType.Error, err.message || err)
|
||||||
|
})
|
||||||
|
|
||||||
getTotalZapAmount(
|
getTotalZapAmount(
|
||||||
addressable.author,
|
addressable.author,
|
||||||
addressable.id,
|
addressable.id,
|
||||||
@ -38,7 +49,13 @@ export const Zap = ({ addressable }: ZapProps) => {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
toast.error(err.message || err)
|
toast.error(err.message || err)
|
||||||
})
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setIsLoading(false)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Hide button if the author hasn't set lud16
|
||||||
|
if (!isAvailable) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -47,7 +64,7 @@ export const Zap = ({ addressable }: ZapProps) => {
|
|||||||
className={`IBMSMSMBSS_Details_Card IBMSMSMBSS_D_CBolt ${
|
className={`IBMSMSMBSS_Details_Card IBMSMSMBSS_D_CBolt ${
|
||||||
hasZapped ? 'IBMSMSMBSS_D_CBActive' : ''
|
hasZapped ? 'IBMSMSMBSS_D_CBActive' : ''
|
||||||
}`}
|
}`}
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={isLoading ? undefined : () => setIsOpen(true)}
|
||||||
>
|
>
|
||||||
<div className='IBMSMSMBSS_Details_CardVisual'>
|
<div className='IBMSMSMBSS_Details_CardVisual'>
|
||||||
<svg
|
<svg
|
||||||
@ -62,7 +79,7 @@ export const Zap = ({ addressable }: ZapProps) => {
|
|||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<p className='IBMSMSMBSS_Details_CardText'>
|
<p className='IBMSMSMBSS_Details_CardText'>
|
||||||
{abbreviateNumber(totalZappedAmount)}
|
{isLoading ? <Dots /> : abbreviateNumber(totalZappedAmount)}
|
||||||
</p>
|
</p>
|
||||||
<div className='IBMSMSMBSSCL_CAElementLoadWrapper'>
|
<div className='IBMSMSMBSSCL_CAElementLoadWrapper'>
|
||||||
<div className='IBMSMSMBSSCL_CAElementLoad'></div>
|
<div className='IBMSMSMBSSCL_CAElementLoad'></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user