Casual refactor of entire eventBuilder
This commit is contained in:
@ -41,9 +41,8 @@ export default function ChatPage() {
|
||||
}, [dmListRef.current?.scrollHeight]);
|
||||
|
||||
async function sendDm() {
|
||||
if (content) {
|
||||
if (content && publisher) {
|
||||
const ev = await publisher.sendDm(content, id);
|
||||
console.debug(ev);
|
||||
publisher.broadcast(ev);
|
||||
setContent("");
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ const HashTagsPage = () => {
|
||||
const publisher = useEventPublisher();
|
||||
|
||||
async function followTags(ts: string[]) {
|
||||
const ev = await publisher.tags(ts);
|
||||
if (ev) {
|
||||
if (publisher) {
|
||||
const ev = await publisher.tags(ts);
|
||||
publisher.broadcast(ev);
|
||||
setTags(login, ts, ev.created_at * 1000);
|
||||
}
|
||||
|
@ -63,7 +63,9 @@ export default function Layout() {
|
||||
}, [location]);
|
||||
|
||||
useEffect(() => {
|
||||
System.HandleAuth = pub.nip42Auth;
|
||||
if (pub) {
|
||||
System.HandleAuth = pub.nip42Auth;
|
||||
}
|
||||
}, [pub]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -224,7 +226,14 @@ const AccountHeader = () => {
|
||||
<Icon name="bell" />
|
||||
{hasNotifications && <span className="has-unread"></span>}
|
||||
</div>
|
||||
{profile && <Avatar user={profile} onClick={() => navigate(profileLink(profile.pubkey))} />}
|
||||
<Avatar
|
||||
user={profile}
|
||||
onClick={() => {
|
||||
if (profile) {
|
||||
navigate(profileLink(profile.pubkey));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -8,13 +8,12 @@ import { HexKey } from "@snort/nostr";
|
||||
|
||||
import { EmailRegex, MnemonicRegex } from "Const";
|
||||
import { bech32ToHex, unwrap } from "Util";
|
||||
import { generateBip39Entropy, entropyToDerivedKey } from "nip6";
|
||||
import { generateBip39Entropy, entropyToPrivateKey } from "nip6";
|
||||
import ZapButton from "Element/ZapButton";
|
||||
import useImgProxy from "Hooks/useImgProxy";
|
||||
import Icon from "Icons/Icon";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { generateNewLogin, LoginStore } from "Login";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import AsyncButton from "Element/AsyncButton";
|
||||
|
||||
import messages from "./messages";
|
||||
@ -68,7 +67,6 @@ export async function getNip05PubKey(addr: string): Promise<string> {
|
||||
|
||||
export default function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
const publisher = useEventPublisher();
|
||||
const login = useLogin();
|
||||
const [key, setKey] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
@ -117,7 +115,7 @@ export default function LoginPage() {
|
||||
throw new Error(insecureMsg);
|
||||
}
|
||||
const ent = generateBip39Entropy(key);
|
||||
const keyHex = entropyToDerivedKey(ent);
|
||||
const keyHex = entropyToPrivateKey(ent);
|
||||
LoginStore.loginWithPrivateKey(keyHex);
|
||||
} else if (secp.utils.isValidPrivateKey(key)) {
|
||||
if (!hasSubtleCrypto) {
|
||||
@ -142,7 +140,7 @@ export default function LoginPage() {
|
||||
}
|
||||
|
||||
async function makeRandomKey() {
|
||||
await generateNewLogin(publisher);
|
||||
await generateNewLogin();
|
||||
navigate("/new");
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ const Extensions = () => {
|
||||
};
|
||||
|
||||
export default function NewUserFlow() {
|
||||
const { publicKey, privateKey, generatedEntropy } = useLogin();
|
||||
const { publicKey, generatedEntropy } = useLogin();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
@ -87,10 +87,6 @@ export default function NewUserFlow() {
|
||||
<FormattedMessage {...messages.YourPubkey} />
|
||||
</h2>
|
||||
<Copy text={hexToBech32("npub", publicKey ?? "")} />
|
||||
<h2>
|
||||
<FormattedMessage {...messages.YourPrivkey} />
|
||||
</h2>
|
||||
<Copy text={hexToBech32("nsec", privateKey ?? "")} />
|
||||
<h2>
|
||||
<FormattedMessage {...messages.YourMnemonic} />
|
||||
</h2>
|
||||
|
@ -14,9 +14,8 @@ export default function NewUserName() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const onNext = async () => {
|
||||
if (username.length > 0) {
|
||||
if (username.length > 0 && publisher) {
|
||||
const ev = await publisher.metadata({ name: username });
|
||||
console.debug(ev);
|
||||
publisher.broadcast(ev);
|
||||
}
|
||||
navigate("/new/verify");
|
||||
|
@ -76,13 +76,14 @@ export default function ProfileSettings(props: ProfileSettingsProps) {
|
||||
delete userCopy["zapService"];
|
||||
console.debug(userCopy);
|
||||
|
||||
const ev = await publisher.metadata(userCopy);
|
||||
console.debug(ev);
|
||||
publisher.broadcast(ev);
|
||||
if (publisher) {
|
||||
const ev = await publisher.metadata(userCopy);
|
||||
publisher.broadcast(ev);
|
||||
|
||||
const newProfile = mapEventToProfile(ev as TaggedRawEvent);
|
||||
if (newProfile) {
|
||||
await UserCache.set(newProfile);
|
||||
const newProfile = mapEventToProfile(ev as TaggedRawEvent);
|
||||
if (newProfile) {
|
||||
await UserCache.set(newProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,10 @@ import { randomSample, unixNowMs } from "Util";
|
||||
import Relay from "Element/Relay";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { System } from "System";
|
||||
|
||||
import messages from "./messages";
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { setRelays } from "Login";
|
||||
|
||||
import messages from "./messages";
|
||||
const RelaySettingsPage = () => {
|
||||
const publisher = useEventPublisher();
|
||||
const login = useLogin();
|
||||
@ -21,16 +20,18 @@ const RelaySettingsPage = () => {
|
||||
}, [relays]);
|
||||
|
||||
async function saveRelays() {
|
||||
const ev = await publisher.saveRelays();
|
||||
publisher.broadcast(ev);
|
||||
publisher.broadcastForBootstrap(ev);
|
||||
try {
|
||||
const onlineRelays = await fetch("https://api.nostr.watch/v1/online").then(r => r.json());
|
||||
const settingsEv = await publisher.saveRelaysSettings();
|
||||
const rs = Object.keys(relays).concat(randomSample(onlineRelays, 20));
|
||||
publisher.broadcastAll(settingsEv, rs);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (publisher) {
|
||||
const ev = await publisher.contactList(login.follows.item, login.relays.item);
|
||||
publisher.broadcast(ev);
|
||||
publisher.broadcastForBootstrap(ev);
|
||||
try {
|
||||
const onlineRelays = await fetch("https://api.nostr.watch/v1/online").then(r => r.json());
|
||||
const relayList = await publisher.relayList(login.relays.item);
|
||||
const rs = Object.keys(relays).concat(randomSample(onlineRelays, 20));
|
||||
publisher.broadcastAll(relayList, rs);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,13 @@ import SnortServiceProvider, { ManageHandle } from "Nip05/SnortServiceProvider";
|
||||
export default function LNForwardAddress({ handle }: { handle: ManageHandle }) {
|
||||
const { formatMessage } = useIntl();
|
||||
const publisher = useEventPublisher();
|
||||
const sp = new SnortServiceProvider(publisher, `${ApiHost}/api/v1/n5sp`);
|
||||
|
||||
const [newAddress, setNewAddress] = useState(handle.lnAddress ?? "");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
async function startUpdate() {
|
||||
if (!publisher) return;
|
||||
|
||||
const req = {
|
||||
lnAddress: newAddress,
|
||||
};
|
||||
@ -33,6 +34,7 @@ export default function LNForwardAddress({ handle }: { handle: ManageHandle }) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sp = new SnortServiceProvider(publisher, `${ApiHost}/api/v1/n5sp`);
|
||||
const rsp = await sp.patch(handle.id, req);
|
||||
if ("error" in rsp) {
|
||||
setError(rsp.error);
|
||||
|
@ -10,13 +10,14 @@ export default function ListHandles() {
|
||||
const navigate = useNavigate();
|
||||
const publisher = useEventPublisher();
|
||||
const [handles, setHandles] = useState<Array<ManageHandle>>([]);
|
||||
const sp = new SnortServiceProvider(publisher, `${ApiHost}/api/v1/n5sp`);
|
||||
|
||||
useEffect(() => {
|
||||
loadHandles().catch(console.error);
|
||||
}, []);
|
||||
}, [publisher]);
|
||||
|
||||
async function loadHandles() {
|
||||
if (!publisher) return;
|
||||
const sp = new SnortServiceProvider(publisher, `${ApiHost}/api/v1/n5sp`);
|
||||
const list = await sp.list();
|
||||
setHandles(list as Array<ManageHandle>);
|
||||
}
|
||||
|
@ -11,13 +11,13 @@ export default function TransferHandle({ handle }: { handle: ManageHandle }) {
|
||||
const publisher = useEventPublisher();
|
||||
const navigate = useNavigate();
|
||||
const { formatMessage } = useIntl();
|
||||
const sp = new SnortServiceProvider(publisher, `${ApiHost}/api/v1/n5sp`);
|
||||
|
||||
const [newKey, setNewKey] = useState("");
|
||||
const [error, setError] = useState<Array<string>>([]);
|
||||
|
||||
async function startTransfer() {
|
||||
if (!newKey) return;
|
||||
if (!newKey || !publisher) return;
|
||||
const sp = new SnortServiceProvider(publisher, `${ApiHost}/api/v1/n5sp`);
|
||||
setError([]);
|
||||
const rsp = await sp.transfer(handle.id, newKey);
|
||||
if ("error" in rsp) {
|
||||
|
Reference in New Issue
Block a user