giving it a shot
This commit is contained in:
parent
f9c0f35862
commit
f89535cf2d
@ -33,7 +33,7 @@ const ConfirmModal = dynamic(() => import("@/components/Modals/Confirm"), {
|
|||||||
export default function Header({ event }: { event: NDKEvent }) {
|
export default function Header({ event }: { event: NDKEvent }) {
|
||||||
const { currentUser } = useCurrentUser();
|
const { currentUser } = useCurrentUser();
|
||||||
const modal = useModal();
|
const modal = useModal();
|
||||||
const { ndk } = useNDK();
|
const { ndk, signer } = useNDK();
|
||||||
const [checkingPayment, setCheckingPayment] = useState(false);
|
const [checkingPayment, setCheckingPayment] = useState(false);
|
||||||
const [hasValidPayment, setHasValidPayment] = useState(false);
|
const [hasValidPayment, setHasValidPayment] = useState(false);
|
||||||
const [syncingUsers, setSyncingUsers] = useState(false);
|
const [syncingUsers, setSyncingUsers] = useState(false);
|
||||||
@ -88,11 +88,11 @@ export default function Header({ event }: { event: NDKEvent }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function handleSyncUsers() {
|
async function handleSyncUsers() {
|
||||||
if (!event || !ndk) return;
|
if (!event || !ndk || !signer) return;
|
||||||
setSyncingUsers(true);
|
setSyncingUsers(true);
|
||||||
try {
|
try {
|
||||||
console.log("handleSyncUsers");
|
console.log("handleSyncUsers");
|
||||||
await updateListUsersFromZaps(ndk, event.tagId(), rawEvent);
|
await updateListUsersFromZaps(ndk, event.tagId(), rawEvent, signer);
|
||||||
toast.success("Users Synced!");
|
toast.success("Users Synced!");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("error syncing users", err);
|
console.log("error syncing users", err);
|
||||||
|
@ -35,12 +35,10 @@ export default function Kind3745(props: Event) {
|
|||||||
["#e"]: [id],
|
["#e"]: [id],
|
||||||
});
|
});
|
||||||
if (directMessageEvent) {
|
if (directMessageEvent) {
|
||||||
console.log("Found DM", directMessageEvent);
|
|
||||||
await directMessageEvent.decrypt(
|
await directMessageEvent.decrypt(
|
||||||
new NDKUser({ hexpubkey: pubkey }),
|
new NDKUser({ hexpubkey: pubkey }),
|
||||||
ndk!.signer,
|
ndk!.signer,
|
||||||
);
|
);
|
||||||
console.log("Decryped DM", directMessageEvent);
|
|
||||||
const passphrase = directMessageEvent.content;
|
const passphrase = directMessageEvent.content;
|
||||||
if (!passphrase) {
|
if (!passphrase) {
|
||||||
setError("Unable to parse event");
|
setError("Unable to parse event");
|
||||||
|
@ -26,7 +26,6 @@ export async function findEphemeralSigner(
|
|||||||
mainSigner: NDKSigner,
|
mainSigner: NDKSigner,
|
||||||
opts: IFindEphemeralSignerLookups,
|
opts: IFindEphemeralSignerLookups,
|
||||||
): Promise<NDKPrivateKeySigner | undefined> {
|
): Promise<NDKPrivateKeySigner | undefined> {
|
||||||
const mainUser = await mainSigner.user();
|
|
||||||
const filter: NDKFilter = { kinds: [2600 as number] };
|
const filter: NDKFilter = { kinds: [2600 as number] };
|
||||||
|
|
||||||
if (opts.name) {
|
if (opts.name) {
|
||||||
@ -38,7 +37,7 @@ export async function findEphemeralSigner(
|
|||||||
);
|
);
|
||||||
filter["#e"] = [hashedEventReference];
|
filter["#e"] = [hashedEventReference];
|
||||||
}
|
}
|
||||||
|
console.log("filter", filter);
|
||||||
const event = await ndk.fetchEvent(filter);
|
const event = await ndk.fetchEvent(filter);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import NDK, {
|
import NDK, {
|
||||||
NDKEvent,
|
NDKEvent,
|
||||||
NDKUser,
|
NDKUser,
|
||||||
|
NDKSigner,
|
||||||
zapInvoiceFromEvent,
|
zapInvoiceFromEvent,
|
||||||
type NostrEvent,
|
type NostrEvent,
|
||||||
} from "@nostr-dev-kit/ndk";
|
} from "@nostr-dev-kit/ndk";
|
||||||
@ -103,6 +104,7 @@ export async function updateListUsersFromZaps(
|
|||||||
ndk: NDK,
|
ndk: NDK,
|
||||||
tagId: string,
|
tagId: string,
|
||||||
event: NostrEvent,
|
event: NostrEvent,
|
||||||
|
signer: NDKSigner,
|
||||||
) {
|
) {
|
||||||
const SECONDS_IN_MONTH = 2_628_000;
|
const SECONDS_IN_MONTH = 2_628_000;
|
||||||
const SECONDS_IN_YEAR = SECONDS_IN_MONTH * 365;
|
const SECONDS_IN_YEAR = SECONDS_IN_MONTH * 365;
|
||||||
@ -120,6 +122,7 @@ export async function updateListUsersFromZaps(
|
|||||||
([pubkey, relay, petname, expiryUnix]) =>
|
([pubkey, relay, petname, expiryUnix]) =>
|
||||||
parseInt(expiryUnix ?? "0") > unixTimeNowInSeconds(),
|
parseInt(expiryUnix ?? "0") > unixTimeNowInSeconds(),
|
||||||
);
|
);
|
||||||
|
const newUsers: string[] = [];
|
||||||
|
|
||||||
for (const paymentInvoice of paymentInvoices) {
|
for (const paymentInvoice of paymentInvoices) {
|
||||||
if (
|
if (
|
||||||
@ -135,7 +138,6 @@ export async function updateListUsersFromZaps(
|
|||||||
event,
|
event,
|
||||||
);
|
);
|
||||||
console.log("Is valid?", isValid);
|
console.log("Is valid?", isValid);
|
||||||
const newUsers: string[] = [];
|
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
validUsers.push([
|
validUsers.push([
|
||||||
paymentInvoice.zappee,
|
paymentInvoice.zappee,
|
||||||
@ -146,8 +148,8 @@ export async function updateListUsersFromZaps(
|
|||||||
newUsers.push(paymentInvoice.zappee);
|
newUsers.push(paymentInvoice.zappee);
|
||||||
// Send old codes to user
|
// Send old codes to user
|
||||||
}
|
}
|
||||||
await sendCodesToNewUsers(ndk, newUsers, tagId);
|
|
||||||
}
|
}
|
||||||
|
await sendCodesToNewUsers(ndk, newUsers, tagId, signer);
|
||||||
|
|
||||||
// Add self
|
// Add self
|
||||||
console.log("Adding self");
|
console.log("Adding self");
|
||||||
@ -166,10 +168,17 @@ export async function updateListUsersFromZaps(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendCodesToNewUsers(ndk: NDK, users: string[], tagId: string) {
|
async function sendCodesToNewUsers(
|
||||||
const signer = await findEphemeralSigner(ndk, ndk!.signer!, {
|
ndk: NDK,
|
||||||
|
users: string[],
|
||||||
|
tagId: string,
|
||||||
|
signer_: NDKSigner,
|
||||||
|
) {
|
||||||
|
console.log("sendCodesToNewUsers", users, signer_);
|
||||||
|
const signer = await findEphemeralSigner(ndk, signer_, {
|
||||||
associatedEventNip19: tagId,
|
associatedEventNip19: tagId,
|
||||||
});
|
});
|
||||||
|
console.log("Signer", signer);
|
||||||
if (!signer) return;
|
if (!signer) return;
|
||||||
const delegate = await signer.user();
|
const delegate = await signer.user();
|
||||||
const messages = await ndk.fetchEvents({
|
const messages = await ndk.fetchEvents({
|
||||||
@ -195,6 +204,7 @@ async function sendCodesToNewUsers(ndk: NDK, users: string[], tagId: string) {
|
|||||||
],
|
],
|
||||||
pubkey: delegate.pubkey,
|
pubkey: delegate.pubkey,
|
||||||
} as NostrEvent);
|
} as NostrEvent);
|
||||||
|
console.log("Sending message");
|
||||||
await messageEvent.encrypt(new NDKUser({ hexpubkey: user }), signer);
|
await messageEvent.encrypt(new NDKUser({ hexpubkey: user }), signer);
|
||||||
await messageEvent.sign(signer);
|
await messageEvent.sign(signer);
|
||||||
await messageEvent.publish();
|
await messageEvent.publish();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user