mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-03-26 17:52:18 +01:00
replace moment with dayjs
This commit is contained in:
parent
0836872f51
commit
f383903bec
5
.changeset/new-moose-hide.md
Normal file
5
.changeset/new-moose-hide.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"nostrudel": minor
|
||||
---
|
||||
|
||||
replace momentjs with dayjs
|
@ -16,11 +16,11 @@
|
||||
"@emotion/react": "^11.11.0",
|
||||
"@emotion/styled": "^11.11.0",
|
||||
"bech32": "^2.0.0",
|
||||
"dayjs": "^1.11.8",
|
||||
"framer-motion": "^7.10.3",
|
||||
"idb": "^7.1.1",
|
||||
"identicon.js": "^2.3.3",
|
||||
"light-bolt11-decoder": "^3.0.0",
|
||||
"moment": "^2.29.4",
|
||||
"noble-secp256k1": "^1.2.14",
|
||||
"nostr-tools": "^1.11.1",
|
||||
"react": "^18.2.0",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { NostrSubscription } from "./nostr-subscription";
|
||||
import { SuperMap } from "./super-map";
|
||||
import { NostrEvent } from "../types/nostr-event";
|
||||
@ -74,9 +74,9 @@ class PubkeyEventRequestSubscription {
|
||||
this.requestNext.clear();
|
||||
|
||||
// prune pubkeys
|
||||
const timeout = moment().subtract(1, "minute");
|
||||
const timeout = dayjs().subtract(1, "minute");
|
||||
for (const [pubkey, date] of this.requestedPubkeys) {
|
||||
if (moment(date).isBefore(timeout)) {
|
||||
if (dayjs(date).isBefore(timeout)) {
|
||||
this.requestedPubkeys.delete(pubkey);
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { utils } from "nostr-tools";
|
||||
import { NostrEvent } from "../types/nostr-event";
|
||||
import { NostrQuery } from "../types/nostr-query";
|
||||
import { NostrRequest } from "./nostr-request";
|
||||
import { NostrMultiSubscription } from "./nostr-multi-subscription";
|
||||
import { PersistentSubject } from "./subject";
|
||||
import { utils } from "nostr-tools";
|
||||
|
||||
type Options = {
|
||||
name?: string;
|
||||
@ -22,7 +22,7 @@ export class TimelineLoader {
|
||||
|
||||
private seenEvents = new Set<string>();
|
||||
private subscription: NostrMultiSubscription;
|
||||
private opts: Options = { pageSize: moment.duration(1, "hour").asSeconds(), startLimit: 10 };
|
||||
private opts: Options = { pageSize: 60*60, startLimit: 10 };
|
||||
|
||||
constructor(relays: string[], query: NostrQuery, opts?: TimelineLoaderOptions) {
|
||||
this.relays = relays;
|
||||
@ -53,7 +53,7 @@ export class TimelineLoader {
|
||||
}
|
||||
|
||||
private getPageDates(page: number) {
|
||||
const start = this.events.value[0]?.created_at ?? moment().unix();
|
||||
const start = this.events.value[0]?.created_at ?? dayjs().unix();
|
||||
const until = start - page * this.opts.pageSize;
|
||||
const since = until - this.opts.pageSize;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { NostrEvent } from "../types/nostr-event";
|
||||
import { NostrQuery } from "../types/nostr-query";
|
||||
import { NostrRequest } from "./nostr-request";
|
||||
@ -7,7 +7,7 @@ import { PersistentSubject } from "./subject";
|
||||
import { utils } from "nostr-tools";
|
||||
import { truncatedId } from "../helpers/nostr-event";
|
||||
|
||||
const PAGE_SIZE = moment.duration(1, "week").asSeconds();
|
||||
const PAGE_SIZE = 60 * 60 * 24 * 7; //in seconds
|
||||
|
||||
export default class UserTimeline {
|
||||
pubkey: string;
|
||||
@ -41,7 +41,7 @@ export default class UserTimeline {
|
||||
}
|
||||
|
||||
private getPageDates(page: number) {
|
||||
const start = this.events.value[0]?.created_at ?? moment().unix();
|
||||
const start = this.events.value[0]?.created_at ?? dayjs().unix();
|
||||
const until = start - page * PAGE_SIZE;
|
||||
const since = until - PAGE_SIZE;
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
import React, { useState } from "react";
|
||||
import { Box, Button, ButtonGroup, IconButton, Text } from "@chakra-ui/react";
|
||||
import { requestProvider } from "webln";
|
||||
import { parsePaymentRequest, readablizeSats } from "../helpers/bolt11";
|
||||
import { useAsync } from "react-use";
|
||||
import dayjs from "dayjs";
|
||||
import { requestProvider } from "webln";
|
||||
import { Box, Button, ButtonGroup, IconButton, Text } from "@chakra-ui/react";
|
||||
|
||||
import { parsePaymentRequest, readablizeSats } from "../helpers/bolt11";
|
||||
import { ClipboardIcon } from "./icons";
|
||||
import moment from "moment";
|
||||
|
||||
export type InvoiceButtonProps = {
|
||||
paymentRequest: string;
|
||||
@ -37,7 +38,7 @@ export const InlineInvoiceCard = ({ paymentRequest }: InvoiceButtonProps) => {
|
||||
|
||||
if (!invoice) return <>Loading Invoice...</>;
|
||||
|
||||
const isExpired = moment(invoice.expiry).isBefore(moment());
|
||||
const isExpired = dayjs(invoice.expiry).isBefore(dayjs());
|
||||
|
||||
return (
|
||||
<Box
|
||||
@ -56,7 +57,7 @@ export const InlineInvoiceCard = ({ paymentRequest }: InvoiceButtonProps) => {
|
||||
</Box>
|
||||
<Box>
|
||||
<Text color={isExpired ? "red.400" : undefined}>
|
||||
{isExpired ? "Expired" : "Expires"}: {moment(invoice.expiry).fromNow()}
|
||||
{isExpired ? "Expired" : "Expires"}: {dayjs(invoice.expiry).fromNow()}
|
||||
</Text>
|
||||
</Box>
|
||||
<ButtonGroup>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Button, ButtonProps } from "@chakra-ui/react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { Kind } from "nostr-tools";
|
||||
import { useState } from "react";
|
||||
import { nostrPostAction } from "../../../classes/nostr-post-action";
|
||||
@ -11,7 +11,7 @@ import clientRelaysService from "../../../services/client-relays";
|
||||
import eventReactionsService from "../../../services/event-reactions";
|
||||
import { getEventRelays } from "../../../services/event-relays";
|
||||
import { DraftNostrEvent, NostrEvent } from "../../../types/nostr-event";
|
||||
import { DislikeIcon, LikeIcon } from "../../icons";
|
||||
import { LikeIcon } from "../../icons";
|
||||
|
||||
export default function ReactionButton({ note, ...props }: { note: NostrEvent } & Omit<ButtonProps, "children">) {
|
||||
const { requestSignature } = useSigningContext();
|
||||
@ -29,7 +29,7 @@ export default function ReactionButton({ note, ...props }: { note: NostrEvent }
|
||||
["e", note.id, random(eventRelays)],
|
||||
["p", note.pubkey], // TODO: pick a relay for the user
|
||||
],
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
const signed = await requestSignature(event);
|
||||
if (signed) {
|
||||
|
@ -1,13 +1,11 @@
|
||||
import { Link as RouterLink } from "react-router-dom";
|
||||
import moment from "moment";
|
||||
import { Card, CardBody, CardHeader, Flex, Heading, Link } from "@chakra-ui/react";
|
||||
import dayjs from "dayjs";
|
||||
import { Card, CardBody, CardHeader, Flex, Heading } from "@chakra-ui/react";
|
||||
|
||||
import { NoteContents } from "./note-contents";
|
||||
import { NostrEvent } from "../../types/nostr-event";
|
||||
import { UserAvatarLink } from "../user-avatar-link";
|
||||
import { UserLink } from "../user-link";
|
||||
import { UserDnsIdentityIcon } from "../user-dns-identity-icon";
|
||||
import { Bech32Prefix, normalizeToBech32 } from "../../helpers/nip19";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import useSubject from "../../hooks/use-subject";
|
||||
import appSettings from "../../services/app-settings";
|
||||
import EventVerificationIcon from "../event-verification-icon";
|
||||
@ -31,7 +29,7 @@ export default function EmbeddedNote({ note }: { note: NostrEvent }) {
|
||||
<Flex grow={1} />
|
||||
{showSignatureVerification && <EventVerificationIcon event={note} />}
|
||||
<NoteLink noteId={note.id} color="current" whiteSpace="nowrap">
|
||||
{moment(convertTimestampToDate(note.created_at)).fromNow()}
|
||||
{dayjs.unix(note.created_at).fromNow()}
|
||||
</NoteLink>
|
||||
</Flex>
|
||||
</CardHeader>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { useMemo } from "react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import {
|
||||
Box,
|
||||
ButtonGroup,
|
||||
@ -21,7 +21,6 @@ import { NoteRelays } from "./note-relays";
|
||||
import { useIsMobile } from "../../hooks/use-is-mobile";
|
||||
import { UserLink } from "../user-link";
|
||||
import { UserDnsIdentityIcon } from "../user-dns-identity-icon";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import ReactionButton from "./buttons/reaction-button";
|
||||
import NoteZapButton from "./note-zap-button";
|
||||
import { ExpandProvider } from "./expanded";
|
||||
@ -63,7 +62,7 @@ export const Note = React.memo(({ event, maxHeight, variant = "outline" }: NoteP
|
||||
<Flex grow={1} />
|
||||
{showSignatureVerification && <EventVerificationIcon event={event} />}
|
||||
<NoteLink noteId={event.id} whiteSpace="nowrap" color="current">
|
||||
{moment(convertTimestampToDate(event.created_at)).fromNow()}
|
||||
{dayjs.unix(event.created_at).fromNow()}
|
||||
</NoteLink>
|
||||
</Flex>
|
||||
</CardHeader>
|
||||
|
@ -15,14 +15,12 @@ import {
|
||||
import { NostrEvent } from "../../types/nostr-event";
|
||||
import { UserAvatarLink } from "../user-avatar-link";
|
||||
import { UserLink } from "../user-link";
|
||||
import moment from "moment";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import dayjs from "dayjs";
|
||||
import { DislikeIcon, LightningIcon, LikeIcon } from "../icons";
|
||||
import { parseZapNote } from "../../helpers/zaps";
|
||||
import { readablizeSats } from "../../helpers/bolt11";
|
||||
import useEventReactions from "../../hooks/use-event-reactions";
|
||||
import useEventZaps from "../../hooks/use-event-zaps";
|
||||
import { NoteContents } from "./note-contents";
|
||||
import { useIsMobile } from "../../hooks/use-is-mobile";
|
||||
|
||||
function getReactionIcon(content: string) {
|
||||
@ -44,7 +42,7 @@ const ReactionEvent = React.memo(({ event }: { event: NostrEvent }) => (
|
||||
<UserLink pubkey={event.pubkey} />
|
||||
</Flex>
|
||||
<Text ml="auto" flexShrink={0}>
|
||||
{moment(convertTimestampToDate(event.created_at)).fromNow()}
|
||||
{dayjs.unix(event.created_at).fromNow()}
|
||||
</Text>
|
||||
</Flex>
|
||||
));
|
||||
@ -67,7 +65,7 @@ const ZapEvent = React.memo(({ event }: { event: NostrEvent }) => {
|
||||
{readablizeSats(payment.amount / 1000)} <LightningIcon color="yellow.500" />
|
||||
</Text>
|
||||
{/* <Text width="35%" textAlign="right">
|
||||
{moment(convertTimestampToDate(event.created_at)).fromNow()}
|
||||
{dayjs.unix(event.created_at).fromNow()}
|
||||
</Text> */}
|
||||
</Flex>
|
||||
<Text>{request.content}</Text>
|
||||
|
@ -12,7 +12,7 @@ import {
|
||||
IconButton,
|
||||
useToast,
|
||||
} from "@chakra-ui/react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import React, { useRef, useState } from "react";
|
||||
import { useList } from "react-use";
|
||||
import { nostrPostAction, PostResult } from "../../classes/nostr-post-action";
|
||||
@ -34,12 +34,12 @@ function emptyDraft(): DraftNostrEvent {
|
||||
content: "",
|
||||
kind: 1,
|
||||
tags: [],
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
}
|
||||
|
||||
function finalizeNote(draft: DraftNostrEvent) {
|
||||
const updatedDraft: DraftNostrEvent = { ...draft, tags: Array.from(draft.tags), created_at: moment().unix() };
|
||||
const updatedDraft: DraftNostrEvent = { ...draft, tags: Array.from(draft.tags), created_at: dayjs().unix() };
|
||||
|
||||
// replace all occurrences of @npub and @note
|
||||
while (true) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { decode, Section, AmountSection, DescriptionSection, TimestampSection } from "light-bolt11-decoder";
|
||||
import { convertTimestampToDate } from "./date";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
export type ParsedInvoice = {
|
||||
paymentRequest: string;
|
||||
@ -27,8 +27,8 @@ export function parsePaymentRequest(paymentRequest: string): ParsedInvoice {
|
||||
paymentRequest: decoded.paymentRequest,
|
||||
description: decoded.sections.find(isDescription)?.value ?? "",
|
||||
amount: parseInt(decoded.sections.find(isAmount)?.value ?? "0"),
|
||||
timestamp: convertTimestampToDate(timestamp),
|
||||
expiry: convertTimestampToDate(timestamp + decoded.expiry),
|
||||
timestamp: dayjs.unix(timestamp).toDate(),
|
||||
expiry: dayjs.unix(timestamp + decoded.expiry).toDate(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
export function convertTimestampToDate(timestamp: number) {
|
||||
return new Date(timestamp * 1000);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { getEventRelays } from "../services/event-relays";
|
||||
import { DraftNostrEvent, isETag, isPTag, NostrEvent, RTag, Tag } from "../types/nostr-event";
|
||||
import { RelayConfig, RelayMode } from "../classes/relay";
|
||||
@ -149,7 +149,7 @@ export function buildReply(event: NostrEvent, account = accountService.current.v
|
||||
// TODO: be smarter about picking relay
|
||||
tags,
|
||||
content: "",
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ export function buildRepost(event: NostrEvent): DraftNostrEvent {
|
||||
kind: 6, //Kind.Repost
|
||||
tags,
|
||||
content: "",
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ export function buildQuoteRepost(event: NostrEvent): DraftNostrEvent {
|
||||
kind: Kind.Text,
|
||||
tags,
|
||||
content: "#[0]",
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ export function buildDeleteEvent(eventIds: string[], reason = ""): DraftNostrEve
|
||||
kind: Kind.EventDeletion,
|
||||
tags: eventIds.map((id) => ["e", id]),
|
||||
content: reason,
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,11 @@ import { createRoot } from "react-dom/client";
|
||||
import { App } from "./app";
|
||||
import { Providers } from "./providers";
|
||||
|
||||
// setup dayjs
|
||||
import dayjs from "dayjs";
|
||||
import relativeTimePlugin from "dayjs/plugin/relativeTime";
|
||||
dayjs.extend(relativeTimePlugin);
|
||||
|
||||
// register nostr: protocol handler
|
||||
if (import.meta.env.PROD) {
|
||||
try {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { nostrPostAction } from "../classes/nostr-post-action";
|
||||
import { PersistentSubject, Subject } from "../classes/subject";
|
||||
import { DraftNostrEvent, PTag } from "../types/nostr-event";
|
||||
@ -66,7 +66,7 @@ function getDraftEvent(): DraftNostrEvent {
|
||||
// https://github.com/nostr-protocol/nips/blob/master/02.md
|
||||
// some other clients are using the content to store relays.
|
||||
content: "",
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { nostrPostAction } from "../classes/nostr-post-action";
|
||||
import { unique } from "../helpers/array";
|
||||
import { DraftNostrEvent, RTag } from "../types/nostr-event";
|
||||
@ -79,7 +79,7 @@ class ClientRelayService {
|
||||
kind: 10002,
|
||||
tags: rTags,
|
||||
content: "",
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
|
||||
const newRelayUrls = newRelays.filter((r) => r.mode & RelayMode.WRITE).map((r) => r.url);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import moment, { MomentInput } from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { NostrMultiSubscription } from "../classes/nostr-multi-subscription";
|
||||
import { NostrEvent, isPTag } from "../types/nostr-event";
|
||||
import clientRelaysService from "./client-relays";
|
||||
@ -7,7 +7,6 @@ import { SuperMap } from "../classes/super-map";
|
||||
import { PersistentSubject } from "../classes/subject";
|
||||
import accountService from "./account";
|
||||
import { NostrQuery } from "../types/nostr-query";
|
||||
import { convertTimestampToDate } from "../helpers/date";
|
||||
import { Kind } from "nostr-tools";
|
||||
|
||||
export function getMessageRecipient(event: NostrEvent): string | undefined {
|
||||
@ -47,14 +46,14 @@ class DirectMessagesService {
|
||||
this.incomingSub.setQuery({
|
||||
...this.incomingSub.query,
|
||||
"#p": [newAccount.pubkey],
|
||||
since: moment().subtract(1, "day").unix(),
|
||||
since: dayjs().subtract(1, "day").unix(),
|
||||
});
|
||||
}
|
||||
if (this.outgoingSub.query) {
|
||||
this.outgoingSub.setQuery({
|
||||
...this.outgoingSub.query,
|
||||
authors: [newAccount.pubkey],
|
||||
since: moment().subtract(1, "day").unix(),
|
||||
since: dayjs().subtract(1, "day").unix(),
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -91,11 +90,11 @@ class DirectMessagesService {
|
||||
return this.messages.size;
|
||||
}
|
||||
|
||||
loadDateRange(from: MomentInput) {
|
||||
loadDateRange(from: dayjs.ConfigType) {
|
||||
const account = accountService.current.value;
|
||||
if (!account) return;
|
||||
|
||||
if (this.incomingSub.query?.since && moment(convertTimestampToDate(this.incomingSub.query.since)).isBefore(from)) {
|
||||
if (this.incomingSub.query?.since && dayjs.unix(this.incomingSub.query.since).isBefore(from)) {
|
||||
// "since" is already set on the subscription and its older than "from"
|
||||
return;
|
||||
}
|
||||
@ -103,14 +102,14 @@ class DirectMessagesService {
|
||||
const incomingQuery: NostrQuery = {
|
||||
kinds: [Kind.EncryptedDirectMessage],
|
||||
"#p": [account.pubkey],
|
||||
since: moment(from).unix(),
|
||||
since: dayjs(from).unix(),
|
||||
};
|
||||
this.incomingSub.setQuery(incomingQuery);
|
||||
|
||||
const outgoingQuery: NostrQuery = {
|
||||
kinds: [Kind.EncryptedDirectMessage],
|
||||
authors: [account.pubkey],
|
||||
since: moment(from).unix(),
|
||||
since: dayjs(from).unix(),
|
||||
};
|
||||
this.outgoingSub.setQuery(outgoingQuery);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import db from "./db";
|
||||
|
||||
function parseAddress(address: string): { name?: string; domain?: string } {
|
||||
@ -62,7 +62,7 @@ async function fetchIdentity(address: string) {
|
||||
const inMemoryCache = new Map<string, DnsIdentity>();
|
||||
|
||||
async function addToCache(domain: string, json: IdentityJson) {
|
||||
const now = moment().unix();
|
||||
const now = dayjs().unix();
|
||||
const transaction = db.transaction("dnsIdentifiers", "readwrite");
|
||||
|
||||
for (const name of Object.keys(json.names)) {
|
||||
@ -98,7 +98,7 @@ async function pruneCache() {
|
||||
const keys = await db.getAllKeysFromIndex(
|
||||
"dnsIdentifiers",
|
||||
"updated",
|
||||
IDBKeyRange.upperBound(moment().subtract(1, "day").unix())
|
||||
IDBKeyRange.upperBound(dayjs().subtract(1, "day").unix())
|
||||
);
|
||||
|
||||
for (const pubkey of keys) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { SuperMap } from "../classes/super-map";
|
||||
import db from "./db";
|
||||
|
||||
@ -121,7 +121,7 @@ class RelayScoreboardService {
|
||||
// relayTimeouts = new SuperMap<string, IncidentMeasure>((relay) => new IncidentMeasure(relay));
|
||||
|
||||
prune() {
|
||||
const cutOff = moment().subtract(1, "week").toDate();
|
||||
const cutOff = dayjs().subtract(1, "week").toDate();
|
||||
for (const [relay, measure] of this.relayResponseTimes) measure.prune(cutOff);
|
||||
for (const [relay, measure] of this.relayEjectTime) measure.prune(cutOff);
|
||||
for (const [relay, measure] of this.relayConnectionTime) measure.prune(cutOff);
|
||||
|
@ -3,7 +3,7 @@ import { DraftNostrEvent, NostrEvent } from "../types/nostr-event";
|
||||
import { SuperMap } from "../classes/super-map";
|
||||
import { PersistentSubject } from "../classes/subject";
|
||||
import { safeJson } from "../helpers/parse";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { ColorMode } from "@chakra-ui/react";
|
||||
import db from "./db";
|
||||
|
||||
@ -98,7 +98,7 @@ class UserAppSettings {
|
||||
kind: 30078,
|
||||
tags: [["d", DTAG]],
|
||||
content: JSON.stringify(settings),
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Box, Button, Card, CardBody, CardProps, Flex, IconButton, Spacer, Text, Textarea } from "@chakra-ui/react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { Kind } from "nostr-tools";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link, Navigate, useParams } from "react-router-dom";
|
||||
@ -7,7 +7,6 @@ import { nostrPostAction } from "../../classes/nostr-post-action";
|
||||
import { ArrowLeftSIcon } from "../../components/icons";
|
||||
import { UserAvatar } from "../../components/user-avatar";
|
||||
import { UserLink } from "../../components/user-link";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import { normalizeToHex } from "../../helpers/nip19";
|
||||
import { useCurrentAccount } from "../../hooks/use-current-account";
|
||||
import { useIsMobile } from "../../hooks/use-is-mobile";
|
||||
@ -38,7 +37,7 @@ function Message({ event }: { event: NostrEvent } & Omit<CardProps, "children">)
|
||||
return (
|
||||
<Flex direction="column">
|
||||
<Text size="sm" textAlign={isOwnMessage ? "right" : "left"} px="2">
|
||||
{moment(convertTimestampToDate(event.created_at)).fromNow()}
|
||||
{dayjs.unix(event.created_at).fromNow()}
|
||||
</Text>
|
||||
<Card size="sm" mr={isOwnMessage ? 0 : "8"} ml={isOwnMessage ? "8" : 0}>
|
||||
<CardBody position="relative">
|
||||
@ -63,14 +62,14 @@ function DirectMessageChatPage() {
|
||||
const { requestEncrypt, requestSignature } = useSigningContext();
|
||||
const isMobile = useIsMobile();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [from, setFrom] = useState(moment().subtract(1, "week"));
|
||||
const [from, setFrom] = useState(dayjs().subtract(1, "week"));
|
||||
const [content, setContent] = useState<string>("");
|
||||
|
||||
useEffect(() => directMessagesService.loadDateRange(from), [from]);
|
||||
|
||||
const loadMore = () => {
|
||||
setLoading(true);
|
||||
setFrom((date) => moment(date).subtract(1, "week"));
|
||||
setFrom((date) => dayjs(date).subtract(1, "week"));
|
||||
setTimeout(() => {
|
||||
setLoading(false);
|
||||
}, 1000);
|
||||
@ -87,7 +86,7 @@ function DirectMessageChatPage() {
|
||||
kind: Kind.EncryptedDirectMessage,
|
||||
content: encrypted,
|
||||
tags: [["p", pubkey]],
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
};
|
||||
const signed = await requestSignature(event);
|
||||
if (!signed) return;
|
||||
|
@ -13,11 +13,10 @@ import {
|
||||
LinkOverlay,
|
||||
Text,
|
||||
} from "@chakra-ui/react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link as RouterLink } from "react-router-dom";
|
||||
import { UserAvatar } from "../../components/user-avatar";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import { Bech32Prefix, normalizeToBech32 } from "../../helpers/nip19";
|
||||
import { getUserDisplayName } from "../../helpers/user-metadata";
|
||||
import useSubject from "../../hooks/use-subject";
|
||||
@ -39,9 +38,7 @@ function ContactCard({ pubkey }: { pubkey: string }) {
|
||||
<UserAvatar pubkey={pubkey} />
|
||||
<Flex direction="column" gap="1" overflow="hidden" flex={1}>
|
||||
<Text flex={1}>{getUserDisplayName(metadata, pubkey)}</Text>
|
||||
{messages[0] && (
|
||||
<Text flexShrink={0}>{moment(convertTimestampToDate(messages[0].created_at)).fromNow()}</Text>
|
||||
)}
|
||||
{messages[0] && <Text flexShrink={0}>{dayjs.unix(messages[0].created_at).fromNow()}</Text>}
|
||||
</Flex>
|
||||
</CardBody>
|
||||
<LinkOverlay as={RouterLink} to={`/dm/${npub ?? pubkey}`} />
|
||||
@ -51,7 +48,7 @@ function ContactCard({ pubkey }: { pubkey: string }) {
|
||||
|
||||
function DirectMessagesPage() {
|
||||
const isMobile = useIsMobile();
|
||||
const [from, setFrom] = useState(moment().subtract(2, "days"));
|
||||
const [from, setFrom] = useState(dayjs().subtract(2, "days"));
|
||||
const conversations = useSubject(directMessagesService.conversations);
|
||||
|
||||
useEffect(() => directMessagesService.loadDateRange(from), [from]);
|
||||
@ -59,7 +56,7 @@ function DirectMessagesPage() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const loadMore = () => {
|
||||
setLoading(true);
|
||||
setFrom((date) => moment(date).subtract(2, "days"));
|
||||
setFrom((date) => dayjs(date).subtract(2, "days"));
|
||||
setTimeout(() => {
|
||||
setLoading(false);
|
||||
}, 1000);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
import { Button, Flex, Spinner } from "@chakra-ui/react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { Note } from "../../components/note";
|
||||
import { useTimelineLoader } from "../../hooks/use-timeline-loader";
|
||||
import { isReply, truncatedId } from "../../helpers/nostr-event";
|
||||
@ -72,8 +72,8 @@ function DiscoverTabBody() {
|
||||
const { events, loading, loadMore } = useTimelineLoader(
|
||||
`${truncatedId(account.pubkey)}-discover`,
|
||||
relays,
|
||||
{ authors: throttledPubkeys, kinds: [1], since: moment().subtract(1, "hour").unix() },
|
||||
{ pageSize: moment.duration(1, "hour").asSeconds(), enabled: throttledPubkeys.length > 0 }
|
||||
{ authors: throttledPubkeys, kinds: [1], since: dayjs().subtract(1, "hour").unix() },
|
||||
{ pageSize: 60 * 60, enabled: throttledPubkeys.length > 0 }
|
||||
);
|
||||
|
||||
const timeline = events.filter((e) => !isReply(e));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Button, Flex, FormControl, FormLabel, Spinner, Switch } from "@chakra-ui/react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { Note } from "../../components/note";
|
||||
import { isReply, truncatedId } from "../../helpers/nostr-event";
|
||||
import { useTimelineLoader } from "../../hooks/use-timeline-loader";
|
||||
@ -28,8 +28,8 @@ function FollowingTabBody() {
|
||||
const { events, loading, loadMore } = useTimelineLoader(
|
||||
`${truncatedId(account.pubkey)}-following-posts`,
|
||||
readRelays,
|
||||
{ authors: following, kinds: [1, 6], since: moment().subtract(2, "hour").unix() },
|
||||
{ pageSize: moment.duration(2, "hour").asSeconds(), enabled: following.length > 0 }
|
||||
{ authors: following, kinds: [1, 6], since: dayjs().subtract(2, "hour").unix() },
|
||||
{ pageSize: 60 * 60, enabled: following.length > 0 }
|
||||
);
|
||||
|
||||
const timeline = showReplies ? events : events.filter((e) => !isReply(e));
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { Button, Card, CardBody, CardHeader, Flex, Spinner, Text } from "@chakra-ui/react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { memo } from "react";
|
||||
import { UserAvatar } from "../../components/user-avatar";
|
||||
import { UserLink } from "../../components/user-link";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import { useReadRelayUrls } from "../../hooks/use-client-relays";
|
||||
import { useCurrentAccount } from "../../hooks/use-current-account";
|
||||
import { useTimelineLoader } from "../../hooks/use-timeline-loader";
|
||||
@ -18,7 +17,7 @@ const Kind1Notification = ({ event }: { event: NostrEvent }) => (
|
||||
<UserAvatar pubkey={event.pubkey} size="sm" />
|
||||
<UserLink pubkey={event.pubkey} />
|
||||
<NoteLink noteId={event.id} color="current" ml="auto">
|
||||
{moment(convertTimestampToDate(event.created_at)).fromNow()}
|
||||
{dayjs.unix(event.created_at).fromNow()}
|
||||
</NoteLink>
|
||||
</Flex>
|
||||
</CardHeader>
|
||||
@ -45,7 +44,7 @@ function NotificationsPage() {
|
||||
"#p": [account.pubkey],
|
||||
kinds: [1],
|
||||
},
|
||||
{ pageSize: moment.duration(1, "day").asSeconds() }
|
||||
{ pageSize: 60 * 60 * 24 }
|
||||
);
|
||||
|
||||
const timeline = events
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
Textarea,
|
||||
useToast,
|
||||
} from "@chakra-ui/react";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { nostrPostAction } from "../../classes/nostr-post-action";
|
||||
@ -225,7 +225,7 @@ export const ProfileEditView = () => {
|
||||
}
|
||||
|
||||
const draft: DraftNostrEvent = {
|
||||
created_at: moment().unix(),
|
||||
created_at: dayjs().unix(),
|
||||
kind: 0,
|
||||
content: JSON.stringify(metadata),
|
||||
tags: [],
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
Text,
|
||||
useDisclosure,
|
||||
} from "@chakra-ui/react";
|
||||
import dayjs from "dayjs";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useSearchParams, Link as RouterLink, useNavigate } from "react-router-dom";
|
||||
import { useAsync } from "react-use";
|
||||
@ -18,7 +19,6 @@ import { LightningIcon, QrCodeIcon } from "../../components/icons";
|
||||
import { UserAvatarLink } from "../../components/user-avatar-link";
|
||||
import { UserDnsIdentityIcon } from "../../components/user-dns-identity-icon";
|
||||
import ZapModal from "../../components/zap-modal";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import { truncatedId } from "../../helpers/nostr-event";
|
||||
import QrScannerModal from "../../components/qr-scanner-modal";
|
||||
import { safeDecode } from "../../helpers/nip19";
|
||||
@ -173,7 +173,7 @@ export default function SearchView() {
|
||||
</CardBody>
|
||||
<CardFooter display="flex" gap="2">
|
||||
<Text>{person.followed_count} Followers</Text>
|
||||
<Text>Created: {convertTimestampToDate(person.first_tm).toLocaleDateString()}</Text>
|
||||
<Text>Created: {dayjs.unix(person.first_tm).toString()}</Text>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
))}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React from "react";
|
||||
import { useOutletContext } from "react-router-dom";
|
||||
import moment from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionButton,
|
||||
@ -35,7 +35,6 @@ import { CopyIconButton } from "../../components/copy-icon-button";
|
||||
import { QrIconButton } from "./components/share-qr-button";
|
||||
import { UserDnsIdentityIcon } from "../../components/user-dns-identity-icon";
|
||||
import { useUserContacts } from "../../hooks/use-user-contacts";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import userTrustedStatsService from "../../services/user-trusted-stats";
|
||||
import { readablizeSats } from "../../helpers/bolt11";
|
||||
import { UserAvatar } from "../../components/user-avatar";
|
||||
@ -172,7 +171,7 @@ export default function UserAboutTab() {
|
||||
<StatLabel>Following</StatLabel>
|
||||
<StatNumber>{contacts ? readablizeSats(contacts.contacts.length) : "Unknown"}</StatNumber>
|
||||
{contacts && (
|
||||
<StatHelpText>Updated {moment(convertTimestampToDate(contacts.created_at)).fromNow()}</StatHelpText>
|
||||
<StatHelpText>Updated {dayjs.unix(contacts.created_at).fromNow()}</StatHelpText>
|
||||
)}
|
||||
</Stat>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Box, Button, Flex, Select, Spinner, Text, useDisclosure } from "@chakra-ui/react";
|
||||
import moment, { isMoment } from "moment";
|
||||
import dayjs from "dayjs";
|
||||
import { useState } from "react";
|
||||
import { useOutletContext } from "react-router-dom";
|
||||
import { ErrorBoundary, ErrorFallback } from "../../components/error-boundary";
|
||||
@ -8,7 +8,6 @@ import { NoteLink } from "../../components/note-link";
|
||||
import { UserAvatarLink } from "../../components/user-avatar-link";
|
||||
import { UserLink } from "../../components/user-link";
|
||||
import { readablizeSats } from "../../helpers/bolt11";
|
||||
import { convertTimestampToDate } from "../../helpers/date";
|
||||
import { truncatedId } from "../../helpers/nostr-event";
|
||||
import { isProfileZap, isNoteZap, parseZapNote, totalZaps } from "../../helpers/zaps";
|
||||
import { useTimelineLoader } from "../../hooks/use-timeline-loader";
|
||||
@ -48,7 +47,7 @@ const Zap = ({ zapEvent }: { zapEvent: NostrEvent }) => {
|
||||
Show message
|
||||
</Button>
|
||||
)}
|
||||
<Text ml="auto">{moment(convertTimestampToDate(request.created_at)).fromNow()}</Text>
|
||||
<Text ml="auto">{dayjs.unix(request.created_at).fromNow()}</Text>
|
||||
</Flex>
|
||||
{request.content && isOpen && <Text>{request.content}</Text>}
|
||||
</Box>
|
||||
@ -73,7 +72,7 @@ const UserZapsTab = () => {
|
||||
`${truncatedId(pubkey)}-zaps`,
|
||||
relays,
|
||||
{ "#p": [pubkey], kinds: [9735] },
|
||||
{ pageSize: moment.duration(1, "week").asSeconds() }
|
||||
{ pageSize: 60 * 60 * 24 * 7 }
|
||||
);
|
||||
|
||||
const timeline =
|
||||
@ -92,7 +91,7 @@ const UserZapsTab = () => {
|
||||
<LightningIcon color="yellow.400" />
|
||||
<Text>
|
||||
{readablizeSats(totalZaps(timeline) / 1000)} sats in the last{" "}
|
||||
{moment(convertTimestampToDate(timeline[timeline.length - 1].created_at)).fromNow(true)}
|
||||
{dayjs.unix(timeline[timeline.length - 1].created_at).fromNow(true)}
|
||||
</Text>
|
||||
</Flex>
|
||||
)}
|
||||
|
@ -3451,6 +3451,11 @@ dayjs@^1.10.4:
|
||||
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.7.tgz#4b296922642f70999544d1144a2c25730fce63e2"
|
||||
integrity sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==
|
||||
|
||||
dayjs@^1.11.8:
|
||||
version "1.11.8"
|
||||
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.8.tgz#4282f139c8c19dd6d0c7bd571e30c2d0ba7698ea"
|
||||
integrity sha512-LcgxzFoWMEPO7ggRv1Y2N31hUf2R0Vj7fuy/m+Bg1K8rr+KAs1AEy4y9jd5DXe8pbHgX+srkHNS7TH6Q6ZhYeQ==
|
||||
|
||||
debug@^3.1.0:
|
||||
version "3.2.7"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a"
|
||||
|
Loading…
x
Reference in New Issue
Block a user