got it
This commit is contained in:
parent
f89535cf2d
commit
4a35a785a7
@ -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, signer } = useNDK();
|
||||
const { ndk } = 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 || !signer) return;
|
||||
if (!event || !ndk) return;
|
||||
setSyncingUsers(true);
|
||||
try {
|
||||
console.log("handleSyncUsers");
|
||||
await updateListUsersFromZaps(ndk, event.tagId(), rawEvent, signer);
|
||||
await updateListUsersFromZaps(ndk, event.tagId(), rawEvent);
|
||||
toast.success("Users Synced!");
|
||||
} catch (err) {
|
||||
console.log("error syncing users", err);
|
||||
|
@ -60,6 +60,7 @@ export default function CreateList() {
|
||||
kind: 30001,
|
||||
tags: tags,
|
||||
});
|
||||
console.log("EVENT Created", event);
|
||||
if (event && getTagValues("subscriptions", event.tags)) {
|
||||
await getSigner(new NDKList(ndk, event.rawEvent()))
|
||||
.then((delegateSigner) =>
|
||||
|
@ -101,15 +101,16 @@ function generateContent(
|
||||
async function generateTags(mainSigner: NDKSigner, opts: ISaveOpts = {}) {
|
||||
const mainUser = await mainSigner.user();
|
||||
const tags = [
|
||||
["p", mainUser.hexpubkey],
|
||||
["p", mainUser.pubkey],
|
||||
["client", "flockstr"],
|
||||
];
|
||||
|
||||
if (opts.associatedEvent) {
|
||||
// TODO: This is trivially reversable; better to encrypt it or hash it with the hexpubkey
|
||||
const hashedEventReference = await getHashedKeyName(
|
||||
opts.associatedEvent.encode(),
|
||||
);
|
||||
const encodedEvent = opts.associatedEvent.encode();
|
||||
console.log("encodedEvent", encodedEvent);
|
||||
// TODO: This is trivially reversable; better to encrypt it or hash it with the pubkey
|
||||
const hashedEventReference = await getHashedKeyName(encodedEvent);
|
||||
console.log("hashedEventReference", hashedEventReference);
|
||||
tags.push(["e", hashedEventReference]);
|
||||
}
|
||||
|
||||
@ -139,7 +140,7 @@ export async function saveEphemeralSigner(
|
||||
content: generateContent(targetSigner, opts),
|
||||
tags: await generateTags(mainSigner, opts),
|
||||
} as NostrEvent);
|
||||
event.pubkey = mainUser.hexpubkey;
|
||||
event.pubkey = mainUser.pubkey;
|
||||
await event.encrypt(mainUser, mainSigner);
|
||||
await event.publish();
|
||||
|
||||
@ -152,7 +153,7 @@ export async function saveEphemeralSigner(
|
||||
content: JSON.stringify(opts.keyProfile),
|
||||
tags: [] as NDKTag[],
|
||||
} as NostrEvent);
|
||||
event.pubkey = user.hexpubkey;
|
||||
event.pubkey = user.pubkey;
|
||||
await event.sign(targetSigner);
|
||||
await event.publish();
|
||||
}
|
||||
|
@ -104,7 +104,6 @@ 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;
|
||||
@ -122,7 +121,7 @@ export async function updateListUsersFromZaps(
|
||||
([pubkey, relay, petname, expiryUnix]) =>
|
||||
parseInt(expiryUnix ?? "0") > unixTimeNowInSeconds(),
|
||||
);
|
||||
const newUsers: string[] = [];
|
||||
const newUsers: string[] = currentUsers.map(([pub]) => pub as string);
|
||||
|
||||
for (const paymentInvoice of paymentInvoices) {
|
||||
if (
|
||||
@ -149,7 +148,7 @@ export async function updateListUsersFromZaps(
|
||||
// Send old codes to user
|
||||
}
|
||||
}
|
||||
await sendCodesToNewUsers(ndk, newUsers, tagId, signer);
|
||||
await sendCodesToNewUsers(ndk, newUsers, tagId, event);
|
||||
|
||||
// Add self
|
||||
console.log("Adding self");
|
||||
@ -172,11 +171,10 @@ async function sendCodesToNewUsers(
|
||||
ndk: NDK,
|
||||
users: string[],
|
||||
tagId: string,
|
||||
signer_: NDKSigner,
|
||||
event: NostrEvent,
|
||||
) {
|
||||
console.log("sendCodesToNewUsers", users, signer_);
|
||||
const signer = await findEphemeralSigner(ndk, signer_, {
|
||||
associatedEventNip19: tagId,
|
||||
const signer = await findEphemeralSigner(ndk, ndk.signer!, {
|
||||
associatedEventNip19: new NDKEvent(ndk, event).encode(),
|
||||
});
|
||||
console.log("Signer", signer);
|
||||
if (!signer) return;
|
||||
@ -188,9 +186,10 @@ async function sendCodesToNewUsers(
|
||||
});
|
||||
const codes: [string, string][] = [];
|
||||
for (const message of Array.from(messages)) {
|
||||
await message.decrypt(delegate, signer);
|
||||
await message.decrypt();
|
||||
codes.push([getTagValues("e", message.tags) ?? "", message.content]);
|
||||
}
|
||||
console.log("codes", codes);
|
||||
|
||||
for (const user of users) {
|
||||
for (const [event, code] of codes) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user