diff --git a/src/components/content/carousels/MessagesCarousel.js b/src/components/content/carousels/MessagesCarousel.js index 45e5bdf..7f294d8 100644 --- a/src/components/content/carousels/MessagesCarousel.js +++ b/src/components/content/carousels/MessagesCarousel.js @@ -63,15 +63,6 @@ const MessageCarousel = ({ copyToClipboard }) => { ); const messages = [ - { - title: "Welcome to the PlebDevs Platform testing phase! 👋", - description: "During this testing phase all prices will be reduced by 10x but all purchases, subscriptions, and progress will be reset on launch, cheers!", - showGithub: false, - showX: false, - showNostr: false, - showDonate: false, - showFeedback: true, - }, { title: "PlebDevs 🤝👨‍💻🤝👩‍💻🤝🧑‍💻🤝", description: "Plebdevs is open source software and is still in early development. If you have any questions drop an issue on the Github repo, or reach out to me in the Community feed.", diff --git a/src/components/feeds/MessageInput.js b/src/components/feeds/MessageInput.js index 5f3f3b5..fafc1da 100644 --- a/src/components/feeds/MessageInput.js +++ b/src/components/feeds/MessageInput.js @@ -4,15 +4,28 @@ import GenericButton from '@/components/buttons/GenericButton'; import { Panel } from 'primereact/panel'; import { useNDKContext } from "@/context/NDKContext"; import { NDKEvent } from "@nostr-dev-kit/ndk"; +import { finalizeEvent, verifyEvent } from 'nostr-tools/pure' +import { SimplePool } from 'nostr-tools/pool' +import appConfig from '@/config/appConfig'; import { useToast } from '@/hooks/useToast'; +import { useSession } from 'next-auth/react'; const MessageInput = () => { const [message, setMessage] = useState(''); const [collapsed, setCollapsed] = useState(true); const { ndk, addSigner } = useNDKContext(); const { showToast } = useToast(); + const { data: session } = useSession(); const handleSubmit = async () => { + if (session && session?.user && session.user?.privkey) { + handleManualSubmit(session.user.privkey); + } else { + handleExtensionSubmit(); + } + } + + const handleExtensionSubmit = async () => { if (!message.trim() || !ndk) return; try { @@ -33,6 +46,37 @@ const MessageInput = () => { } }; + const handleManualSubmit = async (privkey) => { + try { + let event = finalizeEvent({ + kind: 1, + created_at: Math.floor(Date.now() / 1000), + tags: [ + ['t', 'plebdevs'] + ], + content: message, + }, privkey) + + let isGood = verifyEvent(event); + + if (isGood) { + const pool = new SimplePool(); + const published = await pool.publish(appConfig.defaultRelayUrls, event); + if (published) { + showToast('success', 'Message Sent', 'Your message has been sent to the PlebDevs community.'); + setMessage(''); + } else { + showToast('error', 'Error', 'There was an error sending your message. Please try again.'); + } + } else { + showToast('error', 'Error', 'There was an error sending your message. Please try again.'); + } + } catch (error) { + console.error("Error finalizing event:", error); + showToast('error', 'Error', 'There was an error sending your message. Please try again.'); + } + } + const headerTemplate = (options) => { return (
diff --git a/src/components/profile/UserProfile.js b/src/components/profile/UserProfile.js index e657054..84cb0a5 100644 --- a/src/components/profile/UserProfile.js +++ b/src/components/profile/UserProfile.js @@ -53,6 +53,26 @@ const UserProfile = () => {
); + const menuItems = [ + ...(user?.privkey ? [{ + label: 'Copy nsec', + icon: 'pi pi-key', + command: () => { + const privkeyBuffer = Buffer.from(user.privkey, 'hex'); + copyToClipboard(nip19.nsecEncode(privkeyBuffer)); + } + }] : []), + { + label: 'Copy npub', + icon: 'pi pi-user', + command: () => { + if (user.pubkey) { + copyToClipboard(nip19.npubEncode(user?.pubkey)); + } + } + } + ]; + return ( user && (
@@ -70,8 +90,21 @@ const UserProfile = () => { height={100} className="rounded-full my-4" /> +
+ menu.current.toggle(e)} + /> + +
+

{user.username || user?.email || "Anon"}

diff --git a/src/components/profile/UserSettings.js b/src/components/profile/UserSettings.js index b7cc281..b8f00b0 100644 --- a/src/components/profile/UserSettings.js +++ b/src/components/profile/UserSettings.js @@ -2,6 +2,7 @@ import React, { useRef, useState, useEffect, useCallback } from "react"; import GenericButton from "@/components/buttons/GenericButton"; import { DataTable } from "primereact/datatable"; import { Column } from "primereact/column"; +import { Menu } from "primereact/menu"; import { useImageProxy } from "@/hooks/useImageProxy"; import { useSession } from 'next-auth/react'; import { ProgressSpinner } from "primereact/progressspinner"; @@ -25,6 +26,7 @@ const UserSettings = () => { const { ndk, userRelays, setUserRelays, reInitializeNDK } = useNDKContext(); const { data: session } = useSession(); const { returnImageProxy } = useImageProxy(); + const menu = useRef(null); const windowWidth = useWindowWidth(); const [newRelayUrl, setNewRelayUrl] = useState(""); const { showToast } = useToast(); @@ -160,6 +162,24 @@ const UserSettings = () => { ); + const menuItems = [ + ...(user?.privkey ? [{ + label: 'Copy nsec', + icon: 'pi pi-key', + command: () => { + const privkeyBuffer = Buffer.from(user.privkey, 'hex'); + copyToClipboard(nip19.nsecEncode(privkeyBuffer)); + } + }] : []), + { + label: 'Copy npub', + icon: 'pi pi-user', + command: () => { + copyToClipboard(nip19.npubEncode(user?.pubkey)); + } + } + ]; + return ( user && (
@@ -177,6 +197,18 @@ const UserSettings = () => { height={100} className="rounded-full my-4" /> +
+ menu.current.toggle(e)} + /> + +