snort/packages/app/src/Element/ZapButton.tsx

33 lines
941 B
TypeScript
Raw Normal View History

2023-01-19 11:14:41 +00:00
import "./ZapButton.css";
2023-01-19 00:03:24 +00:00
import { useState } from "react";
2023-03-03 11:56:03 +00:00
import { HexKey } from "@snort/nostr";
2023-02-25 21:18:36 +00:00
2023-03-03 14:30:31 +00:00
import { useUserProfile } from "Hooks/useUserProfile";
2023-02-07 13:32:32 +00:00
import SendSats from "Element/SendSats";
2023-04-18 09:28:19 +00:00
import Icon from "Icons/Icon";
2023-01-19 00:03:24 +00:00
2023-04-18 09:28:19 +00:00
const ZapButton = ({ pubkey, lnurl, children }: { pubkey: HexKey; lnurl?: string; children?: React.ReactNode }) => {
2023-02-07 19:47:57 +00:00
const profile = useUserProfile(pubkey);
const [zap, setZap] = useState(false);
2023-02-25 21:18:36 +00:00
const service = lnurl ?? (profile?.lud16 || profile?.lud06);
if (!service) return null;
2023-01-19 00:03:24 +00:00
return (
<>
2023-04-18 09:28:19 +00:00
<div className="zap-button flex" onClick={() => setZap(true)}>
<Icon name="zap" className={children ? "mr5" : ""} size={15} />
{children}
</div>
<SendSats
target={profile?.display_name || profile?.name}
2023-02-25 21:18:36 +00:00
lnurl={service}
show={zap}
onClose={() => setZap(false)}
author={pubkey}
/>
</>
);
};
2023-01-19 00:03:24 +00:00
2023-01-19 11:14:41 +00:00
export default ZapButton;