mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-09-19 12:00:32 +02:00
Fix stream view crashing when failing to parse zap request
This commit is contained in:
5
.changeset/few-melons-watch.md
Normal file
5
.changeset/few-melons-watch.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"nostrudel": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix stream view crashing when failing to parse zap request
|
@@ -1,4 +1,4 @@
|
|||||||
import React, { useRef } from "react";
|
import React, { useMemo, useRef } from "react";
|
||||||
import { Box, Flex, Text } from "@chakra-ui/react";
|
import { Box, Flex, Text } from "@chakra-ui/react";
|
||||||
import { ParsedStream } from "../../../../helpers/nostr/stream";
|
import { ParsedStream } from "../../../../helpers/nostr/stream";
|
||||||
import { UserAvatar } from "../../../../components/user-avatar";
|
import { UserAvatar } from "../../../../components/user-avatar";
|
||||||
@@ -15,20 +15,25 @@ function ZapMessage({ zap, stream }: { zap: NostrEvent; stream: ParsedStream })
|
|||||||
const ref = useRef<HTMLDivElement | null>(null);
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
useRegisterIntersectionEntity(ref, zap.id);
|
useRegisterIntersectionEntity(ref, zap.id);
|
||||||
|
|
||||||
const { request, payment } = parseZapEvent(zap);
|
const parsed = useMemo(() => {
|
||||||
if (!payment.amount) return null;
|
try {
|
||||||
|
return parseZapEvent(zap);
|
||||||
|
} catch (e) {}
|
||||||
|
}, [zap]);
|
||||||
|
|
||||||
|
if (!parsed || !parsed.payment.amount) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TrustProvider event={request}>
|
<TrustProvider event={parsed.request}>
|
||||||
<Flex direction="column" borderRadius="md" borderColor="yellow.400" borderWidth="1px" p="2" ref={ref}>
|
<Flex direction="column" borderRadius="md" borderColor="yellow.400" borderWidth="1px" p="2" ref={ref}>
|
||||||
<Flex gap="2">
|
<Flex gap="2">
|
||||||
<LightningIcon color="yellow.400" />
|
<LightningIcon color="yellow.400" />
|
||||||
<UserAvatar pubkey={request.pubkey} size="xs" />
|
<UserAvatar pubkey={parsed.request.pubkey} size="xs" />
|
||||||
<UserLink pubkey={request.pubkey} fontWeight="bold" color="yellow.400" />
|
<UserLink pubkey={parsed.request.pubkey} fontWeight="bold" color="yellow.400" />
|
||||||
<Text>zapped {readablizeSats(payment.amount / 1000)} sats</Text>
|
<Text>zapped {readablizeSats(parsed.payment.amount / 1000)} sats</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Box>
|
<Box>
|
||||||
<ChatMessageContent event={request} />
|
<ChatMessageContent event={parsed.request} />
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
</TrustProvider>
|
</TrustProvider>
|
||||||
|
Reference in New Issue
Block a user