Store added pharmacy in local storage

This commit is contained in:
abhay-raizada
2024-08-12 18:57:17 +05:30
parent 605b89c578
commit ae9f81ddb7
6 changed files with 121 additions and 25 deletions

View File

@@ -47,11 +47,17 @@ export const PrescriptionCreator = () => {
const [selectedPharmacyId, setSelectedPharmacyId] = useState(
pharmacyData[0].npub,
);
const [selectedPharmacyRelays, setSelectedPharmacyRelays] = useState([]);
const [selectedPharmacyRelays, setSelectedPharmacyRelays] = useState<
Array<string>
>([pharmacyData[0].relay!]);
const handleLocationChange = (item: any) => {
const handleLocationChange = (item: {
name: string;
npub: string;
relay: string;
}) => {
setSelectedPharmacyId(item.npub);
setSelectedPharmacyRelays(item.relays);
setSelectedPharmacyRelays([item.relay]);
};
useEffect(() => {
@@ -119,10 +125,18 @@ export const PrescriptionCreator = () => {
pubkey: pk,
};
const finalEvent = finalizeEvent(baseKind4Event, sk);
console.log(
'FINAL EVENT IS ',
finalEvent,
'relays are',
selectedPharmacyRelays,
);
const pool = new SimplePool();
console.log('publishing event');
await Promise.allSettled(pool.publish(selectedPharmacyRelays, finalEvent));
console.log('Event Published');
let messages = await Promise.allSettled(
pool.publish(selectedPharmacyRelays, finalEvent),
);
console.log('Messages from relays', messages);
Alert.alert('Prescription Sent to the pharmacy!');
};