Merge pull request #39 from waku-org/chore/waku-sdk-23
chore: upgrade latest waku sdk, remove relay node
This commit is contained in:
commit
80bb1fd265
File diff suppressed because it is too large
Load Diff
|
@ -65,7 +65,8 @@
|
||||||
"@types/jest": "^29.4.0",
|
"@types/jest": "^29.4.0",
|
||||||
"@types/react": "^18.0.28",
|
"@types/react": "^18.0.28",
|
||||||
"@types/testing-library__jest-dom": "^5.14.5",
|
"@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",
|
"bundlewatch": "^0.3.3",
|
||||||
"eslint": "^8.34.0",
|
"eslint": "^8.34.0",
|
||||||
"eslint-config-prettier": "^8.6.0",
|
"eslint-config-prettier": "^8.6.0",
|
||||||
|
@ -86,8 +87,8 @@
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@waku/sdk": "^0.0.22",
|
"@waku/interfaces": "^0.0.22",
|
||||||
"@waku/interfaces": "^0.0.21",
|
"@waku/sdk": "^0.0.23",
|
||||||
"react": "^16.8.0 || ^17 || ^18"
|
"react": "^16.8.0 || ^17 || ^18"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
|
|
|
@ -3,14 +3,13 @@ import type { Waku } from "@waku/interfaces";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
BootstrapNodeOptions,
|
BootstrapNodeOptions,
|
||||||
CrateNodeResult,
|
CreateNodeResult,
|
||||||
LightNodeOptions,
|
CreateWakuNodeOptions,
|
||||||
ReactChildrenProps,
|
ReactChildrenProps,
|
||||||
RelayNodeOptions,
|
|
||||||
} from "./types";
|
} 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>>({
|
const WakuContext = React.createContext<WakuContextType<Waku>>({
|
||||||
node: undefined,
|
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 {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
|
* @param {Protocols} props.protocols - optional protocols list to initiate node with
|
||||||
* @returns React Light Node provider component
|
* @returns React Light Node provider component
|
||||||
*/
|
*/
|
||||||
export const LightNodeProvider: React.FunctionComponent<
|
export const LightNodeProvider: React.FunctionComponent<
|
||||||
ProviderProps<LightNodeOptions>
|
ProviderProps<CreateWakuNodeOptions>
|
||||||
> = (props) => {
|
> = (props) => {
|
||||||
const result = useCreateLightNode({
|
const result = useCreateLightNode({
|
||||||
options: props.options,
|
options: props.options,
|
||||||
|
@ -64,33 +63,3 @@ export const LightNodeProvider: React.FunctionComponent<
|
||||||
<WakuContext.Provider value={result}>{props.children}</WakuContext.Provider>
|
<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 { ContentPairProvider, useContentPair } from "./ContentPairProvider";
|
||||||
export { LightNodeOptions, RelayNodeOptions } from "./types";
|
export { CreateWakuNodeOptions } from "./types";
|
||||||
export { useCreateContentPair } from "./useCreatContentPair";
|
export { useCreateContentPair } from "./useCreatContentPair";
|
||||||
export { useCreateLightNode, useCreateRelayNode } from "./useCreateWaku";
|
export { useCreateLightNode } from "./useCreateWaku";
|
||||||
export { useFilterMessages } from "./useFilterMessages";
|
export { useFilterMessages } from "./useFilterMessages";
|
||||||
export { useLightPush } from "./useLightPush";
|
export { useLightPush } from "./useLightPush";
|
||||||
export { useStoreMessages } from "./useStoreMessages";
|
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 { Protocols, Waku } from "@waku/interfaces";
|
||||||
import type { relay, waku } from "@waku/sdk";
|
import type { waku } from "@waku/sdk";
|
||||||
|
export type { CreateWakuNodeOptions } from "@waku/sdk";
|
||||||
|
|
||||||
export type HookState = {
|
export type HookState = {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
error: undefined | string;
|
error: undefined | string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CrateNodeResult<T extends Waku> = HookState & {
|
export type CreateNodeResult<T extends Waku> = HookState & {
|
||||||
node: undefined | T;
|
node: undefined | T;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,11 +16,6 @@ export type BootstrapNodeOptions<T = {}> = {
|
||||||
protocols?: Protocols[];
|
protocols?: Protocols[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LightNodeOptions = ProtocolCreateOptions & waku.WakuOptions;
|
|
||||||
export type RelayNodeOptions = ProtocolCreateOptions &
|
|
||||||
waku.WakuOptions &
|
|
||||||
Partial<relay.RelayCreateOptions>;
|
|
||||||
|
|
||||||
export type ContentPair = {
|
export type ContentPair = {
|
||||||
encoder: waku.Encoder;
|
encoder: waku.Encoder;
|
||||||
decoder: waku.Decoder;
|
decoder: waku.Decoder;
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import type { LightNode, RelayNode, Waku } from "@waku/interfaces";
|
import type { LightNode, Waku } from "@waku/interfaces";
|
||||||
import { createLightNode, createRelayNode, waitForRemotePeer } from "@waku/sdk";
|
import { createLightNode, waitForRemotePeer } from "@waku/sdk";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
BootstrapNodeOptions,
|
BootstrapNodeOptions,
|
||||||
CrateNodeResult,
|
CreateNodeResult,
|
||||||
LightNodeOptions,
|
CreateWakuNodeOptions,
|
||||||
RelayNodeOptions,
|
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
type NodeFactory<N, T = {}> = (options?: T) => Promise<N>;
|
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 = {}>(
|
const useCreateNode = <N extends Waku, T = {}>(
|
||||||
params: CreateNodeParams<N, T>,
|
params: CreateNodeParams<N, T>,
|
||||||
): CrateNodeResult<N> => {
|
): CreateNodeResult<N> => {
|
||||||
const { factory, options, protocols = [] } = params;
|
const { factory, options, protocols = [] } = params;
|
||||||
|
|
||||||
const [node, setNode] = React.useState<N | undefined>(undefined);
|
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
|
* @returns {CrateWakuHook} node, loading state and error
|
||||||
*/
|
*/
|
||||||
export const useCreateLightNode = (
|
export const useCreateLightNode = (
|
||||||
params?: BootstrapNodeOptions<LightNodeOptions>,
|
params?: BootstrapNodeOptions<CreateWakuNodeOptions>,
|
||||||
) => {
|
) => {
|
||||||
return useCreateNode<LightNode, LightNodeOptions>({
|
return useCreateNode<LightNode, CreateWakuNodeOptions>({
|
||||||
...params,
|
...params,
|
||||||
factory: createLightNode,
|
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