Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Dec 2, 2024
1 parent f94a345 commit 4e7e856
Show file tree
Hide file tree
Showing 70 changed files with 125 additions and 118 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"start": "vite serve",
"dev": "VITE_APP_VERSION=dev vite serve",
"build": "tsc --project tsconfig.json && vite build",
"format": "prettier --ignore-path .prettierignore -w .",
"build-icons": "node ./scripts/build-icons.mjs",
"analyze": "pnpm dlx vite-bundle-visualizer -o ./stats.html",
"build-icons": "node ./scripts/build-icons.mjs"
"format": "prettier --ignore-path .prettierignore -w ."
},
"dependencies": {
"@cashu/cashu-ts": "2.0.0-rc1",
Expand Down
2 changes: 1 addition & 1 deletion src/classes/chunked-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class ChunkedRequest {
}

let filters: Filter[] = mergeFilter(this.filters, { limit: this.chunkSize });
let oldestEvent = this.getLastEvent();
const oldestEvent = this.getLastEvent();
if (oldestEvent) {
filters = mergeFilter(filters, { until: oldestEvent.created_at - 1 });
}
Expand Down
4 changes: 2 additions & 2 deletions src/classes/pubkey-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class PubkeyGraph extends EventEmitter<EventMap> {
const refCount = new Map<string, number>();
const walkLevel = (level = 0) => {
if (next.size === 0) return;
let keys = new Set(next);
const keys = new Set(next);
next.clear();

for (const key of keys) {
Expand Down Expand Up @@ -141,7 +141,7 @@ export class PubkeyGraph extends EventEmitter<EventMap> {
}

getPaths(pubkey: string, maxLength = 2) {
let paths: string[][] = [];
const paths: string[][] = [];

const walk = (p: string, maxLvl = 0, path: string[] = []) => {
if (path.includes(p)) return;
Expand Down
14 changes: 7 additions & 7 deletions src/classes/relay-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class RelayPool implements IConnectionPool {
}

async waitForOpen(relayOrUrl: string | URL | AbstractRelay, quite = true) {
let relay = this.getRelay(relayOrUrl);
const relay = this.getRelay(relayOrUrl);
if (!relay) return Promise.reject("Missing relay");

if (relay.connected) return true;
Expand All @@ -123,7 +123,7 @@ export default class RelayPool implements IConnectionPool {
}

async requestConnect(relayOrUrl: string | URL | AbstractRelay, quite = true) {
let relay = this.getRelay(relayOrUrl);
const relay = this.getRelay(relayOrUrl);
if (!relay) return;

if (!relay.connected && !offlineMode.value) {
Expand All @@ -144,11 +144,11 @@ export default class RelayPool implements IConnectionPool {
}

getRelayAuthStorageKey(relayOrUrl: string | URL | AbstractRelay) {
let relay = this.getRelay(relayOrUrl);
const relay = this.getRelay(relayOrUrl);
return `${relay!.url}-auth-mode`;
}
getRelayAuthMode(relayOrUrl: string | URL | AbstractRelay): RelayAuthMode | undefined {
let relay = this.getRelay(relayOrUrl);
const relay = this.getRelay(relayOrUrl);
if (!relay) return;

const defaultMode = localSettings.defaultAuthenticationMode.value;
Expand All @@ -157,7 +157,7 @@ export default class RelayPool implements IConnectionPool {
return mode || defaultMode;
}
setRelayAuthMode(relayOrUrl: string | URL | AbstractRelay, mode: RelayAuthMode) {
let relay = this.getRelay(relayOrUrl);
const relay = this.getRelay(relayOrUrl);
if (!relay) return;

localStorage.setItem(this.getRelayAuthStorageKey(relay), mode);
Expand All @@ -169,7 +169,7 @@ export default class RelayPool implements IConnectionPool {
sign: Parameters<AbstractRelay["auth"]>[0],
quite = true,
) {
let relay = this.getRelay(relayOrUrl);
const relay = this.getRelay(relayOrUrl);
if (!relay) return;

const pending = this.pendingAuth.get(relay);
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class RelayPool implements IConnectionPool {
}

canSubscribe(relayOrUrl: string | URL | AbstractRelay) {
let relay = this.getRelay(relayOrUrl);
const relay = this.getRelay(relayOrUrl);
if (!relay) return false;

return this.authForSubscribe.get(relay).value !== false;
Expand Down
2 changes: 1 addition & 1 deletion src/classes/webrtc/nostr-webrtc-peer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export default class NostrWebRTCPeer extends EventEmitter<EventMap> {

this.log(`Got ${candidates.length} candidates`);

for (let candidate of candidates) {
for (const candidate of candidates) {
await pc.addIceCandidate(candidate);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/classes/webrtc/webrtc-relay-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class WebRtcRelayServer extends EventEmitter<EventMap> {
handleCloseMessage(data: any[]) {
const [_, id] = data as [string, string, ...Filter[]];

let sub = this.subscriptions.get(id);
const sub = this.subscriptions.get(id);
if (sub) {
sub.close();
this.subscriptions.delete(id);
Expand Down
4 changes: 2 additions & 2 deletions src/components/content/links/youtube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function renderYoutubePlaylistURL(match: URL) {

function YoutubeVideoEmbed({ url }: { url: URL }) {
const { youtubeRedirect } = useAppSettings();
var videoId = url.searchParams.get("v");
let videoId = url.searchParams.get("v");
if (url.hostname === "youtu.be") videoId = url.pathname.split("/")[1];
if (!videoId) return null;

Expand All @@ -74,7 +74,7 @@ export function renderYoutubeVideoURL(match: URL) {
if (!YOUTUBE_DOMAINS.includes(match.hostname)) return null;
if (match.pathname.startsWith("/live")) return null;

var videoId = match.searchParams.get("v");
let videoId = match.searchParams.get("v");
if (match.hostname === "youtu.be") videoId = match.pathname.split("/")[1];
if (!videoId) return null;

Expand Down
2 changes: 1 addition & 1 deletion src/components/debug-modal/pages/cache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function DebugEventCachePage({ event }: { event: NostrEvent }) {
const update = () => eventStore.update(event);

const renderValue = (field: symbol) => {
let value = Reflect.get(event, field);
const value = Reflect.get(event, field);

if (value instanceof Map) return JSON.stringify(Object.fromEntries(value.entries()));
if (value instanceof Set) return JSON.stringify(Array.from(value));
Expand Down
12 changes: 8 additions & 4 deletions src/components/layout/ghost/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@ function TimelineItem({ event }: { event: NostrEvent }) {

const renderContent = () => {
switch (event.kind) {
case kinds.EncryptedDirectMessage:
case kinds.EncryptedDirectMessage: {
const sender = getDMSender(event);
const recipient = getDMRecipient(event);
return (
<Text>
<UserName pubkey={sender} fontWeight="bold" /> messaged <UserName pubkey={recipient} fontWeight="bold" />
</Text>
);
case kinds.Contacts:
}
case kinds.Contacts: {
return (
<Text noOfLines={1} isTruncated>
Updated contacts
</Text>
);
case kinds.Reaction:
}
case kinds.Reaction: {
const pointer = nip25.getReactedEventPointer(event);
return (
<HoverLinkOverlay
Expand All @@ -70,12 +72,14 @@ function TimelineItem({ event }: { event: NostrEvent }) {
{event.content}
</HoverLinkOverlay>
);
default:
}
default: {
return (
<HoverLinkOverlay as={RouterLink} to={`/l/${getSharableEventAddress(event)}`} noOfLines={1} isTruncated>
{event.content}
</HoverLinkOverlay>
);
}
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/components/magic-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,6 @@ const MagicTextArea = forwardRef<HTMLTextAreaElement, TextareaProps & { instance
},
);

MagicTextArea.displayName = "MagicTextArea";

export { MagicInput, MagicTextArea as default };
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import StreamNote from "./stream-note";
import RelayRecommendation from "./relay-recommendation";
import BadgeAwardCard from "../../../views/badges/components/badge-award-card";
import { isReply } from "../../../helpers/nostr/event";
import { STREAM_KIND } from "../../../helpers/nostr/stream";
import { NostrEvent } from "../../../types/nostr-event";
import { FLARE_VIDEO_KIND } from "../../../helpers/nostr/video";
import EmbeddedFlareVideo from "../../embed-event/event-types/embedded-flare-video";
Expand Down
4 changes: 2 additions & 2 deletions src/components/timeline-page/media-timeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function ImageGallery({ images }: { images: PhotoWithEvent[] }) {

export default function MediaTimeline({ timeline }: { timeline: NostrEvent[] }) {
const images = useMemo(() => {
var images: PhotoWithEvent[] = [];
const images: PhotoWithEvent[] = [];

for (const event of timeline) {
if (event.kind === kinds.Repost || event.kind === kinds.GenericRepost) continue;
const urls = event.content.matchAll(getMatchLink());

let i = 0;
const i = 0;
for (const match of urls) {
if (isImageURL(match[0])) images.push({ event, src: match[0] });
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/user/user-follow-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ export function UserFollowButton({ pubkey, showLists, ...props }: UserFollowButt
const signed = await requestSignature(draft);
await publish("Follow", signed);
setLoading(false);
}, [contacts, requestSignature]);
}, [contacts, requestSignature, pubkey, publish]);
const handleUnfollow = useAsyncErrorHandler(async () => {
setLoading(true);
const draft = listRemovePerson(contacts || createEmptyContactList(), pubkey);
const signed = await requestSignature(draft);
await publish("Unfollow", signed);
setLoading(false);
}, [contacts, requestSignature]);
}, [contacts, requestSignature, pubkey, publish]);

if (showLists) {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/lightning.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// based on https://stackoverflow.com/a/10469752
export function humanReadableSats(sats: number) {
if (sats === 0) return "0";
var s = ["", "K", "M"];
var e = Math.floor(Math.log(sats) / Math.log(1000));
const s = ["", "K", "M"];
const e = Math.floor(Math.log(sats) / Math.log(1000));
return Math.round((sats / Math.pow(1000, e)) * 100) / 100 + s[e];
}
2 changes: 1 addition & 1 deletion src/helpers/nostr/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function getContentTagRefs(content: string, tags: Tag[]) {
break;
}

let matchingTags = tags.filter((t) => t[0] === type && t[1] === id);
const matchingTags = tags.filter((t) => t[0] === type && t[1] === id);
for (const t of matchingTags) foundTags.add(t);
}

Expand Down
6 changes: 3 additions & 3 deletions src/helpers/nostr/mailbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { cloneEvent } from "./event";

/** fixes or removes any bad r tags */
export function cleanRTags(tags: Tag[]) {
let newTags: Tag[] = [];
const newTags: Tag[] = [];
for (const tag of tags) {
if (tag[0] === "r") {
if (!tag[1]) continue;
Expand Down Expand Up @@ -39,7 +39,7 @@ export function getRelaysFromMailbox(list: NostrEvent | DraftNostrEvent): { url:
}

export function addRelayModeToMailbox(list: NostrEvent | undefined, relay: string, mode: RelayMode): DraftNostrEvent {
let draft = cloneEvent(kinds.RelayList, list);
const draft = cloneEvent(kinds.RelayList, list);
draft.tags = cleanRTags(draft.tags);

const existing = draft.tags.find((t) => t[0] === "r" && t[1] === relay) as RTag;
Expand All @@ -54,7 +54,7 @@ export function removeRelayModeFromMailbox(
relay: string,
mode: RelayMode,
): DraftNostrEvent {
let draft = cloneEvent(kinds.RelayList, list);
const draft = cloneEvent(kinds.RelayList, list);
draft.tags = cleanRTags(draft.tags);

const existing = draft.tags.find((t) => t[0] === "r" && t[1] === relay) as RTag;
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/nostr/zaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import { getZapPayment, isETag, isPTag, ProfileContent } from "applesauce-core/h
export async function getZapEndpoint(metadata: ProfileContent): Promise<null | string> {
try {
let lnurl: string = "";
let { lud06, lud16 } = metadata;
const { lud06, lud16 } = metadata;
if (lud06) {
let { words } = bech32.decode(lud06 as `${string}1${string}`, 1000);
let data = bech32.fromWords(words);
const { words } = bech32.decode(lud06 as `${string}1${string}`, 1000);
const data = bech32.fromWords(words);
lnurl = utils.utf8Decoder.decode(data);
} else if (lud16) {
let [name, domain] = lud16.split("@");
const [name, domain] = lud16.split("@");
lnurl = `https://${domain}/.well-known/lnurlp/${name}`;
} else {
return null;
}

let res = await fetch(lnurl);
let body = await res.json();
const res = await fetch(lnurl);
const body = await res.json();

if (body.allowsNostr && body.nostrPubkey) {
return body.callback;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/qrcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QrCode } from "../lib/qrcodegen";

export function drawSvgPath(qr: QrCode, border: number): string {
if (border < 0) throw new RangeError("Border must be non-negative");
let parts: Array<string> = [];
const parts: Array<string> = [];
for (let y = 0; y < qr.size; y++) {
for (let x = 0; x < qr.size; x++) {
if (qr.getModule(x, y)) parts.push(`M${x + border},${y + border}h1v1h-1z`);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function subscribeMany(relays: string[], filters: Filter[], params: Subsc
return;
}

let subscription = relay.subscribe(filters, {
const subscription = relay.subscribe(filters, {
...params,
oneose: () => handleEose(i),
onclose: (reason) => handleClose(i, reason),
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/timeline/use-number-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type NumberCache = {
export default function useNumberCache(cacheKey: string): NumberCache {
const get = useCallback(
(key: string) => {
let map = cache.get(cacheKey);
const map = cache.get(cacheKey);
if (!map) return undefined;

return map.get(key);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/open-graph-scraper/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function mediaSetup(ogObject: OgObjectInteral) {
ogObject.ogImageURL = ogObject.ogImageURL ? ogObject.ogImageURL : [];
ogObject.ogImageProperty = ogObject.ogImageProperty ? ogObject.ogImageProperty : [];
// set ogImageProperty to ogImageSecureURL if it exists
// eslint-disable-next-line max-len

ogObject.ogImageProperty =
ogObject.ogImageSecureURL.length !== 0 ? ogObject.ogImageSecureURL : ogObject.ogImageProperty;
// fall back to ogImageURL if ogImageProperty isn't set
Expand Down Expand Up @@ -150,7 +150,7 @@ export function mediaSetup(ogObject: OgObjectInteral) {
ogObject.twitterImageAlt
) {
ogObject.twitterImageSrc = ogObject.twitterImageSrc ? ogObject.twitterImageSrc : [];
// eslint-disable-next-line max-len

ogObject.twitterImageProperty = ogObject.twitterImageProperty
? ogObject.twitterImageProperty
: ogObject.twitterImageSrc; // deafult to twitterImageSrc
Expand Down
Loading

0 comments on commit 4e7e856

Please sign in to comment.