@xyo-network/react-node 2.45.0-rc.4 → 2.45.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/index.js +0 -1
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/useModule.js +1 -2
- package/dist/cjs/hooks/useModule.js.map +1 -1
- package/dist/cjs/hooks/useNode.js +42 -6
- package/dist/cjs/hooks/useNode.js.map +1 -1
- package/dist/cjs/hooks/useProvidedNode.js +13 -1
- package/dist/cjs/hooks/useProvidedNode.js.map +1 -1
- package/dist/docs.json +324 -272
- package/dist/esm/hooks/index.js +0 -1
- package/dist/esm/hooks/index.js.map +1 -1
- package/dist/esm/hooks/useModule.js +2 -3
- package/dist/esm/hooks/useModule.js.map +1 -1
- package/dist/esm/hooks/useNode.js +39 -5
- package/dist/esm/hooks/useNode.js.map +1 -1
- package/dist/esm/hooks/useProvidedNode.js +14 -2
- package/dist/esm/hooks/useProvidedNode.js.map +1 -1
- package/dist/types/hooks/index.d.ts +0 -1
- package/dist/types/hooks/index.d.ts.map +1 -1
- package/dist/types/hooks/useModule.d.ts.map +1 -1
- package/dist/types/hooks/useNode.d.ts +54 -4
- package/dist/types/hooks/useNode.d.ts.map +1 -1
- package/dist/types/hooks/useProvidedNode.d.ts +3 -2
- package/dist/types/hooks/useProvidedNode.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useModule.tsx +2 -3
- package/src/hooks/useNode.tsx +63 -5
- package/src/hooks/useProvidedNode.tsx +17 -5
- package/dist/cjs/hooks/createUseModuleHook.js +0 -44
- package/dist/cjs/hooks/createUseModuleHook.js.map +0 -1
- package/dist/esm/hooks/createUseModuleHook.js +0 -39
- package/dist/esm/hooks/createUseModuleHook.js.map +0 -1
- package/dist/types/hooks/createUseModuleHook.d.ts +0 -52
- package/dist/types/hooks/createUseModuleHook.d.ts.map +0 -1
- package/src/hooks/createUseModuleHook.tsx +0 -63
package/dist/esm/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ModuleWrapper } from '@xyo-network/module';
|
|
2
|
-
import { createUseModuleHook } from './
|
|
3
|
-
|
|
4
|
-
export const useModule = createUseModuleHook(ModuleWrapper.wrap, useNode);
|
|
2
|
+
import { createUseModuleHook, useNode } from './useNode';
|
|
3
|
+
export const useModule = createUseModuleHook(ModuleWrapper.wrap, () => useNode(true));
|
|
5
4
|
//# sourceMappingURL=useModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModule.js","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"useModule.js","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExD,MAAM,CAAC,MAAM,SAAS,GAAG,mBAAmB,CAAwB,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA"}
|
|
@@ -1,8 +1,42 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
import { useAsyncEffect } from '@xylabs/react-shared';
|
|
1
3
|
import { NodeWrapper } from '@xyo-network/node';
|
|
2
|
-
import {
|
|
4
|
+
import { useState } from 'react';
|
|
3
5
|
import { useProvidedNode } from './useProvidedNode';
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export const createUseModuleHook = (wrapFunc, nodeFunc) => {
|
|
7
|
+
function use(nameOrAddressOrWrapOrAccount, wrap = false) {
|
|
8
|
+
const [node, nodeError] = nodeFunc();
|
|
9
|
+
const shouldWrap = typeof nameOrAddressOrWrapOrAccount === 'boolean' ? nameOrAddressOrWrapOrAccount : wrap;
|
|
10
|
+
const account = typeof nameOrAddressOrWrapOrAccount === 'object' ? nameOrAddressOrWrapOrAccount : typeof wrap === 'boolean' ? undefined : wrap;
|
|
11
|
+
const nameOrAddress = typeof nameOrAddressOrWrapOrAccount === 'string' ? nameOrAddressOrWrapOrAccount : undefined;
|
|
12
|
+
const [module, setModule] = useState();
|
|
13
|
+
const [error, setError] = useState();
|
|
14
|
+
useAsyncEffect(
|
|
15
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
16
|
+
async (mounted) => {
|
|
17
|
+
try {
|
|
18
|
+
if (nodeError) {
|
|
19
|
+
setError(nodeError);
|
|
20
|
+
setModule(undefined);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const module = await node?.resolve(nameOrAddress);
|
|
24
|
+
const finalModule = shouldWrap ? wrapFunc(module, account) : module;
|
|
25
|
+
if (mounted()) {
|
|
26
|
+
setModule(finalModule);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (ex) {
|
|
31
|
+
if (mounted()) {
|
|
32
|
+
setError(ex);
|
|
33
|
+
setModule(undefined);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, [wrap, node, nameOrAddress, nodeError, shouldWrap, account]);
|
|
37
|
+
return [module, error];
|
|
38
|
+
}
|
|
39
|
+
return use;
|
|
40
|
+
};
|
|
41
|
+
export const useNode = createUseModuleHook(NodeWrapper.wrap, () => useProvidedNode(true));
|
|
8
42
|
//# sourceMappingURL=useNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNode.js","sourceRoot":"","sources":["../../../src/hooks/useNode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"useNode.js","sourceRoot":"","sources":["../../../src/hooks/useNode.tsx"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,OAAO,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAOnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAKjC,QAAmB,EACnB,QAA4D,EAC5D,EAAE;IAMF,SAAS,GAAG,CACV,4BAAyD,EACzD,OAA0B,KAAK;QAE/B,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAE,CAAA;QACpC,MAAM,UAAU,GAAG,OAAO,4BAA4B,KAAK,SAAS,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAI,CAAA;QAC1G,MAAM,OAAO,GAAG,OAAO,4BAA4B,KAAK,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;QAC9I,MAAM,aAAa,GAAG,OAAO,4BAA4B,KAAK,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,SAAS,CAAA;QACjH,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAsB,CAAA;QAC1D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAA;QAC3C,cAAc;QACZ,uDAAuD;QACvD,KAAK,EAAE,OAAO,EAAE,EAAE;YAChB,IAAI;gBACF,IAAI,SAAS,EAAE;oBACb,QAAQ,CAAC,SAAS,CAAC,CAAA;oBACnB,SAAS,CAAC,SAAS,CAAC,CAAA;iBACrB;qBAAM;oBACL,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,OAAO,CAAU,aAAa,CAAC,CAAA;oBAC1D,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;oBACnE,IAAI,OAAO,EAAE,EAAE;wBACb,SAAS,CAAC,WAAW,CAAC,CAAA;qBACvB;iBACF;aACF;YAAC,OAAO,EAAE,EAAE;gBACX,IAAI,OAAO,EAAE,EAAE;oBACb,QAAQ,CAAC,EAAW,CAAC,CAAA;oBACrB,SAAS,CAAC,SAAS,CAAC,CAAA;iBACrB;aACF;QACH,CAAC,EACD,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAC5D,CAAA;QAED,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACxB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,mBAAmB,CAA0B,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAA"}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { NodeWrapper } from '@xyo-network/node';
|
|
2
|
-
import { useContext } from 'react';
|
|
2
|
+
import { useContext, useState } from 'react';
|
|
3
3
|
import { NodeContext } from '../contexts';
|
|
4
4
|
function useProvidedNodeFunc(wrap) {
|
|
5
5
|
const { node } = useContext(NodeContext);
|
|
6
|
-
|
|
6
|
+
const [wrappedNode, setWrappedNode] = useState();
|
|
7
|
+
const [error, setError] = useState();
|
|
8
|
+
try {
|
|
9
|
+
if (wrap) {
|
|
10
|
+
const wrappedNode = wrap ? NodeWrapper.wrap(node) : undefined;
|
|
11
|
+
setWrappedNode(wrappedNode);
|
|
12
|
+
setError(undefined);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (ex) {
|
|
16
|
+
setError(ex);
|
|
17
|
+
}
|
|
18
|
+
return [wrap ? wrappedNode : node, error];
|
|
7
19
|
}
|
|
8
20
|
export const useProvidedNode = useProvidedNodeFunc;
|
|
9
21
|
//# sourceMappingURL=useProvidedNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProvidedNode.js","sourceRoot":"","sources":["../../../src/hooks/useProvidedNode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"useProvidedNode.js","sourceRoot":"","sources":["../../../src/hooks/useProvidedNode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAKzC,SAAS,mBAAmB,CAAC,IAA8B;IACzD,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAAA;IACxC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,EAAe,CAAA;IAC7D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAA;IAE3C,IAAI;QACF,IAAI,IAAI,EAAE;YACR,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YAC7D,cAAc,CAAC,WAAW,CAAC,CAAA;YAC3B,QAAQ,CAAC,SAAS,CAAC,CAAA;SACpB;KACF;IAAC,OAAO,EAAE,EAAE;QACX,QAAQ,CAAC,EAAW,CAAC,CAAA;KACtB;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"useModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAI3D,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAsF,CAAA"}
|
|
@@ -1,9 +1,59 @@
|
|
|
1
|
+
import { Account } from '@xyo-network/account';
|
|
2
|
+
import { Module, ModuleWrapper } from '@xyo-network/module';
|
|
1
3
|
import { NodeModule, NodeWrapper } from '@xyo-network/node';
|
|
4
|
+
export type WrapFunc<TModule extends Module = Module, TWrapper extends ModuleWrapper = ModuleWrapper> = (module?: TModule, account?: Account) => TWrapper | undefined;
|
|
5
|
+
export declare const createUseModuleHook: <TModule extends Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
6
|
+
name?: string | undefined;
|
|
7
|
+
security?: {
|
|
8
|
+
allowAnonymous?: boolean | undefined;
|
|
9
|
+
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
10
|
+
disallowed?: Record<string, string[]> | undefined;
|
|
11
|
+
} | undefined;
|
|
12
|
+
storeQueries?: boolean | undefined;
|
|
13
|
+
} & {
|
|
14
|
+
schema: string;
|
|
15
|
+
}> = Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
16
|
+
name?: string | undefined;
|
|
17
|
+
security?: {
|
|
18
|
+
allowAnonymous?: boolean | undefined;
|
|
19
|
+
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
20
|
+
disallowed?: Record<string, string[]> | undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
storeQueries?: boolean | undefined;
|
|
23
|
+
} & {
|
|
24
|
+
schema: string;
|
|
25
|
+
}>, TWrapper extends ModuleWrapper<Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
26
|
+
name?: string | undefined;
|
|
27
|
+
security?: {
|
|
28
|
+
allowAnonymous?: boolean | undefined;
|
|
29
|
+
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
30
|
+
disallowed?: Record<string, string[]> | undefined;
|
|
31
|
+
} | undefined;
|
|
32
|
+
storeQueries?: boolean | undefined;
|
|
33
|
+
} & {
|
|
34
|
+
schema: string;
|
|
35
|
+
}>> = ModuleWrapper<Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
36
|
+
name?: string | undefined;
|
|
37
|
+
security?: {
|
|
38
|
+
allowAnonymous?: boolean | undefined;
|
|
39
|
+
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
40
|
+
disallowed?: Record<string, string[]> | undefined;
|
|
41
|
+
} | undefined;
|
|
42
|
+
storeQueries?: boolean | undefined;
|
|
43
|
+
} & {
|
|
44
|
+
schema: string;
|
|
45
|
+
}>>, TWrapFunc extends WrapFunc<TModule, TWrapper> = WrapFunc<TModule, TWrapper>>(wrapFunc: TWrapFunc, nodeFunc: () => [NodeWrapper | undefined, Error | undefined]) => {
|
|
46
|
+
(name?: string): [TModule | undefined, Error | undefined];
|
|
47
|
+
(name: string | undefined, wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
48
|
+
(wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
49
|
+
(address: string): [TModule | undefined, Error | undefined];
|
|
50
|
+
(address: string, wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
51
|
+
};
|
|
2
52
|
export declare const useNode: {
|
|
3
|
-
(name?: string
|
|
4
|
-
(name: string | undefined, wrap: true |
|
|
5
|
-
(wrap: true |
|
|
53
|
+
(name?: string): [NodeModule | undefined, Error | undefined];
|
|
54
|
+
(name: string | undefined, wrap: true | Account): [NodeWrapper | undefined, Error | undefined];
|
|
55
|
+
(wrap: true | Account): [NodeWrapper | undefined, Error | undefined];
|
|
6
56
|
(address: string): [NodeModule | undefined, Error | undefined];
|
|
7
|
-
(address: string, wrap: true |
|
|
57
|
+
(address: string, wrap: true | Account): [NodeWrapper | undefined, Error | undefined];
|
|
8
58
|
};
|
|
9
59
|
//# sourceMappingURL=useNode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useNode.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useNode.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAK3D,MAAM,MAAM,QAAQ,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,QAAQ,SAAS,aAAa,GAAG,aAAa,IAAI,CACtG,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,OAAO,KACd,QAAQ,GAAG,SAAS,CAAA;AAEzB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iHAMpB,MAAM,CAAC,WAAW,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC;YAExC,MAAM;WACP,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG,OAAO;WACxC,IAAI,GAAG,OAAO;cACX,MAAM;cACN,MAAM,QAAQ,IAAI,GAAG,OAAO;CAsCnD,CAAA;AAED,eAAO,MAAM,OAAO;YA5CE,MAAM;WACP,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG,OAAO;WACxC,IAAI,GAAG,OAAO;cACX,MAAM;cACN,MAAM,QAAQ,IAAI,GAAG,OAAO;CAwC8D,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NodeModule, NodeWrapper } from '@xyo-network/node';
|
|
2
|
-
declare function useProvidedNodeFunc(wrap?:
|
|
3
|
-
declare function useProvidedNodeFunc(wrap:
|
|
2
|
+
declare function useProvidedNodeFunc(wrap?: undefined): [NodeModule | undefined, Error | undefined];
|
|
3
|
+
declare function useProvidedNodeFunc(wrap: false): [NodeModule | undefined, Error | undefined];
|
|
4
|
+
declare function useProvidedNodeFunc(wrap: true): [NodeWrapper | undefined, Error | undefined];
|
|
4
5
|
export declare const useProvidedNode: typeof useProvidedNodeFunc;
|
|
5
6
|
export {};
|
|
6
7
|
//# sourceMappingURL=useProvidedNode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProvidedNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useProvidedNode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAK3D,iBAAS,mBAAmB,CAAC,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"useProvidedNode.d.ts","sourceRoot":"","sources":["../../../src/hooks/useProvidedNode.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAK3D,iBAAS,mBAAmB,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,CAAC,UAAU,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC,CAAA;AAC3F,iBAAS,mBAAmB,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,UAAU,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC,CAAA;AACtF,iBAAS,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,WAAW,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC,CAAA;AAkBtF,eAAO,MAAM,eAAe,4BAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@xyo-network/module-model": "^2.51.1",
|
|
22
22
|
"@xyo-network/node": "^2.51.1",
|
|
23
23
|
"@xyo-network/payload-model": "^2.51.1",
|
|
24
|
-
"@xyo-network/react-shared": "^2.45.0-rc.
|
|
24
|
+
"@xyo-network/react-shared": "^2.45.0-rc.6",
|
|
25
25
|
"@xyo-network/witness": "^2.51.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -83,6 +83,6 @@
|
|
|
83
83
|
},
|
|
84
84
|
"sideEffects": false,
|
|
85
85
|
"types": "dist/types/index.d.ts",
|
|
86
|
-
"version": "2.45.0-rc.
|
|
86
|
+
"version": "2.45.0-rc.6",
|
|
87
87
|
"stableVersion": "2.44.1"
|
|
88
88
|
}
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/useModule.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Module, ModuleWrapper } from '@xyo-network/module'
|
|
2
2
|
|
|
3
|
-
import { createUseModuleHook } from './
|
|
4
|
-
import { useNode } from './useNode'
|
|
3
|
+
import { createUseModuleHook, useNode } from './useNode'
|
|
5
4
|
|
|
6
|
-
export const useModule = createUseModuleHook<Module, ModuleWrapper>(ModuleWrapper.wrap, useNode)
|
|
5
|
+
export const useModule = createUseModuleHook<Module, ModuleWrapper>(ModuleWrapper.wrap, () => useNode(true))
|
package/src/hooks/useNode.tsx
CHANGED
|
@@ -1,9 +1,67 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
3
|
+
import { Account } from '@xyo-network/account'
|
|
4
|
+
import { Module, ModuleWrapper } from '@xyo-network/module'
|
|
1
5
|
import { NodeModule, NodeWrapper } from '@xyo-network/node'
|
|
6
|
+
import { useState } from 'react'
|
|
2
7
|
|
|
3
|
-
import { createUseModuleHook } from './createUseModuleHook'
|
|
4
8
|
import { useProvidedNode } from './useProvidedNode'
|
|
5
9
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export type WrapFunc<TModule extends Module = Module, TWrapper extends ModuleWrapper = ModuleWrapper> = (
|
|
11
|
+
module?: TModule,
|
|
12
|
+
account?: Account,
|
|
13
|
+
) => TWrapper | undefined
|
|
14
|
+
|
|
15
|
+
export const createUseModuleHook = <
|
|
16
|
+
TModule extends Module = Module,
|
|
17
|
+
TWrapper extends ModuleWrapper = ModuleWrapper,
|
|
18
|
+
TWrapFunc extends WrapFunc<TModule, TWrapper> = WrapFunc<TModule, TWrapper>,
|
|
19
|
+
>(
|
|
20
|
+
wrapFunc: TWrapFunc,
|
|
21
|
+
nodeFunc: () => [NodeWrapper | undefined, Error | undefined],
|
|
22
|
+
) => {
|
|
23
|
+
function use(name?: string): [TModule | undefined, Error | undefined]
|
|
24
|
+
function use(name: string | undefined, wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
25
|
+
function use(wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
26
|
+
function use(address: string): [TModule | undefined, Error | undefined]
|
|
27
|
+
function use(address: string, wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
28
|
+
function use(
|
|
29
|
+
nameOrAddressOrWrapOrAccount?: string | boolean | Account,
|
|
30
|
+
wrap: boolean | Account = false,
|
|
31
|
+
): [TWrapper | TModule | undefined, Error | undefined] {
|
|
32
|
+
const [node, nodeError] = nodeFunc()
|
|
33
|
+
const shouldWrap = typeof nameOrAddressOrWrapOrAccount === 'boolean' ? nameOrAddressOrWrapOrAccount : wrap
|
|
34
|
+
const account = typeof nameOrAddressOrWrapOrAccount === 'object' ? nameOrAddressOrWrapOrAccount : typeof wrap === 'boolean' ? undefined : wrap
|
|
35
|
+
const nameOrAddress = typeof nameOrAddressOrWrapOrAccount === 'string' ? nameOrAddressOrWrapOrAccount : undefined
|
|
36
|
+
const [module, setModule] = useState<TModule | TWrapper>()
|
|
37
|
+
const [error, setError] = useState<Error>()
|
|
38
|
+
useAsyncEffect(
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
async (mounted) => {
|
|
41
|
+
try {
|
|
42
|
+
if (nodeError) {
|
|
43
|
+
setError(nodeError)
|
|
44
|
+
setModule(undefined)
|
|
45
|
+
} else {
|
|
46
|
+
const module = await node?.resolve<TModule>(nameOrAddress)
|
|
47
|
+
const finalModule = shouldWrap ? wrapFunc(module, account) : module
|
|
48
|
+
if (mounted()) {
|
|
49
|
+
setModule(finalModule)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch (ex) {
|
|
53
|
+
if (mounted()) {
|
|
54
|
+
setError(ex as Error)
|
|
55
|
+
setModule(undefined)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[wrap, node, nameOrAddress, nodeError, shouldWrap, account],
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return [module, error]
|
|
63
|
+
}
|
|
64
|
+
return use
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const useNode = createUseModuleHook<NodeModule, NodeWrapper>(NodeWrapper.wrap, () => useProvidedNode(true))
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { NodeModule, NodeWrapper } from '@xyo-network/node'
|
|
2
|
-
import { useContext } from 'react'
|
|
2
|
+
import { useContext, useState } from 'react'
|
|
3
3
|
|
|
4
4
|
import { NodeContext } from '../contexts'
|
|
5
5
|
|
|
6
|
-
function useProvidedNodeFunc(wrap?:
|
|
7
|
-
function useProvidedNodeFunc(wrap:
|
|
8
|
-
function useProvidedNodeFunc(wrap
|
|
6
|
+
function useProvidedNodeFunc(wrap?: undefined): [NodeModule | undefined, Error | undefined]
|
|
7
|
+
function useProvidedNodeFunc(wrap: false): [NodeModule | undefined, Error | undefined]
|
|
8
|
+
function useProvidedNodeFunc(wrap: true): [NodeWrapper | undefined, Error | undefined]
|
|
9
|
+
function useProvidedNodeFunc(wrap: true | false | undefined): [NodeModule | NodeWrapper | undefined, Error | undefined] {
|
|
9
10
|
const { node } = useContext(NodeContext)
|
|
11
|
+
const [wrappedNode, setWrappedNode] = useState<NodeWrapper>()
|
|
12
|
+
const [error, setError] = useState<Error>()
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
try {
|
|
15
|
+
if (wrap) {
|
|
16
|
+
const wrappedNode = wrap ? NodeWrapper.wrap(node) : undefined
|
|
17
|
+
setWrappedNode(wrappedNode)
|
|
18
|
+
setError(undefined)
|
|
19
|
+
}
|
|
20
|
+
} catch (ex) {
|
|
21
|
+
setError(ex as Error)
|
|
22
|
+
}
|
|
23
|
+
return [wrap ? wrappedNode : node, error]
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
export const useProvidedNode = useProvidedNodeFunc
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createUseModuleHook = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
6
|
-
const react_shared_1 = require("@xylabs/react-shared");
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const createUseModuleHook = (wrapFunc, useNodeHook) => {
|
|
9
|
-
function use(nameOrAddressOrWrapOrAccount, wrap = false) {
|
|
10
|
-
const shouldWrap = typeof nameOrAddressOrWrapOrAccount === 'boolean' ? nameOrAddressOrWrapOrAccount : wrap;
|
|
11
|
-
const account = typeof nameOrAddressOrWrapOrAccount === 'object' ? nameOrAddressOrWrapOrAccount : typeof wrap === 'boolean' ? undefined : wrap;
|
|
12
|
-
const nameOrAddress = typeof nameOrAddressOrWrapOrAccount === 'string' ? nameOrAddressOrWrapOrAccount : undefined;
|
|
13
|
-
const [node, nodeError] = useNodeHook(nameOrAddress, true);
|
|
14
|
-
const [module, setModule] = (0, react_1.useState)();
|
|
15
|
-
const [error, setError] = (0, react_1.useState)();
|
|
16
|
-
(0, react_shared_1.useAsyncEffect)(
|
|
17
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
18
|
-
(mounted) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
try {
|
|
20
|
-
if (nodeError) {
|
|
21
|
-
setError(nodeError);
|
|
22
|
-
setModule(undefined);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const module = yield (node === null || node === void 0 ? void 0 : node.resolve(nameOrAddress));
|
|
26
|
-
const finalModule = shouldWrap ? wrapFunc(module, account) : module;
|
|
27
|
-
if (mounted()) {
|
|
28
|
-
setModule(finalModule);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (ex) {
|
|
33
|
-
if (mounted()) {
|
|
34
|
-
setError(ex);
|
|
35
|
-
setModule(undefined);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}), [wrap, node, nameOrAddress, nodeError, shouldWrap, account]);
|
|
39
|
-
return [module, error];
|
|
40
|
-
}
|
|
41
|
-
return use;
|
|
42
|
-
};
|
|
43
|
-
exports.createUseModuleHook = createUseModuleHook;
|
|
44
|
-
//# sourceMappingURL=createUseModuleHook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUseModuleHook.js","sourceRoot":"","sources":["../../../src/hooks/createUseModuleHook.tsx"],"names":[],"mappings":";;;;AAAA,+CAA+C;AAC/C,uDAAqD;AAIrD,iCAAgC;AAOzB,MAAM,mBAAmB,GAAG,CAKjC,QAAmB,EACnB,WAA4G,EAC5G,EAAE;IAMF,SAAS,GAAG,CACV,4BAAyD,EACzD,OAA0B,KAAK;QAE/B,MAAM,UAAU,GAAG,OAAO,4BAA4B,KAAK,SAAS,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAI,CAAA;QAC1G,MAAM,OAAO,GAAG,OAAO,4BAA4B,KAAK,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;QAC9I,MAAM,aAAa,GAAG,OAAO,4BAA4B,KAAK,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,SAAS,CAAA;QACjH,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;QAC1D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,GAAsB,CAAA;QAC1D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,GAAS,CAAA;QAC3C,IAAA,6BAAc;QACZ,uDAAuD;QACvD,CAAO,OAAO,EAAE,EAAE;YAChB,IAAI;gBACF,IAAI,SAAS,EAAE;oBACb,QAAQ,CAAC,SAAS,CAAC,CAAA;oBACnB,SAAS,CAAC,SAAS,CAAC,CAAA;iBACrB;qBAAM;oBACL,MAAM,MAAM,GAAG,MAAM,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAU,aAAa,CAAC,CAAA,CAAA;oBAC1D,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;oBACnE,IAAI,OAAO,EAAE,EAAE;wBACb,SAAS,CAAC,WAAW,CAAC,CAAA;qBACvB;iBACF;aACF;YAAC,OAAO,EAAE,EAAE;gBACX,IAAI,OAAO,EAAE,EAAE;oBACb,QAAQ,CAAC,EAAW,CAAC,CAAA;oBACrB,SAAS,CAAC,SAAS,CAAC,CAAA;iBACrB;aACF;QACH,CAAC,CAAA,EACD,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAC5D,CAAA;QAED,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACxB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAlDY,QAAA,mBAAmB,uBAkD/B"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
import { useAsyncEffect } from '@xylabs/react-shared';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
export const createUseModuleHook = (wrapFunc, useNodeHook) => {
|
|
5
|
-
function use(nameOrAddressOrWrapOrAccount, wrap = false) {
|
|
6
|
-
const shouldWrap = typeof nameOrAddressOrWrapOrAccount === 'boolean' ? nameOrAddressOrWrapOrAccount : wrap;
|
|
7
|
-
const account = typeof nameOrAddressOrWrapOrAccount === 'object' ? nameOrAddressOrWrapOrAccount : typeof wrap === 'boolean' ? undefined : wrap;
|
|
8
|
-
const nameOrAddress = typeof nameOrAddressOrWrapOrAccount === 'string' ? nameOrAddressOrWrapOrAccount : undefined;
|
|
9
|
-
const [node, nodeError] = useNodeHook(nameOrAddress, true);
|
|
10
|
-
const [module, setModule] = useState();
|
|
11
|
-
const [error, setError] = useState();
|
|
12
|
-
useAsyncEffect(
|
|
13
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
-
async (mounted) => {
|
|
15
|
-
try {
|
|
16
|
-
if (nodeError) {
|
|
17
|
-
setError(nodeError);
|
|
18
|
-
setModule(undefined);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const module = await node?.resolve(nameOrAddress);
|
|
22
|
-
const finalModule = shouldWrap ? wrapFunc(module, account) : module;
|
|
23
|
-
if (mounted()) {
|
|
24
|
-
setModule(finalModule);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (ex) {
|
|
29
|
-
if (mounted()) {
|
|
30
|
-
setError(ex);
|
|
31
|
-
setModule(undefined);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}, [wrap, node, nameOrAddress, nodeError, shouldWrap, account]);
|
|
35
|
-
return [module, error];
|
|
36
|
-
}
|
|
37
|
-
return use;
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=createUseModuleHook.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUseModuleHook.js","sourceRoot":"","sources":["../../../src/hooks/createUseModuleHook.tsx"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAIrD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAOhC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAKjC,QAAmB,EACnB,WAA4G,EAC5G,EAAE;IAMF,SAAS,GAAG,CACV,4BAAyD,EACzD,OAA0B,KAAK;QAE/B,MAAM,UAAU,GAAG,OAAO,4BAA4B,KAAK,SAAS,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,IAAI,CAAA;QAC1G,MAAM,OAAO,GAAG,OAAO,4BAA4B,KAAK,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;QAC9I,MAAM,aAAa,GAAG,OAAO,4BAA4B,KAAK,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,SAAS,CAAA;QACjH,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,WAAW,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;QAC1D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAsB,CAAA;QAC1D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAA;QAC3C,cAAc;QACZ,uDAAuD;QACvD,KAAK,EAAE,OAAO,EAAE,EAAE;YAChB,IAAI;gBACF,IAAI,SAAS,EAAE;oBACb,QAAQ,CAAC,SAAS,CAAC,CAAA;oBACnB,SAAS,CAAC,SAAS,CAAC,CAAA;iBACrB;qBAAM;oBACL,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,OAAO,CAAU,aAAa,CAAC,CAAA;oBAC1D,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;oBACnE,IAAI,OAAO,EAAE,EAAE;wBACb,SAAS,CAAC,WAAW,CAAC,CAAA;qBACvB;iBACF;aACF;YAAC,OAAO,EAAE,EAAE;gBACX,IAAI,OAAO,EAAE,EAAE;oBACb,QAAQ,CAAC,EAAW,CAAC,CAAA;oBACrB,SAAS,CAAC,SAAS,CAAC,CAAA;iBACrB;aACF;QACH,CAAC,EACD,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAC5D,CAAA;QAED,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACxB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Account } from '@xyo-network/account';
|
|
2
|
-
import { Module, ModuleWrapper } from '@xyo-network/module';
|
|
3
|
-
import { NodeWrapper } from '@xyo-network/node';
|
|
4
|
-
export type WrapFunc<TModule extends Module = Module, TWrapper extends ModuleWrapper = ModuleWrapper> = (module?: TModule, account?: Account) => TWrapper | undefined;
|
|
5
|
-
export declare const createUseModuleHook: <TModule extends Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
6
|
-
name?: string | undefined;
|
|
7
|
-
security?: {
|
|
8
|
-
allowAnonymous?: boolean | undefined;
|
|
9
|
-
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
10
|
-
disallowed?: Record<string, string[]> | undefined;
|
|
11
|
-
} | undefined;
|
|
12
|
-
storeQueries?: boolean | undefined;
|
|
13
|
-
} & {
|
|
14
|
-
schema: string;
|
|
15
|
-
}> = Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
16
|
-
name?: string | undefined;
|
|
17
|
-
security?: {
|
|
18
|
-
allowAnonymous?: boolean | undefined;
|
|
19
|
-
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
20
|
-
disallowed?: Record<string, string[]> | undefined;
|
|
21
|
-
} | undefined;
|
|
22
|
-
storeQueries?: boolean | undefined;
|
|
23
|
-
} & {
|
|
24
|
-
schema: string;
|
|
25
|
-
}>, TWrapper extends ModuleWrapper<Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
26
|
-
name?: string | undefined;
|
|
27
|
-
security?: {
|
|
28
|
-
allowAnonymous?: boolean | undefined;
|
|
29
|
-
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
30
|
-
disallowed?: Record<string, string[]> | undefined;
|
|
31
|
-
} | undefined;
|
|
32
|
-
storeQueries?: boolean | undefined;
|
|
33
|
-
} & {
|
|
34
|
-
schema: string;
|
|
35
|
-
}>> = ModuleWrapper<Module<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
36
|
-
name?: string | undefined;
|
|
37
|
-
security?: {
|
|
38
|
-
allowAnonymous?: boolean | undefined;
|
|
39
|
-
allowed?: Record<string, (string | import("@xyo-network/module").CosigningAddressSet)[]> | undefined;
|
|
40
|
-
disallowed?: Record<string, string[]> | undefined;
|
|
41
|
-
} | undefined;
|
|
42
|
-
storeQueries?: boolean | undefined;
|
|
43
|
-
} & {
|
|
44
|
-
schema: string;
|
|
45
|
-
}>>, TWrapFunc extends WrapFunc<TModule, TWrapper> = WrapFunc<TModule, TWrapper>>(wrapFunc: TWrapFunc, useNodeHook: (nodeOrAddress: string | undefined, wrap: true) => [NodeWrapper | undefined, Error | undefined]) => {
|
|
46
|
-
(name?: string): [TModule | undefined, Error | undefined];
|
|
47
|
-
(name: string | undefined, wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
48
|
-
(wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
49
|
-
(address: string): [TModule | undefined, Error | undefined];
|
|
50
|
-
(address: string, wrap: true | Account): [TWrapper | undefined, Error | undefined];
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=createUseModuleHook.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createUseModuleHook.d.ts","sourceRoot":"","sources":["../../../src/hooks/createUseModuleHook.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,MAAM,MAAM,QAAQ,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAAE,QAAQ,SAAS,aAAa,GAAG,aAAa,IAAI,CACtG,MAAM,CAAC,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,OAAO,KACd,QAAQ,GAAG,SAAS,CAAA;AAEzB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oIAMD,MAAM,GAAG,SAAS,QAAQ,IAAI,KAAK,CAAC,WAAW,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAAC;YAExF,MAAM;WACP,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG,OAAO;WACxC,IAAI,GAAG,OAAO;cACX,MAAM;cACN,MAAM,QAAQ,IAAI,GAAG,OAAO;CAsCnD,CAAA"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
import { useAsyncEffect } from '@xylabs/react-shared'
|
|
3
|
-
import { Account } from '@xyo-network/account'
|
|
4
|
-
import { Module, ModuleWrapper } from '@xyo-network/module'
|
|
5
|
-
import { NodeWrapper } from '@xyo-network/node'
|
|
6
|
-
import { useState } from 'react'
|
|
7
|
-
|
|
8
|
-
export type WrapFunc<TModule extends Module = Module, TWrapper extends ModuleWrapper = ModuleWrapper> = (
|
|
9
|
-
module?: TModule,
|
|
10
|
-
account?: Account,
|
|
11
|
-
) => TWrapper | undefined
|
|
12
|
-
|
|
13
|
-
export const createUseModuleHook = <
|
|
14
|
-
TModule extends Module = Module,
|
|
15
|
-
TWrapper extends ModuleWrapper = ModuleWrapper,
|
|
16
|
-
TWrapFunc extends WrapFunc<TModule, TWrapper> = WrapFunc<TModule, TWrapper>,
|
|
17
|
-
>(
|
|
18
|
-
wrapFunc: TWrapFunc,
|
|
19
|
-
useNodeHook: (nodeOrAddress: string | undefined, wrap: true) => [NodeWrapper | undefined, Error | undefined],
|
|
20
|
-
) => {
|
|
21
|
-
function use(name?: string): [TModule | undefined, Error | undefined]
|
|
22
|
-
function use(name: string | undefined, wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
23
|
-
function use(wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
24
|
-
function use(address: string): [TModule | undefined, Error | undefined]
|
|
25
|
-
function use(address: string, wrap: true | Account): [TWrapper | undefined, Error | undefined]
|
|
26
|
-
function use(
|
|
27
|
-
nameOrAddressOrWrapOrAccount?: string | boolean | Account,
|
|
28
|
-
wrap: boolean | Account = false,
|
|
29
|
-
): [TWrapper | TModule | undefined, Error | undefined] {
|
|
30
|
-
const shouldWrap = typeof nameOrAddressOrWrapOrAccount === 'boolean' ? nameOrAddressOrWrapOrAccount : wrap
|
|
31
|
-
const account = typeof nameOrAddressOrWrapOrAccount === 'object' ? nameOrAddressOrWrapOrAccount : typeof wrap === 'boolean' ? undefined : wrap
|
|
32
|
-
const nameOrAddress = typeof nameOrAddressOrWrapOrAccount === 'string' ? nameOrAddressOrWrapOrAccount : undefined
|
|
33
|
-
const [node, nodeError] = useNodeHook(nameOrAddress, true)
|
|
34
|
-
const [module, setModule] = useState<TModule | TWrapper>()
|
|
35
|
-
const [error, setError] = useState<Error>()
|
|
36
|
-
useAsyncEffect(
|
|
37
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
-
async (mounted) => {
|
|
39
|
-
try {
|
|
40
|
-
if (nodeError) {
|
|
41
|
-
setError(nodeError)
|
|
42
|
-
setModule(undefined)
|
|
43
|
-
} else {
|
|
44
|
-
const module = await node?.resolve<TModule>(nameOrAddress)
|
|
45
|
-
const finalModule = shouldWrap ? wrapFunc(module, account) : module
|
|
46
|
-
if (mounted()) {
|
|
47
|
-
setModule(finalModule)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
} catch (ex) {
|
|
51
|
-
if (mounted()) {
|
|
52
|
-
setError(ex as Error)
|
|
53
|
-
setModule(undefined)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
[wrap, node, nameOrAddress, nodeError, shouldWrap, account],
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
return [module, error]
|
|
61
|
-
}
|
|
62
|
-
return use
|
|
63
|
-
}
|