Make it work

This commit is contained in:
Abhay Raizada
2024-03-14 22:43:15 +05:30
parent cd7973f49d
commit 3aae1f5c5e
4 changed files with 49 additions and 49 deletions

View File

@@ -1,58 +1,33 @@
import {SimplePool} from 'nostr-tools';
import {V1FormSpec} from '@formstr/sdk/dist/interfaces';
const defaultRelays = ['wss://relay.primal.net/', 'wss://relay.hllo.live'];
const relayList = ['wss://relay.primal.net/', 'wss://relay.hllo.live/'];
export const getFormTemplate = async (formId: string): Promise<{}> => {
console.log('inside getFormTemplate');
const pool = new SimplePool();
let formIdPubkey = formId;
let relayList = defaultRelays;
console.log('everything initialised');
const filter = {
kinds: [0],
authors: [formIdPubkey], //formId is the npub of the form
};
console.log('getting kind0', filter);
pool
.get(relayList, filter, {maxWait: 10})
.then(
value => {
console.log('got kind0', value);
return;
},
reason => {
console.log('failed to get because', reason);
return;
},
)
.catch(reason => {
console.log('Errored', reason);
return;
});
console.log('after promise');
let kind0 = null
try {
console.log('inside try');
console.log(
'Event',
await pool.querySync(relayList, filter, {maxWait: 10}),
);
// console.log('fetching...', fetch('https://github.com'));
console.log('Main thread is stuck');
console.log('inside trydasdsad');
kind0 = await pool.get(relayList, filter)
console.log('Main thread is working, got event', kind0);
} catch (e) {
console.log('inside catch');
console.log('error is', e);
}
console.log('After everything');
pool.close(relayList);
let formTemplate;
// if (kind0) {
// formTemplate = JSON.parse(kind0.content);
// } else {
// throw Error('Form template not found');
// }
return {};
if (kind0) {
formTemplate = JSON.parse(kind0.content);
} else {
throw Error('Form template not found');
}
return formTemplate;
};