chore: upgrade latest waku sdk, remove relay node
This commit is contained in:
parent
b647f750f7
commit
da7f586de9
File diff suppressed because it is too large
Load Diff
|
@ -65,7 +65,8 @@
|
|||
"@types/jest": "^29.4.0",
|
||||
"@types/react": "^18.0.28",
|
||||
"@types/testing-library__jest-dom": "^5.14.5",
|
||||
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
||||
"@typescript-eslint/parser": "^7.1.1",
|
||||
"bundlewatch": "^0.3.3",
|
||||
"eslint": "^8.34.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
|
@ -86,8 +87,8 @@
|
|||
"typescript": "^4.9.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@waku/sdk": "^0.0.22",
|
||||
"@waku/interfaces": "^0.0.21",
|
||||
"@waku/interfaces": "^0.0.22",
|
||||
"@waku/sdk": "^0.0.23",
|
||||
"react": "^16.8.0 || ^17 || ^18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
|
|
|
@ -3,14 +3,13 @@ import type { Waku } from "@waku/interfaces";
|
|||
|
||||
import type {
|
||||
BootstrapNodeOptions,
|
||||
CrateNodeResult,
|
||||
LightNodeOptions,
|
||||
CreateNodeResult,
|
||||
CreateWakuNodeOptions,
|
||||
ReactChildrenProps,
|
||||
RelayNodeOptions,
|
||||
} from "./types";
|
||||
import { useCreateLightNode, useCreateRelayNode } from "./useCreateWaku";
|
||||
import { useCreateLightNode } from "./useCreateWaku";
|
||||
|
||||
type WakuContextType<T extends Waku> = CrateNodeResult<T>;
|
||||
type WakuContextType<T extends Waku> = CreateNodeResult<T>;
|
||||
|
||||
const WakuContext = React.createContext<WakuContextType<Waku>>({
|
||||
node: undefined,
|
||||
|
@ -48,12 +47,12 @@ type ProviderProps<T> = ReactChildrenProps & BootstrapNodeOptions<T>;
|
|||
* ...
|
||||
* };
|
||||
* @param {Object} props - options to create a node and other React props
|
||||
* @param {LightNodeOptions} props.options - optional options for creating Light Node
|
||||
* @param {CreateWakuNodeOptions} props.options - optional options for creating Light Node
|
||||
* @param {Protocols} props.protocols - optional protocols list to initiate node with
|
||||
* @returns React Light Node provider component
|
||||
*/
|
||||
export const LightNodeProvider: React.FunctionComponent<
|
||||
ProviderProps<LightNodeOptions>
|
||||
ProviderProps<CreateWakuNodeOptions>
|
||||
> = (props) => {
|
||||
const result = useCreateLightNode({
|
||||
options: props.options,
|
||||
|
@ -64,33 +63,3 @@ export const LightNodeProvider: React.FunctionComponent<
|
|||
<WakuContext.Provider value={result}>{props.children}</WakuContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Provider for creating Relay Node based on options passed.
|
||||
* @example
|
||||
* const App = (props) => (
|
||||
* <RelayNodeProvider options={{...}}>
|
||||
* <Component />
|
||||
* </RelayNodeProvider>
|
||||
* );
|
||||
* const Component = (props) => {
|
||||
* const { node, isLoading, error } = useWaku<RelayNode>();
|
||||
* ...
|
||||
* };
|
||||
* @param {Object} props - options to create a node and other React props
|
||||
* @param {RelayNodeOptions} props.options - optional options for creating Relay Node
|
||||
* @param {Protocols} props.protocols - optional protocols list to initiate node with
|
||||
* @returns React Relay Node provider component
|
||||
*/
|
||||
export const RelayNodeProvider: React.FunctionComponent<
|
||||
ProviderProps<RelayNodeOptions>
|
||||
> = (props) => {
|
||||
const result = useCreateRelayNode({
|
||||
options: props.options,
|
||||
protocols: props.protocols,
|
||||
});
|
||||
|
||||
return (
|
||||
<WakuContext.Provider value={result}>{props.children}</WakuContext.Provider>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
export { ContentPairProvider, useContentPair } from "./ContentPairProvider";
|
||||
export { LightNodeOptions, RelayNodeOptions } from "./types";
|
||||
export { CreateWakuNodeOptions } from "./types";
|
||||
export { useCreateContentPair } from "./useCreatContentPair";
|
||||
export { useCreateLightNode, useCreateRelayNode } from "./useCreateWaku";
|
||||
export { useCreateLightNode } from "./useCreateWaku";
|
||||
export { useFilterMessages } from "./useFilterMessages";
|
||||
export { useLightPush } from "./useLightPush";
|
||||
export { useStoreMessages } from "./useStoreMessages";
|
||||
export { LightNodeProvider, RelayNodeProvider, useWaku } from "./WakuProvider";
|
||||
export { LightNodeProvider, useWaku } from "./WakuProvider";
|
||||
|
|
12
src/types.ts
12
src/types.ts
|
@ -1,12 +1,13 @@
|
|||
import type { ProtocolCreateOptions, Protocols, Waku } from "@waku/interfaces";
|
||||
import type { relay, waku } from "@waku/sdk";
|
||||
import type { Protocols, Waku } from "@waku/interfaces";
|
||||
import type { waku } from "@waku/sdk";
|
||||
export type { CreateWakuNodeOptions } from "@waku/sdk";
|
||||
|
||||
export type HookState = {
|
||||
isLoading: boolean;
|
||||
error: undefined | string;
|
||||
};
|
||||
|
||||
export type CrateNodeResult<T extends Waku> = HookState & {
|
||||
export type CreateNodeResult<T extends Waku> = HookState & {
|
||||
node: undefined | T;
|
||||
};
|
||||
|
||||
|
@ -15,11 +16,6 @@ export type BootstrapNodeOptions<T = {}> = {
|
|||
protocols?: Protocols[];
|
||||
};
|
||||
|
||||
export type LightNodeOptions = ProtocolCreateOptions & waku.WakuOptions;
|
||||
export type RelayNodeOptions = ProtocolCreateOptions &
|
||||
waku.WakuOptions &
|
||||
Partial<relay.RelayCreateOptions>;
|
||||
|
||||
export type ContentPair = {
|
||||
encoder: waku.Encoder;
|
||||
decoder: waku.Decoder;
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import React from "react";
|
||||
import type { LightNode, RelayNode, Waku } from "@waku/interfaces";
|
||||
import { createLightNode, createRelayNode, waitForRemotePeer } from "@waku/sdk";
|
||||
import type { LightNode, Waku } from "@waku/interfaces";
|
||||
import { createLightNode, waitForRemotePeer } from "@waku/sdk";
|
||||
|
||||
import type {
|
||||
BootstrapNodeOptions,
|
||||
CrateNodeResult,
|
||||
LightNodeOptions,
|
||||
RelayNodeOptions,
|
||||
CreateNodeResult,
|
||||
CreateWakuNodeOptions,
|
||||
} from "./types";
|
||||
|
||||
type NodeFactory<N, T = {}> = (options?: T) => Promise<N>;
|
||||
|
@ -17,7 +16,7 @@ type CreateNodeParams<N extends Waku, T = {}> = BootstrapNodeOptions<T> & {
|
|||
|
||||
const useCreateNode = <N extends Waku, T = {}>(
|
||||
params: CreateNodeParams<N, T>,
|
||||
): CrateNodeResult<N> => {
|
||||
): CreateNodeResult<N> => {
|
||||
const { factory, options, protocols = [] } = params;
|
||||
|
||||
const [node, setNode] = React.useState<N | undefined>(undefined);
|
||||
|
@ -64,24 +63,10 @@ const useCreateNode = <N extends Waku, T = {}>(
|
|||
* @returns {CrateWakuHook} node, loading state and error
|
||||
*/
|
||||
export const useCreateLightNode = (
|
||||
params?: BootstrapNodeOptions<LightNodeOptions>,
|
||||
params?: BootstrapNodeOptions<CreateWakuNodeOptions>,
|
||||
) => {
|
||||
return useCreateNode<LightNode, LightNodeOptions>({
|
||||
return useCreateNode<LightNode, CreateWakuNodeOptions>({
|
||||
...params,
|
||||
factory: createLightNode,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create Relay Node helper hook.
|
||||
* @param {Object} params - optional params to configure & bootstrap node
|
||||
* @returns {CrateWakuHook} node, loading state and error
|
||||
*/
|
||||
export const useCreateRelayNode = (
|
||||
params?: BootstrapNodeOptions<RelayNodeOptions>,
|
||||
) => {
|
||||
return useCreateNode<RelayNode, RelayNodeOptions>({
|
||||
...params,
|
||||
factory: createRelayNode,
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue