remove nostr dev kit dep

This commit is contained in:
Paul Miller
2023-10-28 02:15:17 -05:00
parent 905f18ff05
commit 8e19533e7e
6 changed files with 281 additions and 697 deletions

View File

@@ -48,8 +48,8 @@
"@capacitor/clipboard": "^5.0.6",
"@capacitor/core": "^5.2.2",
"@capacitor/filesystem": "^5.1.4",
"@capacitor/share": "^5.0.6",
"@capacitor/haptics": "^5.0.6",
"@capacitor/share": "^5.0.6",
"@capacitor/toast": "^5.0.6",
"@kobalte/core": "^0.9.8",
"@kobalte/tailwindcss": "^0.5.0",
@@ -57,7 +57,6 @@
"@mutinywallet/barcode-scanner": "5.0.0-beta.3",
"@mutinywallet/mutiny-wasm": "0.4.27",
"@mutinywallet/waila-wasm": "^0.2.1",
"@nostr-dev-kit/ndk": "^0.8.11",
"@solid-primitives/upload": "^0.0.111",
"@solid-primitives/websocket": "^1.1.0",
"@thisbeyond/solid-select": "^0.14.0",

887
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@ import rightArrow from "~/assets/icons/right-arrow.svg";
import { AmountSats, VStack } from "~/components";
import { useI18n } from "~/i18n/context";
import { useMegaStore } from "~/state/megaStore";
import { fetchZaps, getHexpubFromNpub } from "~/utils";
import { fetchZaps, hexpubFromNpub } from "~/utils";
import { timeAgo } from "~/utils/prettyPrintTime";
function Avatar(props: { image_url?: string }) {
@@ -37,7 +37,7 @@ export function NostrActivity() {
const [data, { refetch }] = createResource(state.npub, fetchZaps);
const userHexpub = getHexpubFromNpub(state.npub);
const [userHexpub] = createResource(state.npub, hexpubFromNpub);
function nameFromHexpub(hexpub: string): string {
const profile = data.latest?.profiles[hexpub];
@@ -70,7 +70,7 @@ export function NostrActivity() {
class="rounded-lg bg-m-grey-800 p-2"
classList={{
"outline outline-m-blue":
userHexpub === zap.to_hexpub
userHexpub() === zap.to_hexpub
}}
>
<div class="grid grid-cols-[1fr_auto_1fr] gap-4">

View File

@@ -1,14 +1,14 @@
import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
import { NDKKind, NDKTag, NDKUser } from "@nostr-dev-kit/ndk";
import { ResourceFetcher } from "solid-js";
import { useMegaStore } from "~/state/megaStore";
import { hexpubFromNpub, NostrKind, NostrTag } from "~/utils/nostr";
export type NostrEvent = {
created_at: number;
content: string;
tags: NDKTag[];
kind?: NDKKind | number;
tags: NostrTag[];
kind?: NostrKind | number;
pubkey: string;
id?: string;
sig?: string;
@@ -116,12 +116,6 @@ async function simpleZapFromEvent(
const PRIMAL_API = import.meta.env.VITE_PRIMAL;
export function getHexpubFromNpub(npub?: string) {
if (!npub) return;
const user = new NDKUser({ npub });
return user.hexpubkey();
}
export const fetchZaps: ResourceFetcher<
string,
{
@@ -143,7 +137,13 @@ export const fetchZaps: ResourceFetcher<
// Only have to ask the relays for follows one time
if (follows.length === 0) {
const pubkey = getHexpubFromNpub(npub);
let pubkey = undefined;
try {
pubkey = await hexpubFromNpub(npub);
} catch (err) {
console.error("Failed to get hexpub from npub");
throw err;
}
const response = await fetch(PRIMAL_API, {
method: "POST",

View File

@@ -17,3 +17,4 @@ export * from "./words";
export * from "./fetchZaps";
export * from "./vibrate";
export * from "./openLinkProgrammatically";
export * from "./nostr";

61
src/utils/nostr.ts Normal file
View File

@@ -0,0 +1,61 @@
import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
export type NostrTag = string[];
export declare enum NostrKind {
Metadata = 0,
Text = 1,
RecommendRelay = 2,
Contacts = 3,
EncryptedDirectMessage = 4,
EventDeletion = 5,
Repost = 6,
Reaction = 7,
BadgeAward = 8,
GenericRepost = 16,
ChannelCreation = 40,
ChannelMetadata = 41,
ChannelMessage = 42,
ChannelHideMessage = 43,
ChannelMuteUser = 44,
Report = 1984,
ZapRequest = 9734,
Zap = 9735,
Highlight = 9802,
MuteList = 10000,
PinList = 10001,
RelayList = 10002,
ClientAuth = 22242,
NostrConnect = 24133,
CategorizedPeopleList = 30000,
CategorizedBookmarkList = 30001,
CategorizedRelayList = 30022,
ProfileBadge = 30008,
BadgeDefinition = 30009,
MarketStall = 30017,
MarketProduct = 30018,
Article = 30023,
AppSpecificData = 30078,
Classified = 30402,
AppRecommendation = 31989,
AppHandler = 31990,
CategorizedHighlightList = 39802,
DVMJobFeedback = 65000,
DVMJobResult = 65001,
DVMJobRequestTranscription = 65002
}
export async function hexpubFromNpub(
npub: string
): Promise<string | undefined> {
if (!npub.toLowerCase().startsWith("npub")) {
return undefined;
}
try {
const hexpub = await MutinyWallet.npub_to_hexpub(npub);
return hexpub;
} catch (err) {
console.error(err);
return undefined;
}
}