mirror of
https://github.com/abhay-raizada/PeerScribe.git
synced 2026-04-26 08:14:03 +00:00
Send xml as a message
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -6,7 +6,7 @@ import RNPickerSelect from "react-native-picker-select"
|
||||
interface InputFillerProps {
|
||||
answerType: AnswerTypes;
|
||||
answerSettings: V1AnswerSettings;
|
||||
onChange: (answer: string, message?: string) => void;
|
||||
onChange: (answer: string) => void;
|
||||
defaultValue?: string | number | boolean;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ export const InputFiller: React.FC<InputFillerProps> = ({
|
||||
e: any
|
||||
) => {
|
||||
console.log("E is", e)
|
||||
setInputValue(e.target.value);
|
||||
onChange(e.target.value)
|
||||
setInputValue(e);
|
||||
onChange(e)
|
||||
};
|
||||
|
||||
const handleValueChange = (value: string) => {
|
||||
|
||||
@@ -9,6 +9,31 @@ import { Dropdown } from 'react-native-element-dropdown';
|
||||
import { SimplePool, UnsignedEvent, finalizeEvent, generateSecretKey, getPublicKey, nip04, nip19 } from 'nostr-tools';
|
||||
import EncryptedStorage from 'react-native-encrypted-storage';
|
||||
import { ImportNsec } from './ImportNsec';
|
||||
import { json2xml } from 'xml-js';
|
||||
|
||||
function OBJtoXML(obj: any) {
|
||||
var xml = '';
|
||||
for (var prop in obj) {
|
||||
xml += "<" + prop + ">";
|
||||
if(Array.isArray(obj[prop])) {
|
||||
for (var array of obj[prop]) {
|
||||
|
||||
// A real botch fix here
|
||||
xml += "</" + prop + ">";
|
||||
xml += "<" + prop + ">";
|
||||
|
||||
xml += OBJtoXML(new Object(array));
|
||||
}
|
||||
} else if (typeof obj[prop] == "object") {
|
||||
xml += OBJtoXML(new Object(obj[prop]));
|
||||
} else {
|
||||
xml += obj[prop];
|
||||
}
|
||||
xml += "</" + prop + ">";
|
||||
}
|
||||
var xml = xml.replace(/<\/?[0-9]{1,}>/g,'');
|
||||
return xml
|
||||
}
|
||||
|
||||
type SectionProps = PropsWithChildren<{
|
||||
title: string;
|
||||
@@ -85,6 +110,7 @@ export const PrescriptionCreator = ({ form }: { form: any }) => {
|
||||
const [loggedInNpub, setLoggedInNpub] = useState("")
|
||||
const [selectedPharmacyId, setSelectedPharmacyId] = useState("");
|
||||
const [selectedPharmacyRelays, setSelectedPharmacyRelays] = useState([]);
|
||||
const [finalJSON, setFinalJson] = useState({})
|
||||
|
||||
useEffect(() => {
|
||||
async function initialize() {
|
||||
@@ -114,6 +140,11 @@ export const PrescriptionCreator = ({ form }: { form: any }) => {
|
||||
</View>
|
||||
}
|
||||
|
||||
const handleFormItemChange = (questionId: string, value: string) => {
|
||||
console.log("Filling", questionId, value)
|
||||
setFinalJson({...finalJSON, [questionId]: value})
|
||||
}
|
||||
|
||||
const handleLocationChange = (item: any) => {
|
||||
setSelectedPharmacyId(item.npub)
|
||||
setSelectedPharmacyRelays(item.relays)
|
||||
@@ -125,10 +156,18 @@ export const PrescriptionCreator = ({ form }: { form: any }) => {
|
||||
Alert.alert("not a valid nsec!")
|
||||
return;
|
||||
}
|
||||
setLoggedInNpub(nip19.npubEncode(getPublicKey(nip19.decode(nsec).data as Uint8Array)))
|
||||
setShowImportNsec(false)
|
||||
}
|
||||
|
||||
const sendPrescription = async () => {
|
||||
const handleButtonPress = () => {
|
||||
console.log("Final JSON is", finalJSON)
|
||||
const xml = OBJtoXML({form: finalJSON })
|
||||
console.log("XML is...", xml, typeof xml )
|
||||
sendPrescription(xml);
|
||||
}
|
||||
|
||||
const sendPrescription = async (xml: string) => {
|
||||
console.log("Will generate IDs")
|
||||
const sk = nip19.decode(await EncryptedStorage.getItem("user_credentials") as `nsec1${string}`).data as Uint8Array
|
||||
const pk = getPublicKey(sk)
|
||||
@@ -137,7 +176,7 @@ export const PrescriptionCreator = ({ form }: { form: any }) => {
|
||||
const baseKind4Event: UnsignedEvent = {
|
||||
kind: 4,
|
||||
tags: [["p", pharmacyId]],
|
||||
content: await nip04.encrypt(sk, pharmacyId, "This is a test message from PeerScribe"),
|
||||
content: await nip04.encrypt(sk, pharmacyId, `This is a test prescription from PeerScribe ${xml}`),
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
pubkey: pk
|
||||
}
|
||||
@@ -202,11 +241,12 @@ export const PrescriptionCreator = ({ form }: { form: any }) => {
|
||||
}}>
|
||||
{field.answerType}
|
||||
</Text> */}
|
||||
<InputFiller answerSettings={field.answerSettings} answerType={field.answerType} onChange={() => { }} />
|
||||
<InputFiller answerSettings={field.answerSettings} answerType={field.answerType} onChange={
|
||||
(answer) => handleFormItemChange(field.questionId, answer)} />
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
<Button type='primary' onPress={sendPrescription}> Create RX </Button>
|
||||
<Button type='primary' onPress={handleButtonPress}> Create RX </Button>
|
||||
</View>
|
||||
</Section>
|
||||
<ImportNsec isVisible={showImportNsec} onClose={() => { setShowImportNsec(false)}} onPress={handleImportNsec}/>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"@react-native-community/segmented-control": "^2.2.2",
|
||||
"@react-native-community/slider": "^4.5.0",
|
||||
"@react-native-picker/picker": "^2.6.1",
|
||||
"buffer": "^6.0.3",
|
||||
"events": "^3.3.0",
|
||||
"nostr-tools": "^2.3.1",
|
||||
"react": "18.2.0",
|
||||
@@ -29,7 +30,8 @@
|
||||
"react-native-webview": "^13.8.4",
|
||||
"react-native-webview-crypto": "^0.0.25",
|
||||
"stream": "^0.0.2",
|
||||
"text-encoding-polyfill": "^0.6.7"
|
||||
"text-encoding-polyfill": "^0.6.7",
|
||||
"xml-js": "^1.6.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.0",
|
||||
|
||||
22
yarn.lock
22
yarn.lock
@@ -2851,6 +2851,14 @@ buffer@^5.4.3, buffer@^5.5.0:
|
||||
base64-js "^1.3.1"
|
||||
ieee754 "^1.1.13"
|
||||
|
||||
buffer@^6.0.3:
|
||||
version "6.0.3"
|
||||
resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6"
|
||||
integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==
|
||||
dependencies:
|
||||
base64-js "^1.3.1"
|
||||
ieee754 "^1.2.1"
|
||||
|
||||
bytes@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
|
||||
@@ -4424,7 +4432,7 @@ human-signals@^2.1.0:
|
||||
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
|
||||
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
|
||||
|
||||
ieee754@^1.1.13, ieee754@^1.1.4:
|
||||
ieee754@^1.1.13, ieee754@^1.1.4, ieee754@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
|
||||
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
|
||||
@@ -7013,6 +7021,11 @@ safe-regex@^1.1.0:
|
||||
dependencies:
|
||||
ret "~0.1.10"
|
||||
|
||||
sax@^1.2.4:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/sax/-/sax-1.3.0.tgz#a5dbe77db3be05c9d1ee7785dbd3ea9de51593d0"
|
||||
integrity sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==
|
||||
|
||||
scheduler@0.24.0-canary-efb381bbf-20230505:
|
||||
version "0.24.0-canary-efb381bbf-20230505"
|
||||
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.24.0-canary-efb381bbf-20230505.tgz#5dddc60e29f91cd7f8b983d7ce4a99c2202d178f"
|
||||
@@ -7983,6 +7996,13 @@ ws@^7, ws@^7.5.1:
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591"
|
||||
integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==
|
||||
|
||||
xml-js@^1.6.11:
|
||||
version "1.6.11"
|
||||
resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.11.tgz#927d2f6947f7f1c19a316dd8eea3614e8b18f8e9"
|
||||
integrity sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==
|
||||
dependencies:
|
||||
sax "^1.2.4"
|
||||
|
||||
xtend@~4.0.1:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
|
||||
|
||||
Reference in New Issue
Block a user