mirror of
https://github.com/abhay-raizada/PeerScribe.git
synced 2026-04-26 16:24:03 +00:00
Make it work
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user