diff --git a/src/js/components/events/note/Note.tsx b/src/js/components/events/note/Note.tsx index 0a37605a..fa180dbd 100644 --- a/src/js/components/events/note/Note.tsx +++ b/src/js/components/events/note/Note.tsx @@ -6,7 +6,7 @@ import { Link, route } from 'preact-router'; import InfiniteScroll from '@/components/helpers/InfiniteScroll'; import PubSub from '@/nostr/PubSub'; import { getEventReplyingTo, getEventRoot } from '@/nostr/utils'; -import SortedMap from '@/utils/SortedMap'; +import SortedMap from '@/utils/SortedMap/SortedMap.tsx'; import Key from '../../../nostr/Key'; import { translate as t } from '../../../translations/Translation.mjs'; diff --git a/src/js/nostr/Key.ts b/src/js/nostr/Key.ts index b93dc71c..ed56011d 100644 --- a/src/js/nostr/Key.ts +++ b/src/js/nostr/Key.ts @@ -9,7 +9,7 @@ import { } from 'nostr-tools'; import { route } from 'preact-router'; -import { PublicKey } from '@/utils/Hex.ts'; +import { PublicKey } from '@/utils/Hex/Hex.ts'; import localState from '../state/LocalState.ts'; import Helpers from '../utils/Helpers'; diff --git a/src/js/nostr/hooks/useSubscribe.ts b/src/js/nostr/hooks/useSubscribe.ts index 6c13226b..06452191 100644 --- a/src/js/nostr/hooks/useSubscribe.ts +++ b/src/js/nostr/hooks/useSubscribe.ts @@ -4,7 +4,7 @@ import { Event } from 'nostr-tools'; import Filter from '@/nostr/Filter.ts'; import PubSub from '@/nostr/PubSub.ts'; -import SortedMap from '@/utils/SortedMap.tsx'; +import SortedMap from '@/utils/SortedMap/SortedMap.tsx'; interface SubscribeOptions { filter: Filter; diff --git a/src/js/utils/Hex.test.ts b/src/js/utils/Hex/Hex.test.ts similarity index 62% rename from src/js/utils/Hex.test.ts rename to src/js/utils/Hex/Hex.test.ts index b48c6940..cd1ca513 100644 --- a/src/js/utils/Hex.test.ts +++ b/src/js/utils/Hex/Hex.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import { EventID, PublicKey } from '@/utils/Hex'; +import { EventID, PublicKey } from '@/utils/Hex/Hex.ts'; describe('PublicKey', () => { it('should convert npub bech32 to hex', () => { @@ -54,4 +54,38 @@ describe('EventID', () => { expect(eventId.toHex()).toEqual(noteHex); expect(eventId.toBech32()).toEqual(noteBech32); }); + + it('should init from hex', () => { + const hex = '7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94'; + const eventId = new EventID(hex); + expect(eventId.toHex()).toEqual(hex); + expect(eventId.toBech32()).toEqual( + 'note1wdyajan9c9d72wanqe2l34lxgdu3q5esglhquusfkg34fqq6462qh4cjd5', + ); + }); + + it('should fail with too long hex', () => { + const hex = + '7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae947349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94'; + expect(() => new EventID(hex)).toThrow(); + }); + + it('equals(hexStr)', () => { + const hex = '7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94'; + const eventId = new EventID(hex); + expect(eventId.equals(hex)).toEqual(true); + }); + + it('equals(EventID)', () => { + const hex = '7349d97665c15be53bb30655f8d7e6437910533047ee0e7209b22354801aae94'; + const eventId = new EventID(hex); + const eventId2 = new EventID(hex); + expect(eventId.equals(eventId2)).toEqual(true); + }); + + it('equals(bech32)', () => { + const bech32 = 'note1wdyajan9c9d72wanqe2l34lxgdu3q5esglhquusfkg34fqq6462qh4cjd5'; + const eventId = new EventID(bech32); + expect(eventId.equals(bech32)).toEqual(true); + }); }); diff --git a/src/js/utils/Hex.ts b/src/js/utils/Hex/Hex.ts similarity index 100% rename from src/js/utils/Hex.ts rename to src/js/utils/Hex/Hex.ts diff --git a/src/js/utils/SortedMap.test.ts b/src/js/utils/SortedMap/SortedMap.test.ts similarity index 97% rename from src/js/utils/SortedMap.test.ts rename to src/js/utils/SortedMap/SortedMap.test.ts index 812af213..7f6fc4ae 100644 --- a/src/js/utils/SortedMap.test.ts +++ b/src/js/utils/SortedMap/SortedMap.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; -import RBSortedMap from '../../../tests/RBSortedMap.ts'; +import RBSortedMap from '../../../../tests/RBSortedMap.ts'; import SortedMap from './SortedMap.tsx'; diff --git a/src/js/utils/SortedMap.tsx b/src/js/utils/SortedMap/SortedMap.tsx similarity index 100% rename from src/js/utils/SortedMap.tsx rename to src/js/utils/SortedMap/SortedMap.tsx diff --git a/src/js/views/Note.tsx b/src/js/views/Note.tsx index 8f76631d..d8d52a3f 100644 --- a/src/js/views/Note.tsx +++ b/src/js/views/Note.tsx @@ -1,7 +1,7 @@ import { useEffect } from 'preact/hooks'; import { route } from 'preact-router'; -import { EventID } from '@/utils/Hex.ts'; +import { EventID } from '@/utils/Hex/Hex.ts'; import View from '@/views/View.tsx'; import CreateNoteForm from '../components/create/CreateNoteForm'; diff --git a/src/js/views/chat/ChatList.tsx b/src/js/views/chat/ChatList.tsx index 87ab5ba3..c0a736be 100644 --- a/src/js/views/chat/ChatList.tsx +++ b/src/js/views/chat/ChatList.tsx @@ -5,7 +5,7 @@ import InfiniteScroll from '@/components/helpers/InfiniteScroll'; import Key from '../../nostr/Key'; import localState from '../../state/LocalState.ts'; import { translate as t } from '../../translations/Translation.mjs'; -import SortedMap from '../../utils/SortedMap'; +import SortedMap from '../../utils/SortedMap/SortedMap.tsx'; import ChatListItem from './ChatListItem'; import NewChatButton from './NewChatButton'; diff --git a/src/js/views/chat/ChatMessages.tsx b/src/js/views/chat/ChatMessages.tsx index 413e02fd..de38473f 100644 --- a/src/js/views/chat/ChatMessages.tsx +++ b/src/js/views/chat/ChatMessages.tsx @@ -14,7 +14,7 @@ import PubSub from '../../nostr/PubSub'; import localState from '../../state/LocalState.ts'; import { translate as t } from '../../translations/Translation.mjs'; import Helpers from '../../utils/Helpers'; -import SortedMap from '../../utils/SortedMap'; +import SortedMap from '../../utils/SortedMap/SortedMap.tsx'; import ChatMessageForm from './ChatMessageForm'; import { addGroup, sendSecretInvite } from './NewChat'; diff --git a/src/js/views/profile/Profile.tsx b/src/js/views/profile/Profile.tsx index 351231fd..5e439edb 100644 --- a/src/js/views/profile/Profile.tsx +++ b/src/js/views/profile/Profile.tsx @@ -5,7 +5,7 @@ import SimpleImageModal from '@/components/modal/Image.tsx'; import { useProfile } from '@/nostr/hooks/useProfile.ts'; import { getEventReplyingTo, isRepost } from '@/nostr/utils.ts'; import useLocalState from '@/state/useLocalState.ts'; -import { PublicKey } from '@/utils/Hex.ts'; +import { PublicKey } from '@/utils/Hex/Hex.ts'; import ProfileHelmet from '@/views/profile/Helmet.tsx'; import Feed from '../../components/feed/Feed.tsx'; diff --git a/tests/SortedMap.bench.ts b/tests/SortedMap.bench.ts index a7f73bd0..98ffff6f 100644 --- a/tests/SortedMap.bench.ts +++ b/tests/SortedMap.bench.ts @@ -1,7 +1,7 @@ import { Event } from 'nostr-tools'; import { bench, describe } from 'vitest'; -import SortedMap from '@/utils/SortedMap.tsx'; +import SortedMap from '@/utils/SortedMap/SortedMap.tsx'; import events from './events.json'; import RBSortedMap from './RBSortedMap.ts';