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