Skip to content

Commit

Permalink
Make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-raizada committed Mar 14, 2024
1 parent cd7973f commit 3aae1f5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
25 changes: 14 additions & 11 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* @format
*/

import React, {useEffect, useState} from 'react';
import {SafeAreaView, ScrollView, StatusBar, StyleSheet} from 'react-native';
import React, { useEffect, useState } from 'react';
import { SafeAreaView, ScrollView, StatusBar, StyleSheet } from 'react-native';

import {getFormTemplate} from './formstr/formstr';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import {PrescriptionCreator} from './components/PrescriptionCreator';
import { getFormTemplate } from './formstr/formstr';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import { PrescriptionCreator } from './components/PrescriptionCreator';
import 'react-native-url-polyfill/auto';

function App(): React.JSX.Element {
const backgroundStyle = {
Expand All @@ -22,14 +23,16 @@ function App(): React.JSX.Element {
useEffect(() => {
console.log('inside useeffect');
const fetchForm = async () => {
console.log('fetchiiiing forrmmm!!!');
let form = await getFormTemplate(
'eb3df1f89653475f0bcbd22da35f8d2f126db8a68a88a7abedc53535c76c39b4',
);
setForm(form);
if (!form) {
console.log('fetchiiiing forrmmm!!!');
let form = await getFormTemplate(
'eb3df1f89653475f0bcbd22da35f8d2f126db8a68a88a7abedc53535c76c39b4',
)
setForm(form);
}
};
fetchForm();
}, [form, setForm]);
}, [form]);

return (
<SafeAreaView style={backgroundStyle}>
Expand Down
47 changes: 11 additions & 36 deletions formstr/formstr.ts
Original file line number Diff line number Diff line change
@@ -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;
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"nostr-tools": "^2.3.1",
"react": "18.2.0",
"react-native": "0.73.4",
"react-native-url-polyfill": "^2.0.0",
"text-encoding-polyfill": "^0.6.7"
},
"devDependencies": {
Expand Down
25 changes: 23 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2745,7 +2745,7 @@ buffer-from@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==

buffer@^5.5.0:
buffer@^5.4.3, buffer@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
Expand Down Expand Up @@ -6155,7 +6155,7 @@ prop-types@^15.5.10, prop-types@^15.7.2, prop-types@^15.8.1:
object-assign "^4.1.1"
react-is "^16.13.1"

punycode@^2.1.0:
punycode@^2.1.0, punycode@^2.1.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5"
integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==
Expand Down Expand Up @@ -6254,6 +6254,13 @@ react-native-modal-popover@^2.0.1:
lodash ">4.17.0"
prop-types "^15.8.1"

react-native-url-polyfill@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz#db714520a2985cff1d50ab2e66279b9f91ffd589"
integrity sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA==
dependencies:
whatwg-url-without-unicode "8.0.0-3"

[email protected]:
version "0.73.4"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.73.4.tgz#81e07d4e7b6308c4649d5fa24038c0e87b17f2e1"
Expand Down Expand Up @@ -7404,11 +7411,25 @@ webidl-conversions@^3.0.0:
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==

webidl-conversions@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff"
integrity sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==

whatwg-fetch@^3.0.0:
version "3.6.20"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz#580ce6d791facec91d37c72890995a0b48d31c70"
integrity sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==

[email protected]:
version "8.0.0-3"
resolved "https://registry.yarnpkg.com/whatwg-url-without-unicode/-/whatwg-url-without-unicode-8.0.0-3.tgz#ab6df4bf6caaa6c85a59f6e82c026151d4bb376b"
integrity sha512-HoKuzZrUlgpz35YO27XgD28uh/WJH4B0+3ttFqRo//lmq+9T/mIOJ6kqmINI9HpUpz1imRC/nR/lxKpJiv0uig==
dependencies:
buffer "^5.4.3"
punycode "^2.1.1"
webidl-conversions "^5.0.0"

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
Expand Down

0 comments on commit 3aae1f5

Please sign in to comment.