@xyo-network/react-node 2.55.8 → 2.55.10
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/useModule.js +2 -2
- package/dist/cjs/hooks/useModule.js.map +1 -1
- package/dist/cjs/hooks/useModules.js +18 -47
- package/dist/cjs/hooks/useModules.js.map +1 -1
- package/dist/cjs/hooks/useProvidedNode.js +5 -13
- package/dist/cjs/hooks/useProvidedNode.js.map +1 -1
- package/dist/cjs/hooks/useWrappedModule.js +15 -13
- package/dist/cjs/hooks/useWrappedModule.js.map +1 -1
- package/dist/docs.json +54 -54
- package/dist/esm/hooks/useModule.js +2 -2
- package/dist/esm/hooks/useModule.js.map +1 -1
- package/dist/esm/hooks/useModules.js +18 -47
- package/dist/esm/hooks/useModules.js.map +1 -1
- package/dist/esm/hooks/useProvidedNode.js +6 -14
- package/dist/esm/hooks/useProvidedNode.js.map +1 -1
- package/dist/esm/hooks/useWrappedModule.js +15 -13
- package/dist/esm/hooks/useWrappedModule.js.map +1 -1
- package/dist/types/hooks/useModule.d.ts +2 -2
- package/dist/types/hooks/useModule.d.ts.map +1 -1
- package/dist/types/hooks/useModules.d.ts.map +1 -1
- package/dist/types/hooks/useProvidedNode.d.ts +2 -2
- package/dist/types/hooks/useProvidedNode.d.ts.map +1 -1
- package/dist/types/hooks/useWrappedModule.d.ts +3 -3
- package/dist/types/hooks/useWrappedModule.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/hooks/useModule.tsx +3 -3
- package/src/hooks/useModules.ts +38 -66
- package/src/hooks/useProvidedNode.tsx +7 -16
- package/src/hooks/useWrappedModule.tsx +12 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useAsyncEffect } from '@xylabs/react-async-effect';
|
|
2
2
|
import { useMemo, useState } from 'react';
|
|
3
3
|
import { useProvidedWrappedNode } from './useProvidedNode';
|
|
4
|
-
export const useModule = (nameOrAddressOrFilter,
|
|
4
|
+
export const useModule = (nameOrAddressOrFilter, wallet, logger) => {
|
|
5
5
|
const nameOrAddress = useMemo(() => (typeof nameOrAddressOrFilter === 'string' ? nameOrAddressOrFilter : undefined), [nameOrAddressOrFilter]);
|
|
6
6
|
const filter = useMemo(() => (typeof nameOrAddressOrFilter === 'object' ? nameOrAddressOrFilter : undefined), [nameOrAddressOrFilter]);
|
|
7
|
-
const [node, nodeError] = useProvidedWrappedNode(
|
|
7
|
+
const [node, nodeError] = useProvidedWrappedNode(wallet);
|
|
8
8
|
const [module, setModule] = useState();
|
|
9
9
|
const [error, setError] = useState();
|
|
10
10
|
const address = useMemo(() => module?.address, [module]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModule.js","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAM3D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,qBAA6C,EAC7C,
|
|
1
|
+
{"version":3,"file":"useModule.js","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAM3D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,qBAA6C,EAC7C,MAAuB,EACvB,MAAe,EAC2B,EAAE;IAC5C,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,qBA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AAO,CAAC,CAAA;gBAC5B,QAAQ,CAAC,KAAK,CAAC,CAAA;gBACf,SAAS,CAAC,SAAS,CAAC,CAAA;aACrB;SACF;IACH,CAAC,EACD,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAC1D,CAAA;IAED,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AACxB,CAAC,CAAA"}
|
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
3
|
import { useProvidedWrappedNode } from './useProvidedNode';
|
|
4
4
|
export const useModules = (filter, logger) => {
|
|
5
5
|
const [node, nodeError] = useProvidedWrappedNode();
|
|
6
|
-
const [modules, setModules] = useState();
|
|
7
|
-
const [error, setError] = useState();
|
|
8
6
|
const modulesLength = useRef();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (nodeError || !node || !filter) {
|
|
14
|
-
if (mounted()) {
|
|
15
|
-
nodeError && logger?.error(nodeError.message);
|
|
16
|
-
modulesLength.current = undefined;
|
|
17
|
-
setModules(undefined);
|
|
18
|
-
setError(nodeError);
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const eventUnsubscribe = [];
|
|
23
|
-
try {
|
|
24
|
-
const getModulesFromResolution = async () => {
|
|
7
|
+
const eventUnsubscribe = [];
|
|
8
|
+
const [resolvedModules, resolvedModulesError] = usePromise(async () => {
|
|
9
|
+
const getModulesFromResolution = async () => {
|
|
10
|
+
if (node) {
|
|
25
11
|
const resolvedModules = await node.resolve(filter);
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setModules(resolvedModules);
|
|
31
|
-
setError(undefined);
|
|
32
|
-
}
|
|
12
|
+
if (resolvedModules?.length !== modulesLength.current) {
|
|
13
|
+
logger?.debug(`getModulesFromResolution-setting: [${resolvedModules?.length}]`);
|
|
14
|
+
modulesLength.current = resolvedModules?.length;
|
|
15
|
+
return resolvedModules;
|
|
33
16
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const modules = await getModulesFromResolution();
|
|
20
|
+
if (node) {
|
|
36
21
|
eventUnsubscribe.push(node.on('moduleAttached', async () => {
|
|
37
22
|
logger?.debug('moduleAttached: getModulesFromResolution');
|
|
38
23
|
await getModulesFromResolution();
|
|
@@ -41,29 +26,15 @@ export const useModules = (filter, logger) => {
|
|
|
41
26
|
logger?.debug('moduleDetached: getModulesFromResolution');
|
|
42
27
|
await getModulesFromResolution();
|
|
43
28
|
}));
|
|
44
|
-
//TODO: Obviously get rid of this timer
|
|
45
|
-
const timeoutFunc = async () => {
|
|
46
|
-
await getModulesFromResolution();
|
|
47
|
-
if (mounted()) {
|
|
48
|
-
setTimeout(timeoutFunc, 1000);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
setTimeout(timeoutFunc, 1000);
|
|
52
|
-
}
|
|
53
|
-
catch (ex) {
|
|
54
|
-
if (mounted()) {
|
|
55
|
-
const error = ex;
|
|
56
|
-
logger?.error(`useModules: useAsyncEffect [${error.message}]`);
|
|
57
|
-
modulesLength.current = undefined;
|
|
58
|
-
setModules(undefined);
|
|
59
|
-
setError(error);
|
|
60
|
-
}
|
|
61
29
|
}
|
|
30
|
+
return modules;
|
|
31
|
+
}, [node, filter, logger]);
|
|
32
|
+
useEffect(() => {
|
|
62
33
|
return () => {
|
|
63
34
|
//unsubscribe events
|
|
64
35
|
eventUnsubscribe.forEach((func) => func());
|
|
65
36
|
};
|
|
66
37
|
}, [filter, node, logger, nodeError]);
|
|
67
|
-
return [
|
|
38
|
+
return [resolvedModules, resolvedModulesError];
|
|
68
39
|
};
|
|
69
40
|
//# sourceMappingURL=useModules.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModules.js","sourceRoot":"","sources":["../../../src/hooks/useModules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useModules.js","sourceRoot":"","sources":["../../../src/hooks/useModules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAIlD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE1D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAkC,MAAqB,EAAE,MAAe,EAA8C,EAAE;IAChJ,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,sBAAsB,EAAE,CAAA;IAElD,MAAM,aAAa,GAAG,MAAM,EAAU,CAAA;IAEtC,MAAM,gBAAgB,GAA+B,EAAE,CAAA;IAEvD,MAAM,CAAC,eAAe,EAAE,oBAAoB,CAAC,GAAG,UAAU,CAAwB,KAAK,IAAI,EAAE;QAC3F,MAAM,wBAAwB,GAAG,KAAK,IAAI,EAAE;YAC1C,IAAI,IAAI,EAAE;gBACR,MAAM,eAAe,GAA0B,MAAM,IAAI,CAAC,OAAO,CAAU,MAAM,CAAC,CAAA;gBAClF,IAAI,eAAe,EAAE,MAAM,KAAK,aAAa,CAAC,OAAO,EAAE;oBACrD,MAAM,EAAE,KAAK,CAAC,sCAAsC,eAAe,EAAE,MAAM,GAAG,CAAC,CAAA;oBAC/E,aAAa,CAAC,OAAO,GAAG,eAAe,EAAE,MAAM,CAAA;oBAC/C,OAAO,eAAe,CAAA;iBACvB;aACF;QACH,CAAC,CAAA;QAED,MAAM,OAAO,GAAG,MAAM,wBAAwB,EAAE,CAAA;QAEhD,IAAI,IAAI,EAAE;YACR,gBAAgB,CAAC,IAAI,CACnB,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;gBACnC,MAAM,EAAE,KAAK,CAAC,0CAA0C,CAAC,CAAA;gBACzD,MAAM,wBAAwB,EAAE,CAAA;YAClC,CAAC,CAAC,CACH,CAAA;YACD,gBAAgB,CAAC,IAAI,CACnB,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;gBACnC,MAAM,EAAE,KAAK,CAAC,0CAA0C,CAAC,CAAA;gBACzD,MAAM,wBAAwB,EAAE,CAAA;YAClC,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,OAAO,CAAA;IAChB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAE1B,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,oBAAoB;YACpB,gBAAgB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;QAC5C,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;IAErC,OAAO,CAAC,eAAe,EAAE,oBAAoB,CAAC,CAAA;AAChD,CAAC,CAAA"}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
import { NodeWrapper } from '@xyo-network/node';
|
|
2
2
|
import { NodeContext } from '@xyo-network/react-node-context';
|
|
3
|
-
import {
|
|
3
|
+
import { useWallet } from '@xyo-network/react-wallet';
|
|
4
4
|
import { useContext, useEffect, useState } from 'react';
|
|
5
5
|
export const useProvidedNode = () => {
|
|
6
6
|
const { node } = useContext(NodeContext);
|
|
7
7
|
return [node];
|
|
8
8
|
};
|
|
9
|
-
export const useProvidedWrappedNode = (
|
|
10
|
-
const [
|
|
9
|
+
export const useProvidedWrappedNode = (wallet) => {
|
|
10
|
+
const [walletToUse] = useWallet({ wallet });
|
|
11
11
|
const [node] = useProvidedNode();
|
|
12
12
|
const [wrappedNode, setWrappedNode] = useState();
|
|
13
13
|
const [error, setError] = useState();
|
|
14
|
-
/*
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (!accountToUse) {
|
|
17
|
-
const error = Error('useProvidedWrappedNode requires either an Account context or account parameter')
|
|
18
|
-
setError(error)
|
|
19
|
-
}
|
|
20
|
-
}, [accountToUse])
|
|
21
|
-
*/
|
|
22
14
|
useEffect(() => {
|
|
23
15
|
try {
|
|
24
|
-
if (node &&
|
|
25
|
-
setWrappedNode(NodeWrapper.wrap(node,
|
|
16
|
+
if (node && walletToUse) {
|
|
17
|
+
setWrappedNode(NodeWrapper.wrap(node, walletToUse));
|
|
26
18
|
setError(undefined);
|
|
27
19
|
}
|
|
28
20
|
else {
|
|
@@ -34,7 +26,7 @@ export const useProvidedWrappedNode = (account) => {
|
|
|
34
26
|
setWrappedNode(undefined);
|
|
35
27
|
setError(ex);
|
|
36
28
|
}
|
|
37
|
-
}, [node,
|
|
29
|
+
}, [node, walletToUse]);
|
|
38
30
|
return [wrappedNode, error];
|
|
39
31
|
};
|
|
40
32
|
//# sourceMappingURL=useProvidedNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProvidedNode.js","sourceRoot":"","sources":["../../../src/hooks/useProvidedNode.tsx"],"names":[],"mappings":"
|
|
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,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEvD,MAAM,CAAC,MAAM,eAAe,GAAG,GAA6B,EAAE;IAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAAA;IAExC,OAAO,CAAC,IAAI,CAAC,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,MAAuB,EAAgD,EAAE;IAC9G,MAAM,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3C,MAAM,CAAC,IAAI,CAAC,GAAG,eAAe,EAAE,CAAA;IAChC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,EAAe,CAAA;IAC7D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAS,CAAA;IAE3C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI;YACF,IAAI,IAAI,IAAI,WAAW,EAAE;gBACvB,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAA;gBACnD,QAAQ,CAAC,SAAS,CAAC,CAAA;aACpB;iBAAM;gBACL,cAAc,CAAC,SAAS,CAAC,CAAA;gBACzB,QAAQ,CAAC,SAAS,CAAC,CAAA;aACpB;SACF;QAAC,OAAO,EAAE,EAAE;YACX,cAAc,CAAC,SAAS,CAAC,CAAA;YACzB,QAAQ,CAAC,EAAW,CAAC,CAAA;SACtB;IACH,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAA;IAEvB,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;AAC7B,CAAC,CAAA"}
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import { ModuleWrapper } from '@xyo-network/module';
|
|
2
|
-
import {
|
|
2
|
+
import { useWallet } from '@xyo-network/react-wallet';
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import { useModule } from './useModule';
|
|
5
5
|
export const WrappedModuleHookFactory = (wrapperObject, name) => {
|
|
6
|
-
const useHook = (nameOrAddress,
|
|
6
|
+
const useHook = (nameOrAddress, wallet, logger) => {
|
|
7
7
|
logger?.debug(`Render: ${name}`);
|
|
8
|
-
const [
|
|
8
|
+
const [walletToUse] = useWallet({ wallet });
|
|
9
9
|
const [module, moduleError] = useModule(nameOrAddress ?? {
|
|
10
10
|
query: [wrapperObject.requiredQueries],
|
|
11
|
-
},
|
|
11
|
+
}, walletToUse, logger);
|
|
12
12
|
const [wrapper, setWrapper] = useState();
|
|
13
13
|
const [error, setError] = useState();
|
|
14
|
+
/*
|
|
14
15
|
useEffect(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}, [
|
|
16
|
+
if (!walletToUse) {
|
|
17
|
+
const error = Error('Module hooks require either an Account context or account parameter')
|
|
18
|
+
//console.error(error.message)
|
|
19
|
+
setError(error)
|
|
20
|
+
}
|
|
21
|
+
}, [walletToUse])
|
|
22
|
+
*/
|
|
21
23
|
useEffect(() => {
|
|
22
|
-
if (module &&
|
|
24
|
+
if (module && walletToUse) {
|
|
23
25
|
try {
|
|
24
|
-
const wrapper = wrapperObject.wrap(module,
|
|
26
|
+
const wrapper = wrapperObject.wrap(module, walletToUse);
|
|
25
27
|
setWrapper(wrapper);
|
|
26
28
|
setError(undefined);
|
|
27
29
|
}
|
|
@@ -34,7 +36,7 @@ export const WrappedModuleHookFactory = (wrapperObject, name) => {
|
|
|
34
36
|
setWrapper(undefined);
|
|
35
37
|
setError(moduleError);
|
|
36
38
|
}
|
|
37
|
-
}, [module,
|
|
39
|
+
}, [module, wallet, moduleError, walletToUse]);
|
|
38
40
|
return [wrapper, error];
|
|
39
41
|
};
|
|
40
42
|
return useHook;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWrappedModule.js","sourceRoot":"","sources":["../../../src/hooks/useWrappedModule.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useWrappedModule.js","sourceRoot":"","sources":["../../../src/hooks/useWrappedModule.tsx"],"names":[],"mappings":"AACA,OAAO,EAA8B,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC/E,OA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MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAA;QAE9C,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACzB,CAAC,CAAA;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AccountInstance } from '@xyo-network/account-model';
|
|
2
1
|
import { Logger } from '@xyo-network/core';
|
|
3
2
|
import { Module, ModuleFilter } from '@xyo-network/module-model';
|
|
3
|
+
import { WalletInstance } from '@xyo-network/wallet-model';
|
|
4
4
|
export declare const useModule: <TModule extends Module<import("@xyo-network/module").ModuleParams<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
5
5
|
readonly archivist?: import("@xyo-network/module").ArchivistModuleConfig | undefined;
|
|
6
6
|
readonly name?: string | undefined;
|
|
@@ -57,5 +57,5 @@ export declare const useModule: <TModule extends Module<import("@xyo-network/mod
|
|
|
57
57
|
readonly storeQueries?: boolean | undefined;
|
|
58
58
|
} & Omit<undefined, "schema">, "schema"> & {
|
|
59
59
|
schema: string;
|
|
60
|
-
}, "schema">, undefined>, import("@xyo-network/module").ModuleEventData>>(nameOrAddressOrFilter?: string | ModuleFilter,
|
|
60
|
+
}, "schema">, undefined>, import("@xyo-network/module").ModuleEventData>>(nameOrAddressOrFilter?: string | ModuleFilter, wallet?: WalletInstance, logger?: Logger) => [TModule | undefined, Error | undefined];
|
|
61
61
|
//# sourceMappingURL=useModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModule.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAK1D,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kGACI,MAAM,GAAG,YAAY,WACpC,cAAc,WACd,MAAM,6CAkEhB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModules.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAKhE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mFAA8C,YAAY,WAAW,MAAM,+
|
|
1
|
+
{"version":3,"file":"useModules.d.ts","sourceRoot":"","sources":["../../../src/hooks/useModules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAKhE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mFAA8C,YAAY,WAAW,MAAM,+CA8CjG,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AccountInstance } from '@xyo-network/account-model';
|
|
2
1
|
import { NodeModule, NodeWrapper } from '@xyo-network/node';
|
|
2
|
+
import { WalletInstance } from '@xyo-network/wallet-model';
|
|
3
3
|
export declare const useProvidedNode: () => [NodeModule | undefined];
|
|
4
|
-
export declare const useProvidedWrappedNode: (
|
|
4
|
+
export declare const useProvidedWrappedNode: (wallet?: WalletInstance) => [NodeWrapper | undefined, Error | undefined];
|
|
5
5
|
//# 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,
|
|
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;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAG1D,eAAO,MAAM,eAAe,QAAO,CAAC,UAAU,GAAG,SAAS,CAIzD,CAAA;AAED,eAAO,MAAM,sBAAsB,YAAa,cAAc,KAAG,CAAC,WAAW,GAAG,SAAS,EAAE,KAAK,GAAG,SAAS,CAsB3G,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AccountInstance } from '@xyo-network/account-model';
|
|
2
1
|
import { Logger } from '@xyo-network/core';
|
|
3
2
|
import { ConstructableModuleWrapper, ModuleWrapper } from '@xyo-network/module';
|
|
3
|
+
import { WalletInstance } from '@xyo-network/wallet-model';
|
|
4
4
|
export declare const WrappedModuleHookFactory: <TModuleWrapper extends ModuleWrapper<import("@xyo-network/module").Module<import("@xyo-network/module").ModuleParams<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
5
5
|
readonly archivist?: import("@xyo-network/module").ArchivistModuleConfig | undefined;
|
|
6
6
|
readonly name?: string | undefined;
|
|
@@ -29,8 +29,8 @@ export declare const WrappedModuleHookFactory: <TModuleWrapper extends ModuleWra
|
|
|
29
29
|
readonly storeQueries?: boolean | undefined;
|
|
30
30
|
} & Omit<undefined, "schema">, "schema"> & {
|
|
31
31
|
schema: string;
|
|
32
|
-
}, "schema">, undefined>, import("@xyo-network/module").ModuleEventData>>>(wrapperObject: ConstructableModuleWrapper<TModuleWrapper>, name?: string) => (nameOrAddress?: string,
|
|
33
|
-
export declare const useWrappedModule: (nameOrAddress?: string,
|
|
32
|
+
}, "schema">, undefined>, import("@xyo-network/module").ModuleEventData>>>(wrapperObject: ConstructableModuleWrapper<TModuleWrapper>, name?: string) => (nameOrAddress?: string, wallet?: WalletInstance, logger?: Logger) => [TModuleWrapper | undefined, Error | undefined];
|
|
33
|
+
export declare const useWrappedModule: (nameOrAddress?: string, wallet?: WalletInstance, logger?: Logger) => [ModuleWrapper<import("@xyo-network/module").Module<import("@xyo-network/module").ModuleParams<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
34
34
|
readonly archivist?: import("@xyo-network/module").ArchivistModuleConfig | undefined;
|
|
35
35
|
readonly name?: string | undefined;
|
|
36
36
|
readonly paging?: Record<string, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWrappedModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWrappedModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useWrappedModule.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWrappedModule.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAE/E,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAK1D,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;6IAE5B,MAAM,sBAEoB,MAAM,WAAW,cAAc,WAAW,MAAM,oDA2ClF,CAAA;AAED,eAAO,MAAM,gBAAgB,mBA7CM,MAAM,WAAW,cAAc,WAAW,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;yGA6CQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -11,18 +11,18 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@mui/lab": "^5.0.0-alpha.134",
|
|
14
|
-
"@xylabs/react-async-effect": "^2.17.
|
|
15
|
-
"@xylabs/react-flexbox": "^2.17.
|
|
16
|
-
"@xylabs/react-
|
|
17
|
-
"@
|
|
18
|
-
"@xyo-network/core": "^2.63.
|
|
19
|
-
"@xyo-network/module": "^2.63.
|
|
20
|
-
"@xyo-network/module-model": "^2.63.
|
|
21
|
-
"@xyo-network/node": "^2.63.
|
|
22
|
-
"@xyo-network/react-node-context": "^2.55.
|
|
23
|
-
"@xyo-network/react-node-provider": "^2.55.
|
|
24
|
-
"@xyo-network/react-wallet": "^2.55.
|
|
25
|
-
"@xyo-network/wallet-model": "^2.63.
|
|
14
|
+
"@xylabs/react-async-effect": "^2.17.6",
|
|
15
|
+
"@xylabs/react-flexbox": "^2.17.6",
|
|
16
|
+
"@xylabs/react-promise": "^2.17.6",
|
|
17
|
+
"@xylabs/react-shared": "^2.17.6",
|
|
18
|
+
"@xyo-network/core": "^2.63.10",
|
|
19
|
+
"@xyo-network/module": "^2.63.10",
|
|
20
|
+
"@xyo-network/module-model": "^2.63.10",
|
|
21
|
+
"@xyo-network/node": "^2.63.10",
|
|
22
|
+
"@xyo-network/react-node-context": "^2.55.10",
|
|
23
|
+
"@xyo-network/react-node-provider": "^2.55.10",
|
|
24
|
+
"@xyo-network/react-wallet": "^2.55.10",
|
|
25
|
+
"@xyo-network/wallet-model": "^2.63.10",
|
|
26
26
|
"lodash": "^4.17.21"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@types/lodash": "^4.14.195",
|
|
31
31
|
"@xylabs/ts-scripts-yarn3": "^2.17.17",
|
|
32
32
|
"@xylabs/tsconfig-react": "^2.17.17",
|
|
33
|
-
"@xyo-network/react-storybook": "^2.55.
|
|
34
|
-
"@xyo-network/react-wallet": "^2.55.
|
|
33
|
+
"@xyo-network/react-storybook": "^2.55.10",
|
|
34
|
+
"@xyo-network/react-wallet": "^2.55.10",
|
|
35
35
|
"typescript": "^5.1.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
},
|
|
87
87
|
"sideEffects": false,
|
|
88
88
|
"types": "dist/types/index.d.ts",
|
|
89
|
-
"version": "2.55.
|
|
89
|
+
"version": "2.55.10"
|
|
90
90
|
}
|
package/src/hooks/useModule.tsx
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
2
|
-
import { AccountInstance } from '@xyo-network/account-model'
|
|
3
2
|
import { Logger } from '@xyo-network/core'
|
|
4
3
|
import { EventUnsubscribeFunction } from '@xyo-network/module'
|
|
5
4
|
import { Module, ModuleFilter } from '@xyo-network/module-model'
|
|
6
5
|
import { ModuleAttachedEventArgs, ModuleDetachedEventArgs } from '@xyo-network/node'
|
|
6
|
+
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
7
7
|
import { useMemo, useState } from 'react'
|
|
8
8
|
|
|
9
9
|
import { useProvidedWrappedNode } from './useProvidedNode'
|
|
10
10
|
|
|
11
11
|
export const useModule = <TModule extends Module = Module>(
|
|
12
12
|
nameOrAddressOrFilter?: string | ModuleFilter,
|
|
13
|
-
|
|
13
|
+
wallet?: WalletInstance,
|
|
14
14
|
logger?: Logger,
|
|
15
15
|
): [TModule | undefined, Error | undefined] => {
|
|
16
16
|
const nameOrAddress = useMemo(() => (typeof nameOrAddressOrFilter === 'string' ? nameOrAddressOrFilter : undefined), [nameOrAddressOrFilter])
|
|
17
17
|
const filter = useMemo(() => (typeof nameOrAddressOrFilter === 'object' ? nameOrAddressOrFilter : undefined), [nameOrAddressOrFilter])
|
|
18
|
-
const [node, nodeError] = useProvidedWrappedNode(
|
|
18
|
+
const [node, nodeError] = useProvidedWrappedNode(wallet)
|
|
19
19
|
const [module, setModule] = useState<TModule>()
|
|
20
20
|
const [error, setError] = useState<Error>()
|
|
21
21
|
|
package/src/hooks/useModules.ts
CHANGED
|
@@ -1,83 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise'
|
|
2
2
|
import { Logger } from '@xyo-network/core'
|
|
3
3
|
import { EventUnsubscribeFunction } from '@xyo-network/module'
|
|
4
4
|
import { Module, ModuleFilter } from '@xyo-network/module-model'
|
|
5
|
-
import {
|
|
5
|
+
import { useEffect, useRef } from 'react'
|
|
6
6
|
|
|
7
7
|
import { useProvidedWrappedNode } from './useProvidedNode'
|
|
8
8
|
|
|
9
9
|
export const useModules = <TModule extends Module = Module>(filter?: ModuleFilter, logger?: Logger): [TModule[] | undefined, Error | undefined] => {
|
|
10
10
|
const [node, nodeError] = useProvidedWrappedNode()
|
|
11
|
-
const [modules, setModules] = useState<TModule[]>()
|
|
12
|
-
const [error, setError] = useState<Error>()
|
|
13
11
|
|
|
14
12
|
const modulesLength = useRef<number>()
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
const eventUnsubscribe: EventUnsubscribeFunction[] = []
|
|
15
|
+
|
|
16
|
+
const [resolvedModules, resolvedModulesError] = usePromise<TModule[] | undefined>(async () => {
|
|
17
|
+
const getModulesFromResolution = async () => {
|
|
18
|
+
if (node) {
|
|
19
|
+
const resolvedModules: TModule[] | undefined = await node.resolve<TModule>(filter)
|
|
20
|
+
if (resolvedModules?.length !== modulesLength.current) {
|
|
21
|
+
logger?.debug(`getModulesFromResolution-setting: [${resolvedModules?.length}]`)
|
|
22
|
+
modulesLength.current = resolvedModules?.length
|
|
23
|
+
return resolvedModules
|
|
26
24
|
}
|
|
27
|
-
return
|
|
28
25
|
}
|
|
26
|
+
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const getModulesFromResolution = async () => {
|
|
34
|
-
const resolvedModules: TModule[] | undefined = await node.resolve<TModule>(filter)
|
|
35
|
-
if (mounted()) {
|
|
36
|
-
if (resolvedModules.length !== modulesLength.current) {
|
|
37
|
-
logger?.debug(`getModulesFromResolution-setting: [${resolvedModules.length}]`)
|
|
38
|
-
modulesLength.current = resolvedModules.length
|
|
39
|
-
setModules(resolvedModules)
|
|
40
|
-
setError(undefined)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
await getModulesFromResolution()
|
|
28
|
+
const modules = await getModulesFromResolution()
|
|
45
29
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}),
|
|
51
|
-
)
|
|
52
|
-
eventUnsubscribe.push(
|
|
53
|
-
node.on('moduleDetached', async () => {
|
|
54
|
-
logger?.debug('moduleDetached: getModulesFromResolution')
|
|
55
|
-
await getModulesFromResolution()
|
|
56
|
-
}),
|
|
57
|
-
)
|
|
58
|
-
//TODO: Obviously get rid of this timer
|
|
59
|
-
const timeoutFunc = async () => {
|
|
30
|
+
if (node) {
|
|
31
|
+
eventUnsubscribe.push(
|
|
32
|
+
node.on('moduleAttached', async () => {
|
|
33
|
+
logger?.debug('moduleAttached: getModulesFromResolution')
|
|
60
34
|
await getModulesFromResolution()
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
return [modules, error]
|
|
35
|
+
}),
|
|
36
|
+
)
|
|
37
|
+
eventUnsubscribe.push(
|
|
38
|
+
node.on('moduleDetached', async () => {
|
|
39
|
+
logger?.debug('moduleDetached: getModulesFromResolution')
|
|
40
|
+
await getModulesFromResolution()
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
return modules
|
|
45
|
+
}, [node, filter, logger])
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
return () => {
|
|
49
|
+
//unsubscribe events
|
|
50
|
+
eventUnsubscribe.forEach((func) => func())
|
|
51
|
+
}
|
|
52
|
+
}, [filter, node, logger, nodeError])
|
|
53
|
+
|
|
54
|
+
return [resolvedModules, resolvedModulesError]
|
|
83
55
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AccountInstance } from '@xyo-network/account-model'
|
|
2
1
|
import { NodeModule, NodeWrapper } from '@xyo-network/node'
|
|
3
2
|
import { NodeContext } from '@xyo-network/react-node-context'
|
|
4
|
-
import {
|
|
3
|
+
import { useWallet } from '@xyo-network/react-wallet'
|
|
4
|
+
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
5
5
|
import { useContext, useEffect, useState } from 'react'
|
|
6
6
|
|
|
7
7
|
export const useProvidedNode = (): [NodeModule | undefined] => {
|
|
@@ -10,25 +10,16 @@ export const useProvidedNode = (): [NodeModule | undefined] => {
|
|
|
10
10
|
return [node]
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const useProvidedWrappedNode = (
|
|
14
|
-
const [
|
|
13
|
+
export const useProvidedWrappedNode = (wallet?: WalletInstance): [NodeWrapper | undefined, Error | undefined] => {
|
|
14
|
+
const [walletToUse] = useWallet({ wallet })
|
|
15
15
|
const [node] = useProvidedNode()
|
|
16
16
|
const [wrappedNode, setWrappedNode] = useState<NodeWrapper>()
|
|
17
17
|
const [error, setError] = useState<Error>()
|
|
18
18
|
|
|
19
|
-
/*
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (!accountToUse) {
|
|
22
|
-
const error = Error('useProvidedWrappedNode requires either an Account context or account parameter')
|
|
23
|
-
setError(error)
|
|
24
|
-
}
|
|
25
|
-
}, [accountToUse])
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
19
|
useEffect(() => {
|
|
29
20
|
try {
|
|
30
|
-
if (node &&
|
|
31
|
-
setWrappedNode(NodeWrapper.wrap(node,
|
|
21
|
+
if (node && walletToUse) {
|
|
22
|
+
setWrappedNode(NodeWrapper.wrap(node, walletToUse))
|
|
32
23
|
setError(undefined)
|
|
33
24
|
} else {
|
|
34
25
|
setWrappedNode(undefined)
|
|
@@ -38,7 +29,7 @@ export const useProvidedWrappedNode = (account?: AccountInstance): [NodeWrapper
|
|
|
38
29
|
setWrappedNode(undefined)
|
|
39
30
|
setError(ex as Error)
|
|
40
31
|
}
|
|
41
|
-
}, [node,
|
|
32
|
+
}, [node, walletToUse])
|
|
42
33
|
|
|
43
34
|
return [wrappedNode, error]
|
|
44
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AccountInstance } from '@xyo-network/account-model'
|
|
2
1
|
import { Logger } from '@xyo-network/core'
|
|
3
2
|
import { ConstructableModuleWrapper, ModuleWrapper } from '@xyo-network/module'
|
|
4
|
-
import {
|
|
3
|
+
import { useWallet } from '@xyo-network/react-wallet'
|
|
4
|
+
import { WalletInstance } from '@xyo-network/wallet-model'
|
|
5
5
|
import { useEffect, useState } from 'react'
|
|
6
6
|
|
|
7
7
|
import { useModule } from './useModule'
|
|
@@ -10,32 +10,34 @@ export const WrappedModuleHookFactory = <TModuleWrapper extends ModuleWrapper>(
|
|
|
10
10
|
wrapperObject: ConstructableModuleWrapper<TModuleWrapper>,
|
|
11
11
|
name?: string,
|
|
12
12
|
) => {
|
|
13
|
-
const useHook = (nameOrAddress?: string,
|
|
13
|
+
const useHook = (nameOrAddress?: string, wallet?: WalletInstance, logger?: Logger): [TModuleWrapper | undefined, Error | undefined] => {
|
|
14
14
|
logger?.debug(`Render: ${name}`)
|
|
15
|
-
const [
|
|
15
|
+
const [walletToUse] = useWallet({ wallet })
|
|
16
16
|
const [module, moduleError] = useModule<TModuleWrapper['module']>(
|
|
17
17
|
nameOrAddress ?? {
|
|
18
18
|
query: [wrapperObject.requiredQueries],
|
|
19
19
|
},
|
|
20
|
-
|
|
20
|
+
walletToUse,
|
|
21
21
|
logger,
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
const [wrapper, setWrapper] = useState<TModuleWrapper>()
|
|
25
25
|
const [error, setError] = useState<Error>()
|
|
26
26
|
|
|
27
|
+
/*
|
|
27
28
|
useEffect(() => {
|
|
28
|
-
if (!
|
|
29
|
+
if (!walletToUse) {
|
|
29
30
|
const error = Error('Module hooks require either an Account context or account parameter')
|
|
30
31
|
//console.error(error.message)
|
|
31
32
|
setError(error)
|
|
32
33
|
}
|
|
33
|
-
}, [
|
|
34
|
+
}, [walletToUse])
|
|
35
|
+
*/
|
|
34
36
|
|
|
35
37
|
useEffect(() => {
|
|
36
|
-
if (module &&
|
|
38
|
+
if (module && walletToUse) {
|
|
37
39
|
try {
|
|
38
|
-
const wrapper = wrapperObject.wrap(module,
|
|
40
|
+
const wrapper = wrapperObject.wrap(module, walletToUse)
|
|
39
41
|
setWrapper(wrapper)
|
|
40
42
|
setError(undefined)
|
|
41
43
|
} catch (ex) {
|
|
@@ -46,7 +48,7 @@ export const WrappedModuleHookFactory = <TModuleWrapper extends ModuleWrapper>(
|
|
|
46
48
|
setWrapper(undefined)
|
|
47
49
|
setError(moduleError)
|
|
48
50
|
}
|
|
49
|
-
}, [module,
|
|
51
|
+
}, [module, wallet, moduleError, walletToUse])
|
|
50
52
|
|
|
51
53
|
return [wrapper, error]
|
|
52
54
|
}
|