@xyo-network/react-sentinel 7.5.8 → 7.5.12

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.
@@ -1,214 +0,0 @@
1
- {
2
- "$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/a5a229a767e3998e13cce8160fd1c2b027317424/packages/manifest/src/schema.json",
3
- "nodes": [
4
- {
5
- "config": {
6
- "accountPath": "/0'/0'",
7
- "name": "NftInfoNode",
8
- "schema": "network.xyo.node.config"
9
- },
10
- "modules": {
11
- "public": [
12
- {
13
- "config": {
14
- "accountPath": "/1'/0'",
15
- "call": {
16
- "functionName": "name",
17
- "params": []
18
- },
19
- "labels": {
20
- "network.xyo.evm.interface": "Erc721"
21
- },
22
- "language": "javascript",
23
- "name": "Erc721NameWitness",
24
- "schema": "network.xyo.evm.call.witness.config"
25
- }
26
- },
27
- {
28
- "config": {
29
- "accountPath": "/1'/1'",
30
- "call": {
31
- "functionName": "symbol",
32
- "params": []
33
- },
34
- "labels": {
35
- "network.xyo.evm.interface": "Erc721"
36
- },
37
- "language": "javascript",
38
- "name": "Erc721SymbolWitness",
39
- "schema": "network.xyo.evm.call.witness.config"
40
- }
41
- },
42
- {
43
- "config": {
44
- "accountPath": "/1'/2'",
45
- "call": {
46
- "functionName": "totalSupply",
47
- "params": []
48
- },
49
- "labels": {
50
- "network.xyo.evm.interface": "Erc721Enumerable"
51
- },
52
- "language": "javascript",
53
- "name": "Erc721TotalSupplyWitness",
54
- "schema": "network.xyo.evm.call.witness.config"
55
- }
56
- },
57
- {
58
- "config": {
59
- "accountPath": "/1'/3'",
60
- "call": {
61
- "functionName": "tokenURI"
62
- },
63
- "labels": {
64
- "network.xyo.evm.interface": "Erc721"
65
- },
66
- "language": "javascript",
67
- "name": "Erc721TokenURIWitness",
68
- "schema": "network.xyo.evm.call.witness.config"
69
- }
70
- },
71
- {
72
- "config": {
73
- "accountPath": "/1'/4'",
74
- "call": {
75
- "functionName": "ownerOf"
76
- },
77
- "labels": {
78
- "network.xyo.evm.interface": "Erc721"
79
- },
80
- "language": "javascript",
81
- "name": "Erc721OwnerOfWitness",
82
- "schema": "network.xyo.evm.call.witness.config"
83
- }
84
- },
85
- {
86
- "config": {
87
- "accountPath": "/1'/5'",
88
- "call": {
89
- "functionName": "uri",
90
- "params": []
91
- },
92
- "labels": {
93
- "network.xyo.evm.interface": "Erc1155"
94
- },
95
- "language": "javascript",
96
- "name": "Erc1155UriWitness",
97
- "schema": "network.xyo.evm.call.witness.config"
98
- }
99
- },
100
- {
101
- "config": {
102
- "accountPath": "/2'/0'",
103
- "language": "javascript",
104
- "name": "Erc721ContractInfoDiviner",
105
- "schema": "network.xyo.evm.call.diviner.config"
106
- }
107
- },
108
- {
109
- "config": {
110
- "accountPath": "/2'/1'",
111
- "language": "javascript",
112
- "name": "Erc1155ContractInfoDiviner",
113
- "schema": "network.xyo.evm.call.diviner.config"
114
- }
115
- },
116
- {
117
- "config": {
118
- "accountPath": "/2'/2'",
119
- "language": "javascript",
120
- "name": "Erc721TokenContractInfoDiviner",
121
- "schema": "network.xyo.evm.call.diviner.config"
122
- }
123
- },
124
- {
125
- "config": {
126
- "accountPath": "/2'/3'",
127
- "language": "javascript",
128
- "name": "Erc1155TokenContractInfoDiviner",
129
- "schema": "network.xyo.evm.call.diviner.config"
130
- }
131
- },
132
- {
133
- "config": {
134
- "accountPath": "/3'/0'",
135
- "language": "javascript",
136
- "name": "NftInfoSentinel",
137
- "schema": "network.xyo.sentinel.config",
138
- "synchronous": "true",
139
- "tasks": [
140
- {
141
- "input": true,
142
- "mod": "Erc721NameWitness"
143
- },
144
- {
145
- "input": true,
146
- "mod": "Erc721SymbolWitness"
147
- },
148
- {
149
- "input": true,
150
- "mod": "Erc721TotalSupplyWitness"
151
- },
152
- {
153
- "input": true,
154
- "mod": "Erc1155UriWitness"
155
- },
156
- {
157
- "input": [
158
- "Erc721NameWitness",
159
- "Erc721SymbolWitness",
160
- "Erc721TotalSupplyWitness"
161
- ],
162
- "mod": "Erc721ContractInfoDiviner"
163
- },
164
- {
165
- "input": [
166
- "Erc1155UriWitness"
167
- ],
168
- "mod": "Erc1155ContractInfoDiviner"
169
- }
170
- ]
171
- }
172
- },
173
- {
174
- "config": {
175
- "accountPath": "/3'/1'",
176
- "language": "javascript",
177
- "name": "NftTokenInfoSentinel",
178
- "schema": "network.xyo.sentinel.config",
179
- "synchronous": "true",
180
- "tasks": [
181
- {
182
- "input": true,
183
- "mod": "Erc721TokenURIWitness"
184
- },
185
- {
186
- "input": true,
187
- "mod": "Erc721OwnerOfWitness"
188
- },
189
- {
190
- "input": true,
191
- "mod": "Erc1155UriWitness"
192
- },
193
- {
194
- "input": [
195
- "Erc721TokenURIWitness",
196
- "Erc721OwnerOfWitness"
197
- ],
198
- "mod": "Erc721TokenContractInfoDiviner"
199
- },
200
- {
201
- "input": [
202
- "Erc1155UriWitness"
203
- ],
204
- "mod": "Erc1155TokenContractInfoDiviner"
205
- }
206
- ]
207
- }
208
- }
209
- ]
210
- }
211
- }
212
- ],
213
- "schema": "network.xyo.manifest"
214
- }
@@ -1,3 +0,0 @@
1
- export * from './Card.tsx'
2
- export * from './CardContent.tsx'
3
- export * from './CardHeader.tsx'
@@ -1 +0,0 @@
1
- export { default as NftSentinelManifest } from './NftSentinel.json' with { type: 'json' }
@@ -1 +0,0 @@
1
- export * from './Card/index.ts'
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { SentinelContextState } from './State.ts'
4
-
5
- export const SentinelContext = createContextEx<SentinelContextState>()
@@ -1,131 +0,0 @@
1
- import { useAsyncEffect } from '@xylabs/react-async-effect'
2
- import type { AccountInstance } from '@xyo-network/account-model'
3
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
4
- import type { ModuleIdentifier } from '@xyo-network/module-model'
5
- import { useWitnessesFromNode } from '@xyo-network/react-witness'
6
- import { MemorySentinel } from '@xyo-network/sentinel-memory'
7
- import type { SentinelConfig } from '@xyo-network/sentinel-model'
8
- import { SentinelConfigSchema } from '@xyo-network/sentinel-model'
9
- import type { WitnessInstance } from '@xyo-network/witness-model'
10
- import { asWitnessInstance } from '@xyo-network/witness-model'
11
- import type { PropsWithChildren } from 'react'
12
- import React, {
13
- useEffect, useMemo, useState,
14
- } from 'react'
15
-
16
- import { SentinelContext } from './Context.ts'
17
- import type { SentinelContextState, SentinelReportProgress } from './State.ts'
18
- import { SentinelReportStatus } from './State.ts'
19
-
20
- export interface SentinelProviderProps {
21
- /** Account used by the sentinel for signing */
22
- account: AccountInstance
23
- /** @deprecated - sentinel no longer uses archive but relies on an archivist */
24
- archive?: string
25
- archivist?: string
26
- ids?: ModuleIdentifier[]
27
- name?: string
28
- required?: boolean
29
- witnesses?: WitnessInstance[]
30
- }
31
-
32
- export const SentinelProvider: React.FC<PropsWithChildren<SentinelProviderProps>> = ({
33
- account, archivist, children, ids, name, required = false,
34
- }) => {
35
- const [sentinel, setSentinel] = useState<MemorySentinel>()
36
- const [history, setHistory] = useState<BoundWitness[]>()
37
- const [progress, setProgress] = useState<SentinelReportProgress>({})
38
- const [status, setStatus] = useState<SentinelReportStatus>(SentinelReportStatus.Idle)
39
- const [reportingErrors, setReportingErrors] = useState<Error[]>()
40
- const [witnesses] = useWitnessesFromNode(ids)
41
-
42
- useAsyncEffect(
43
-
44
- async (mounted) => {
45
- const sentinel = await MemorySentinel.create({
46
- account,
47
- config: {
48
- archivists: archivist ? [archivist] : undefined,
49
- name,
50
-
51
- schema: SentinelConfigSchema,
52
- synchronous: true,
53
-
54
- tasks: witnesses?.map(mod => ({ mod: mod.address })),
55
- } as SentinelConfig,
56
- })
57
- const offCallbacks: (() => void)[] = [
58
- sentinel.on('reportEnd', ({ mod, outPayloads }) => {
59
- if (mounted()) {
60
- setProgress({
61
- archivists: progress.archivists,
62
- witnesses: progress.witnesses,
63
- })
64
- setStatus(outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed)
65
- setReportingErrors([new Error(`Witness failed [${mod?.config?.name ?? mod.address}]`)])
66
- }
67
- }),
68
- sentinel.on('reportStart', () => {
69
- if (mounted()) {
70
- setProgress({ archivists: {}, witnesses: {} })
71
- setStatus(SentinelReportStatus.Started)
72
- }
73
- }),
74
- ]
75
- if (witnesses)
76
- for (const witness of witnesses) {
77
- offCallbacks.push(
78
- witness.on('observeEnd', ({ mod, outPayloads }) => {
79
- const witnesses = progress.witnesses ?? {}
80
- witnesses[witness.address] = {
81
- status: outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed,
82
- witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`, { required: true }),
83
- }
84
- if (mounted()) {
85
- setProgress({
86
- archivists: progress.archivists,
87
- witnesses,
88
- })
89
- }
90
- }),
91
- witness.on('observeStart', ({ mod }) => {
92
- const witnesses = progress.witnesses ?? {}
93
- witnesses[witness.address] = {
94
- status: SentinelReportStatus.Started,
95
- witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`, { required: true }),
96
- }
97
- if (mounted()) {
98
- setProgress({
99
- archivists: progress.archivists,
100
- witnesses,
101
- })
102
- }
103
- }),
104
- )
105
- }
106
- setSentinel(sentinel as MemorySentinel)
107
- setHistory(sentinel?.history as BoundWitness[])
108
- return () => {
109
- // unsubscribe from events
110
- for (const callback of offCallbacks) {
111
- callback()
112
- }
113
- }
114
- },
115
-
116
- [account, archivist, witnesses],
117
- )
118
-
119
- const value: SentinelContextState = useMemo(() => ({
120
- history, progress, provided: true, reportingErrors, sentinel, status,
121
- }), [history, progress, reportingErrors, sentinel, status])
122
-
123
- return !required || sentinel
124
-
125
- ? (
126
- <SentinelContext value={value}>
127
- {children}
128
- </SentinelContext>
129
- )
130
- : null
131
- }
@@ -1,40 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { EnumValue } from '@xylabs/sdk-js'
3
- import { Enum } from '@xylabs/sdk-js'
4
- import type { ArchivistModuleInstance } from '@xyo-network/archivist-model'
5
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
6
- import type { SentinelModule } from '@xyo-network/sentinel-model'
7
- import type { WitnessModule } from '@xyo-network/witness-model'
8
-
9
- export const SentinelReportStatus = Enum({
10
- Idle: 'idle',
11
- Queued: 'queued',
12
- Started: 'started',
13
- Succeeded: 'succeeded',
14
- Failed: 'failed',
15
- })
16
-
17
- export type SentinelReportStatus = EnumValue<typeof SentinelReportStatus>
18
-
19
- export interface SentinelWitnessReportProgress {
20
- status: SentinelReportStatus
21
- witness: WitnessModule
22
- }
23
-
24
- export interface SentinelArchivistApiReportProgress {
25
- archivist: ArchivistModuleInstance
26
- status: SentinelReportStatus
27
- }
28
-
29
- export interface SentinelReportProgress {
30
- archivists?: Record<string, SentinelArchivistApiReportProgress>
31
- witnesses?: Record<string, SentinelWitnessReportProgress>
32
- }
33
-
34
- export type SentinelContextState = ContextExState<{
35
- history?: BoundWitness[]
36
- progress?: SentinelReportProgress
37
- reportingErrors?: Error[]
38
- sentinel?: SentinelModule
39
- status?: SentinelReportStatus
40
- }>
@@ -1,4 +0,0 @@
1
- export * from './Context.ts'
2
- export * from './Provider.tsx'
3
- export * from './State.ts'
4
- export * from './use.ts'
@@ -1,12 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { SentinelContext } from './Context.ts'
4
-
5
- export const useSentinelContext = () => {
6
- const {
7
- sentinel, history, progress, reportingErrors, status,
8
- } = useContextEx(SentinelContext, 'Sentinel')
9
- return {
10
- history, progress, reportingErrors, sentinel, status,
11
- }
12
- }
@@ -1 +0,0 @@
1
- export * from './node/index.ts'
@@ -1,4 +0,0 @@
1
- export * from './useSentinelFromNode.tsx'
2
- export * from './useSentinelsFromNode.tsx'
3
- export * from './useWeakSentinelFromNode.tsx'
4
- export * from './useWeakSentinelsFromNode.tsx'
@@ -1,18 +0,0 @@
1
- import type { ModuleFromNodeConfig } from '@xyo-network/react-node'
2
- import { useModuleFromNode } from '@xyo-network/react-node'
3
- import type { SentinelInstance } from '@xyo-network/sentinel-model'
4
- import { asSentinelInstance } from '@xyo-network/sentinel-model'
5
-
6
- export const useSentinelFromNode = (
7
- nameOrAddressOrInstance?: string | SentinelInstance,
8
- config?: ModuleFromNodeConfig,
9
- ): [SentinelInstance | undefined, Error | undefined] => {
10
- const [mod, error] = useModuleFromNode(nameOrAddressOrInstance, config)
11
- const instance = asSentinelInstance(mod)
12
- if (mod && !instance) {
13
- const error = new Error(`Resolved module is not a SentinelInstance [${mod.config?.schema}:${mod.config?.name}:${mod.address}]`)
14
- console.error(error.message)
15
- return [undefined, error]
16
- }
17
- return [instance, error]
18
- }
@@ -1,27 +0,0 @@
1
- import type { ModuleIdentifier } from '@xyo-network/module-model'
2
- import type { ModuleFromNodeConfig } from '@xyo-network/react-node'
3
- import { useModulesFromNode } from '@xyo-network/react-node'
4
- import type { SentinelInstance } from '@xyo-network/sentinel-model'
5
- import { isSentinelInstance } from '@xyo-network/sentinel-model'
6
-
7
- export const useSentinelsFromNode = (
8
- ids?: ModuleIdentifier[],
9
- config?: ModuleFromNodeConfig,
10
- ): [SentinelInstance[] | null | undefined, Error | undefined] => {
11
- const [modules, error] = useModulesFromNode(ids, config)
12
- if (error) {
13
- return [null, error]
14
- }
15
- return modules
16
- ? [
17
- // eslint-disable-next-line unicorn/no-array-reduce
18
- modules.reduce<SentinelInstance[]>((prev, mod) => {
19
- if (isSentinelInstance(mod)) {
20
- prev.push(mod)
21
- }
22
- return prev
23
- }, []),
24
- undefined,
25
- ]
26
- : [modules, error]
27
- }
@@ -1,11 +0,0 @@
1
- import type { WeakModuleFromNodeConfig } from '@xyo-network/react-node'
2
- import { useWeakModuleFromNode } from '@xyo-network/react-node'
3
- import type { SentinelInstance } from '@xyo-network/sentinel-model'
4
- import { isSentinelInstance } from '@xyo-network/sentinel-model'
5
-
6
- export const useWeakSentinelFromNode = (
7
- nameOrAddressOrInstance?: string | SentinelInstance,
8
- config?: WeakModuleFromNodeConfig,
9
- ): [WeakRef<SentinelInstance> | undefined, Error | undefined] => {
10
- return useWeakModuleFromNode<SentinelInstance>(nameOrAddressOrInstance, { identity: isSentinelInstance, ...config })
11
- }
@@ -1,27 +0,0 @@
1
- import { exists } from '@xylabs/sdk-js'
2
- import type { ModuleIdentifier } from '@xyo-network/module-model'
3
- import type { ModuleFromNodeConfig } from '@xyo-network/react-node'
4
- import { useWeakModulesFromNode } from '@xyo-network/react-node'
5
- import type { SentinelInstance } from '@xyo-network/sentinel-model'
6
- import { asSentinelInstance } from '@xyo-network/sentinel-model'
7
-
8
- export const useWeakSentinelsFromNode = (
9
- ids?: ModuleIdentifier[],
10
- config?: ModuleFromNodeConfig,
11
- ): [WeakRef<SentinelInstance>[] | null | undefined, Error | undefined] => {
12
- const [modules, error] = useWeakModulesFromNode(ids, config)
13
- if (error) {
14
- return [null, error]
15
- }
16
- return [
17
- modules
18
- ?.map((mod) => {
19
- const instance = asSentinelInstance(mod?.deref())
20
- if (instance) {
21
- return new WeakRef(instance)
22
- }
23
- })
24
- .filter(exists) ?? [],
25
- undefined,
26
- ]
27
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './components/index.ts'
2
- export * from './contexts/index.ts'
3
- export * from './hooks/index.ts'