mirror of
https://github.com/logos-messaging/examples.waku.org.git
synced 2026-01-02 04:43:07 +00:00
* use next.js tempalte * use next lint rules * alight UI * fix problem with margins * remove old page, rename to hooks * add constants * create RLN service, add utils * add RLN init * refactor a bit * add init for Keystore * add store functions * add styles * add contract hooks, add store fields, fix multiple downloads issue * add features * add keystore read logic * add import export * combine to useContract * add useWaku stub, add state to Waku block, styles * add creation of a node * add messages functionality * up readme * update CI * update readme * remove and rename, address comments * update readme * move const
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
"use client";
|
|
import React from "react";
|
|
import { rln, RLN, RLNEventsNames } from "@/services/rln";
|
|
import { useStore } from "./useStore";
|
|
|
|
type RLNResult = {
|
|
rln: undefined | RLN;
|
|
};
|
|
|
|
export const useRLN = (): RLNResult => {
|
|
const { setAppStatus, setKeystoreCredentials } = useStore();
|
|
const rlnRef = React.useRef<undefined | RLN>(undefined);
|
|
|
|
React.useEffect(() => {
|
|
if (rlnRef.current || !rln) {
|
|
return;
|
|
}
|
|
|
|
let terminate = false;
|
|
|
|
const statusListener = (event: CustomEvent) => {
|
|
setAppStatus(event?.detail);
|
|
};
|
|
rln.addEventListener(RLNEventsNames.Status, statusListener);
|
|
|
|
const keystoreListener = (event: CustomEvent) => {
|
|
setKeystoreCredentials(event?.detail || []);
|
|
};
|
|
rln.addEventListener(RLNEventsNames.Keystore, keystoreListener);
|
|
|
|
const run = async () => {
|
|
if (terminate) {
|
|
return;
|
|
}
|
|
await rln?.init();
|
|
rlnRef.current = rln;
|
|
};
|
|
|
|
run();
|
|
return () => {
|
|
terminate = true;
|
|
rln?.removeEventListener(RLNEventsNames.Status, statusListener);
|
|
rln?.removeEventListener(RLNEventsNames.Keystore, keystoreListener);
|
|
};
|
|
}, [rlnRef, setAppStatus]);
|
|
|
|
return {
|
|
rln: rlnRef.current,
|
|
};
|
|
};
|