bug: Fix profile update & relays for new user
This commit is contained in:
@ -7,7 +7,7 @@ import { FormattedMessage } from "react-intl";
|
||||
import { RelaySettings } from "@snort/nostr";
|
||||
import messages from "./messages";
|
||||
|
||||
import { bech32ToHex, randomSample } from "Util";
|
||||
import { bech32ToHex, randomSample, unixNowMs, unwrap } from "Util";
|
||||
import Icon from "Icons/Icon";
|
||||
import { RootState } from "State/Store";
|
||||
import { init, setRelays } from "State/Login";
|
||||
@ -19,7 +19,7 @@ import useModeration from "Hooks/useModeration";
|
||||
import { NoteCreator } from "Element/NoteCreator";
|
||||
import { db } from "Db";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { SnortPubKey } from "Const";
|
||||
import { DefaultRelays, SnortPubKey } from "Const";
|
||||
import SubDebug from "Element/SubDebug";
|
||||
import { preload } from "Cache";
|
||||
import { useDmCache } from "Hooks/useDmsCache";
|
||||
@ -129,11 +129,14 @@ export default function Layout() {
|
||||
const online: string[] = await rsp.json();
|
||||
const pickRandom = randomSample(online, 4);
|
||||
const relayObjects = pickRandom.map(a => [a, { read: true, write: true }]);
|
||||
newRelays = Object.fromEntries(relayObjects);
|
||||
newRelays = {
|
||||
...Object.fromEntries(relayObjects),
|
||||
...Object.fromEntries(DefaultRelays.entries()),
|
||||
};
|
||||
dispatch(
|
||||
setRelays({
|
||||
relays: newRelays,
|
||||
createdAt: 1,
|
||||
createdAt: unixNowMs(),
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -141,7 +144,7 @@ export default function Layout() {
|
||||
console.warn(e);
|
||||
}
|
||||
|
||||
const ev = await pub.addFollow(bech32ToHex(SnortPubKey), newRelays);
|
||||
const ev = await pub.addFollow([bech32ToHex(SnortPubKey), unwrap(publicKey)], newRelays);
|
||||
pub.broadcast(ev);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ export default function LoginPage() {
|
||||
const { formatMessage } = useIntl();
|
||||
const { proxy } = useImgProxy();
|
||||
const hasNip7 = "nostr" in window;
|
||||
const isSecure = window.location.protocol === "https:";
|
||||
const hasSubtleCrypto = window.crypto.subtle !== undefined;
|
||||
|
||||
useEffect(() => {
|
||||
if (publicKey) {
|
||||
@ -92,7 +92,7 @@ export default function LoginPage() {
|
||||
});
|
||||
try {
|
||||
if (key.startsWith("nsec")) {
|
||||
if (!isSecure) {
|
||||
if (!hasSubtleCrypto) {
|
||||
throw new Error(insecureMsg);
|
||||
}
|
||||
const hexKey = bech32ToHex(key);
|
||||
@ -108,14 +108,14 @@ export default function LoginPage() {
|
||||
const hexKey = await getNip05PubKey(key);
|
||||
dispatch(setPublicKey(hexKey));
|
||||
} else if (key.match(MnemonicRegex)) {
|
||||
if (!isSecure) {
|
||||
if (!hasSubtleCrypto) {
|
||||
throw new Error(insecureMsg);
|
||||
}
|
||||
const ent = generateBip39Entropy(key);
|
||||
const keyHex = entropyToDerivedKey(ent);
|
||||
dispatch(setPrivateKey(keyHex));
|
||||
} else if (secp.utils.isValidPrivateKey(key)) {
|
||||
if (!isSecure) {
|
||||
if (!hasSubtleCrypto) {
|
||||
throw new Error(insecureMsg);
|
||||
}
|
||||
dispatch(setPrivateKey(key));
|
||||
@ -178,7 +178,7 @@ export default function LoginPage() {
|
||||
}
|
||||
|
||||
function generateKey() {
|
||||
if (!isSecure) return;
|
||||
if (!hasSubtleCrypto) return;
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -205,7 +205,7 @@ export default function LoginPage() {
|
||||
}
|
||||
|
||||
function installExtension() {
|
||||
if (isSecure) return;
|
||||
if (hasSubtleCrypto) return;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -6,17 +6,18 @@ import { useSelector } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faShop } from "@fortawesome/free-solid-svg-icons";
|
||||
import { HexKey, TaggedRawEvent } from "@snort/nostr";
|
||||
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
import { useUserProfile } from "Hooks/useUserProfile";
|
||||
import { hexToBech32, openFile } from "Util";
|
||||
import Copy from "Element/Copy";
|
||||
import { RootState } from "State/Store";
|
||||
import { HexKey } from "@snort/nostr";
|
||||
import useFileUpload from "Upload";
|
||||
|
||||
import messages from "./messages";
|
||||
import AsyncButton from "../../Element/AsyncButton";
|
||||
import AsyncButton from "Element/AsyncButton";
|
||||
import { mapEventToProfile, UserCache } from "Cache";
|
||||
|
||||
export interface ProfileSettingsProps {
|
||||
avatar?: boolean;
|
||||
@ -80,6 +81,11 @@ export default function ProfileSettings(props: ProfileSettingsProps) {
|
||||
const ev = await publisher.metadata(userCopy);
|
||||
console.debug(ev);
|
||||
publisher.broadcast(ev);
|
||||
|
||||
const newProfile = mapEventToProfile(ev as TaggedRawEvent);
|
||||
if (newProfile) {
|
||||
await UserCache.set(newProfile);
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadFile() {
|
||||
|
Reference in New Issue
Block a user