Skip to content

Commit

Permalink
nostr types fix + compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-hickey committed May 1, 2023
1 parent 74aa6dd commit 5e7d9a2
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 19 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>Frens :)</title>
</head>
<body>
<div id="root"></div>
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"devDependencies": {
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/node": "18.13.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"@vitejs/plugin-react-swc": "^3.0.0",
Expand Down
33 changes: 20 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
getPublicKey, relayInit, SimplePool,
Event, getEventHash, signEvent, Relay,
} from "nostr-tools";
getPublicKey, relayInit, Event,
getEventHash, signEvent, Relay, UnsignedEvent,
} from 'nostr-tools';
import { useState, useEffect } from "react";
import './App.css';
import CreatePostCard from "./components/createPostCard";
Expand All @@ -20,7 +20,6 @@ export const RELAYS = [


function App() {
const [pool, setPool] = useState<SimplePool | null>(null);
const [showKeysModal, setShowKeysModal] = useState<boolean>(false);
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
const [events, setEvents] = useState<Event[]>([]);
Expand Down Expand Up @@ -50,26 +49,34 @@ function App() {
}
}, [sk, pk]);

const publishEvent = (event: Event, _sk?: string) => {
console.log(event, _sk)
event.id = getEventHash(event);
event.sig = signEvent(event, _sk ? _sk : sk);
const createEvent = (unsignedEvent: UnsignedEvent, sk: string): Event => {
const eventHash = getEventHash(unsignedEvent);
const signature = signEvent(unsignedEvent, sk);
return {
...unsignedEvent,
id: eventHash,
sig: signature,
}
}

const pub = relay.publish(event);
pub.on("ok", () => {
const publishEvent = (event: UnsignedEvent, _sk?: string) => {
console.log(event, _sk)
const signedEvent = createEvent(event, _sk ? _sk : sk ? sk : "");
const pub = relay?.publish(signedEvent);
pub?.on("ok", () => {
console.log('hit')
setIsLoggedIn(true);
});
pub.on("failed", reason => {
pub?.on("failed", (reason: string) => {
console.log(reason);
})
}

const getEvents = async () => {
let events = await relay.list([{
let events = await relay?.list([{
kinds: [1],
}]);
setEvents(events);
if (events) setEvents(events);
}


Expand Down
4 changes: 2 additions & 2 deletions src/components/authCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Dispatch, SetStateAction, useRef } from "react";
import { GiSkeletonKey } from "react-icons/gi";
import { HiPencilSquare, HiUserCircle } from "react-icons/hi2"
import { generatePrivateKey, getPublicKey, Event } from "nostr-tools";
import { generatePrivateKey, getPublicKey, UnsignedEvent } from "nostr-tools";


interface AuthCardProps {
setSk: Dispatch<SetStateAction<string | null>>,
publishEvent: (event: Event, sk?:string) => void,
publishEvent: (event: UnsignedEvent, sk?:string) => void,
setShowKeysModal: Dispatch<SetStateAction<boolean>>,
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/createPostCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Event } from "nostr-tools";
import { UnsignedEvent } from "nostr-tools";
import { useProfile } from "nostr-react";

import { useRef } from "react";
Expand All @@ -7,7 +7,7 @@ import { useRef } from "react";
interface CreatePostCardProps {
posterPK: string,
posterSK: string,
publishEvent: (event: Event) => void,
publishEvent: (event: UnsignedEvent) => void,
}

export default function CreatePostCard(props: CreatePostCardProps) {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function CreatePostCard(props: CreatePostCardProps) {
kind: 1,
created_at: Math.floor(Date.now() / 1000),
tags: [],
content: textArea?.current?.value,
content: textArea?.current?.value!,
pubkey: props.posterPK,
}

Expand Down
Loading

2 comments on commit 5e7d9a2

@vercel
Copy link

@vercel vercel bot commented on 5e7d9a2 May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

frens – ./

frens-git-master-antonio-hickey.vercel.app
frens-antonio-hickey.vercel.app
frens-rho.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5e7d9a2 May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.