@xyo-network/dapp-template 3.2.0

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.
Files changed (76) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/neutral/DappHost.d.ts +7 -0
  4. package/dist/neutral/DappHost.d.ts.map +1 -0
  5. package/dist/neutral/Params.d.ts +4 -0
  6. package/dist/neutral/Params.d.ts.map +1 -0
  7. package/dist/neutral/Payloads.d.ts +22 -0
  8. package/dist/neutral/Payloads.d.ts.map +1 -0
  9. package/dist/neutral/ReactDapp.d.ts +13 -0
  10. package/dist/neutral/ReactDapp.d.ts.map +1 -0
  11. package/dist/neutral/UiParams.d.ts +4 -0
  12. package/dist/neutral/UiParams.d.ts.map +1 -0
  13. package/dist/neutral/XyOsHost.d.ts +14 -0
  14. package/dist/neutral/XyOsHost.d.ts.map +1 -0
  15. package/dist/neutral/components/Dapp.d.ts +3 -0
  16. package/dist/neutral/components/Dapp.d.ts.map +1 -0
  17. package/dist/neutral/components/index.d.ts +2 -0
  18. package/dist/neutral/components/index.d.ts.map +1 -0
  19. package/dist/neutral/icon/Icon.d.ts +2 -0
  20. package/dist/neutral/icon/Icon.d.ts.map +1 -0
  21. package/dist/neutral/icon/index.d.ts +3 -0
  22. package/dist/neutral/icon/index.d.ts.map +1 -0
  23. package/dist/neutral/index.d.ts +5 -0
  24. package/dist/neutral/index.d.ts.map +1 -0
  25. package/dist/neutral/index.mjs +187 -0
  26. package/dist/neutral/index.mjs.map +1 -0
  27. package/dist/neutral/window/Dapp.d.ts +2 -0
  28. package/dist/neutral/window/Dapp.d.ts.map +1 -0
  29. package/dist/neutral/window/index.d.ts +2 -0
  30. package/dist/neutral/window/index.d.ts.map +1 -0
  31. package/dist/node/DappHost.d.ts +7 -0
  32. package/dist/node/DappHost.d.ts.map +1 -0
  33. package/dist/node/Params.d.ts +4 -0
  34. package/dist/node/Params.d.ts.map +1 -0
  35. package/dist/node/Payloads.d.ts +22 -0
  36. package/dist/node/Payloads.d.ts.map +1 -0
  37. package/dist/node/ReactDapp.d.ts +13 -0
  38. package/dist/node/ReactDapp.d.ts.map +1 -0
  39. package/dist/node/UiParams.d.ts +4 -0
  40. package/dist/node/UiParams.d.ts.map +1 -0
  41. package/dist/node/XyOsHost.d.ts +14 -0
  42. package/dist/node/XyOsHost.d.ts.map +1 -0
  43. package/dist/node/components/Dapp.d.ts +3 -0
  44. package/dist/node/components/Dapp.d.ts.map +1 -0
  45. package/dist/node/components/index.d.ts +2 -0
  46. package/dist/node/components/index.d.ts.map +1 -0
  47. package/dist/node/icon/Icon.d.ts +2 -0
  48. package/dist/node/icon/Icon.d.ts.map +1 -0
  49. package/dist/node/icon/index.d.ts +3 -0
  50. package/dist/node/icon/index.d.ts.map +1 -0
  51. package/dist/node/index.d.ts +5 -0
  52. package/dist/node/index.d.ts.map +1 -0
  53. package/dist/node/index.mjs +187 -0
  54. package/dist/node/index.mjs.map +1 -0
  55. package/dist/node/window/Dapp.d.ts +2 -0
  56. package/dist/node/window/Dapp.d.ts.map +1 -0
  57. package/dist/node/window/index.d.ts +2 -0
  58. package/dist/node/window/index.d.ts.map +1 -0
  59. package/package.json +83 -0
  60. package/src/DappHost.tsx +145 -0
  61. package/src/Params.ts +15 -0
  62. package/src/Payloads.ts +73 -0
  63. package/src/ReactDapp.ts +13 -0
  64. package/src/UiParams.ts +11 -0
  65. package/src/XyOsHost.tsx +61 -0
  66. package/src/components/Dapp.tsx +10 -0
  67. package/src/components/index.ts +1 -0
  68. package/src/dapp.manifest.json +30 -0
  69. package/src/dapp.stories.tsx +75 -0
  70. package/src/icon/Icon.tsx +45 -0
  71. package/src/icon/index.ts +2 -0
  72. package/src/index.ts +4 -0
  73. package/src/window/Dapp.tsx +19 -0
  74. package/src/window/index.ts +1 -0
  75. package/typedoc.json +5 -0
  76. package/xy.config.ts +10 -0
@@ -0,0 +1,11 @@
1
+ import type { UnregisteredReactDapp } from '@xyo-network/os-react-model'
2
+
3
+ import { CustomDappParams } from './Params.js'
4
+ import { CustomDapp } from './window/index.ts'
5
+
6
+ export const CustomDappUiParams: UnregisteredReactDapp['params'] = {
7
+ ...CustomDappParams,
8
+ modes: { window: { component: CustomDapp } },
9
+ }
10
+
11
+ export { CustomDappUiParams as default }
@@ -0,0 +1,61 @@
1
+ import { Typography } from '@mui/material'
2
+ import { FlexCol } from '@xylabs/react-flexbox'
3
+ import { usePromise } from '@xylabs/react-promise'
4
+ import { HDWallet, type WalletInstance } from '@xyo-network/account'
5
+ import { Kernel } from '@xyo-network/kernel'
6
+ import type { KernelExternal } from '@xyo-network/kernel-model'
7
+ import { ModuleFactoryLocator } from '@xyo-network/module-factory-locator'
8
+ import { XyOsUiContextProvider } from '@xyo-network/os-react-runtime'
9
+ import { EventBus, XyOs } from '@xyo-network/os-runtime'
10
+ import type React from 'react'
11
+ import { useMemo } from 'react'
12
+
13
+ export interface XyOsHostProps {
14
+ children?: React.ReactNode
15
+ eventBus?: EventBus
16
+ kernel?: KernelExternal
17
+ locator?: ModuleFactoryLocator
18
+ wallet?: WalletInstance
19
+ }
20
+
21
+ export const XyOsHost: React.FC<XyOsHostProps> = ({
22
+ children, eventBus, kernel, locator, wallet,
23
+ }) => {
24
+ const [walletToUse] = usePromise(async () => wallet ?? await HDWallet.random(), [wallet])
25
+ const eventBusToUse: EventBus = useMemo(() => eventBus ?? new EventBus(), [kernel])
26
+ const kernelToUse: KernelExternal = useMemo(() => kernel ?? new Kernel(), [kernel])
27
+ const locatorToUse = useMemo(() => locator ?? new ModuleFactoryLocator(), [locator])
28
+
29
+ const [os, error] = usePromise(async () => {
30
+ if (walletToUse && kernelToUse && eventBusToUse && locatorToUse) {
31
+ const os = new XyOs({
32
+ kernel: kernelToUse, eventBus: new EventBus(), locator: locatorToUse,
33
+ })
34
+ await os.boot(walletToUse, locatorToUse)
35
+ return os
36
+ }
37
+ }, [kernelToUse, walletToUse, locator, eventBusToUse, locatorToUse])
38
+
39
+ return os
40
+ ? <XyOsUiContextProvider value={os}>{children}</XyOsUiContextProvider>
41
+ : (
42
+ <FlexCol>
43
+ <Typography>
44
+ wallet:
45
+ {walletToUse ? 'ready' : 'loading'}
46
+ </Typography>
47
+ <Typography>
48
+ kernel:
49
+ {kernelToUse ? 'ready' : 'loading'}
50
+ </Typography>
51
+ <Typography>
52
+ os:
53
+ {os ? 'ready' : 'loading'}
54
+ </Typography>
55
+ <Typography>
56
+ os-error:
57
+ {error?.message}
58
+ </Typography>
59
+ </FlexCol>
60
+ )
61
+ }
@@ -0,0 +1,10 @@
1
+ import { FlexRow } from '@xylabs/react-flexbox'
2
+ import type { PathToComponent } from '@xyo-network/os-react-runtime'
3
+ import React from 'react'
4
+
5
+ export const CustomDappPathToComponent: PathToComponent[] = [
6
+ {
7
+ component: <FlexRow />,
8
+ path: 'home',
9
+ },
10
+ ]
@@ -0,0 +1 @@
1
+ export * from './Dapp.tsx'
@@ -0,0 +1,30 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/compilations/dapp-package-manifest-schema.json",
3
+ "nodes": [
4
+ {
5
+ "config": {
6
+ "accountPath": "0'",
7
+ "name": "Node",
8
+ "schema": "network.xyo.node.config"
9
+ },
10
+ "modules": {
11
+ "private": [],
12
+ "public": [
13
+ {
14
+ "config": {
15
+ "accountPath": "1'",
16
+ "name": "DappArchivist",
17
+ "dbName": "DappArchivist",
18
+ "storeName": "payloads",
19
+ "schema": "network.xyo.archivist.config",
20
+ "labels": {
21
+ "network.xyo.archivist.persistence.scope": "device"
22
+ }
23
+ }
24
+ }
25
+ ]
26
+ }
27
+ }
28
+ ],
29
+ "schema": "network.xyo.manifest.package.dapp"
30
+ }
@@ -0,0 +1,75 @@
1
+ import type { Meta, StoryFn } from '@storybook/react'
2
+ import { DappRegisteredSchema, DappRegisteredState } from '@xyo-network/os-model'
3
+ import type { RegisteredReactDapp } from '@xyo-network/os-react-model'
4
+ import React from 'react'
5
+ import {
6
+ BrowserRouter, Route, Routes,
7
+ } from 'react-router-dom'
8
+
9
+ import type { DappHostProps } from './DappHost.tsx'
10
+ import { DappHost } from './DappHost.tsx'
11
+ import { CustomDappConfig } from './Payloads.ts'
12
+ import { CustomDappUiParams } from './ReactDapp.ts'
13
+
14
+ const StorybookEntry = {
15
+ argTypes: {},
16
+ component: DappHost,
17
+ parameters: { docs: { page: null } },
18
+ title: 'dapps/accounts',
19
+ } as Meta<typeof DappHost>
20
+
21
+ const DappRoutes: React.FC<DappHostProps> = args => (
22
+ <Routes>
23
+ <Route
24
+ path="/"
25
+ element={(
26
+ <DappHost {...args} />
27
+ )}
28
+ />
29
+ <Route
30
+ path="/:dappName"
31
+ element={(
32
+ <DappHost {...args} />
33
+ )}
34
+ />
35
+ <Route
36
+ path="/:dappName/:path/*"
37
+ element={(
38
+ <DappHost {...args} />
39
+ )}
40
+ />
41
+ <Route
42
+ path="*"
43
+ element={(
44
+ <DappHost {...args} />
45
+ )}
46
+ />
47
+ </Routes>
48
+ )
49
+
50
+ const Template: StoryFn<typeof DappHost> = (args: DappHostProps) => {
51
+ return (
52
+ <BrowserRouter>
53
+ <DappRoutes {...args} />
54
+ </BrowserRouter>
55
+ )
56
+ }
57
+
58
+ const dapp: RegisteredReactDapp = {
59
+ config: {
60
+ ...CustomDappConfig,
61
+ state: DappRegisteredState.Registered,
62
+ schema: DappRegisteredSchema,
63
+ walletId: 'Accounts',
64
+ },
65
+ accessors: [],
66
+ params: CustomDappUiParams,
67
+ widgetConfigs: [],
68
+ }
69
+
70
+ const Default = Template.bind({})
71
+ Default.args = { dapp }
72
+
73
+ export { Default }
74
+
75
+ export default StorybookEntry
@@ -0,0 +1,45 @@
1
+ /* eslint-disable @stylistic/max-len */
2
+ export const CustomDappIconSvg = `
3
+ <svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
4
+ <path
5
+ fill="transparent"
6
+ d="M6.44,27.12c-.78,0-1.44.28-2,.83-.55.55-.83,1.21-.83,1.99s.28,1.44.83,2c.55.55,1.21.83,1.99.83s1.44-.28,2-.83c.55-.55.83-1.21.83-1.99s-.28-1.44-.83-2c-.55-.55-1.21-.83-1.99-.83Z"
7
+ />
8
+ <path
9
+ fill="transparent"
10
+ d="M18.01,27.91c-.55.55-.83,1.22-.83,1.99s.28,1.44.83,2c.55.55,1.21.83,1.99.83s1.44-.28,2-.83c.55-.55.83-1.21.83-1.99s-.28-1.44-.83-2c-.55-.55-1.21-.83-1.99-.83s-1.44.28-2,.83Z"
11
+ />
12
+ <path
13
+ fill="transparent"
14
+ d="M33.56,27.12c-.78,0-1.44.28-2,.83-.55.55-.83,1.21-.83,1.99s.28,1.44.83,2c.55.55,1.21.83,1.99.83s1.44-.28,2-.83c.55-.55.83-1.21.83-1.99s-.28-1.44-.83-2c-.55-.55-1.21-.83-1.99-.83Z"
15
+ />
16
+ <path
17
+ fill="currentColor"
18
+ d="M36.55,26.94c-.82-.82-1.82-1.23-3-1.23-.32,0-.63.04-.93.11-.3.07-.59.17-.87.31l-5.87-8.09c-.18.03-.36.05-.56.05h-1.13l6.42,8.83c-.39.4-.7.85-.93,1.36-.23.51-.35,1.06-.35,1.66,0,1.18.41,2.17,1.23,3s1.82,1.23,3,1.23,2.17-.41,3-1.23,1.23-1.82,1.23-3-.41-2.17-1.23-3ZM35.55,31.93c-.55.55-1.22.83-2,.83s-1.44-.28-1.99-.83c-.55-.55-.83-1.22-.83-2s.28-1.44.83-1.99c.55-.55,1.22-.83,2-.83s1.44.28,1.99.83c.55.55.83,1.22.83,2s-.28,1.44-.83,1.99Z"
19
+ />
20
+ <path
21
+ fill="currentColor"
22
+ d="M19.29,25.73c-1,.16-1.84.64-2.52,1.42-.67.79-1.01,1.7-1.01,2.75,0,1.18.41,2.17,1.23,3,.82.82,1.82,1.23,3,1.23s2.17-.41,3-1.23c.82-.82,1.23-1.82,1.23-3,0-1.05-.34-1.97-1.01-2.74-.67-.78-1.51-1.25-2.52-1.43v-7.65h-1.41v7.65ZM22,27.91c.55.55.83,1.22.83,2s-.28,1.44-.83,1.99c-.55.55-1.22.83-2,.83s-1.44-.28-1.99-.83c-.55-.55-.83-1.22-.83-2s.28-1.44.83-1.99c.55-.55,1.22-.83,2-.83s1.44.28,1.99.83Z"
23
+ />
24
+ <path
25
+ fill="currentColor"
26
+ d="M14.1,18l-5.89,8.08c-.28-.13-.56-.22-.86-.28-.29-.06-.6-.09-.91-.09-1.18,0-2.17.41-3,1.23-.82.82-1.23,1.82-1.23,3s.41,2.17,1.23,3,1.82,1.23,3,1.23,2.17-.41,3-1.23,1.23-1.82,1.23-3c0-.6-.12-1.15-.36-1.66s-.56-.96-.95-1.36l6.45-8.83h-1c-.25,0-.48-.03-.7-.08ZM8.44,31.93c-.55.55-1.22.83-2,.83s-1.44-.28-1.99-.83c-.55-.55-.83-1.22-.83-2s.28-1.44.83-1.99c.55-.55,1.22-.83,2-.83s1.44.28,1.99.83c.55.55.83,1.22.83,2s-.28,1.44-.83,1.99Z"
27
+ />
28
+ <path
29
+ fill="transparent"
30
+ d="M20,12.91c1.26,0,2.46.19,3.61.56,1.15.37,2.23.88,3.23,1.54V4.86c0-.44-.15-.82-.46-1.12s-.68-.46-1.12-.46h-10.52c-.44,0-.82.15-1.12.46s-.46.68-.46,1.12v10.15c1-.66,2.08-1.17,3.23-1.54s2.36-.56,3.61-.56ZM17.7,5.83c.63-.63,1.4-.95,2.3-.95s1.66.32,2.3.95.95,1.4.95,2.3-.32,1.66-.95,2.3-1.4.95-2.3.95-1.66-.32-2.3-.95-.95-1.4-.95-2.3.32-1.66.95-2.3Z"
31
+ />
32
+ <path
33
+ fill="transparent"
34
+ d="M20,10.32c.6,0,1.12-.21,1.55-.64.43-.43.65-.94.65-1.55s-.22-1.12-.65-1.55c-.43-.43-.95-.65-1.55-.65s-1.12.22-1.55.65-.64.95-.64,1.55.21,1.12.64,1.55.94.64,1.55.64Z"
35
+ />
36
+ <path
37
+ fill="currentColor"
38
+ d="M20,11.37c.9,0,1.66-.32,2.3-.95s.95-1.4.95-2.3-.32-1.66-.95-2.3-1.4-.95-2.3-.95-1.66.32-2.3.95-.95,1.4-.95,2.3.32,1.66.95,2.3,1.4.95,2.3.95ZM18.45,6.58c.43-.43.95-.65,1.55-.65s1.12.22,1.55.65c.43.43.65.95.65,1.55s-.22,1.12-.65,1.55c-.43.43-.95.64-1.55.64s-1.12-.21-1.55-.64-.64-.95-.64-1.55.21-1.12.64-1.55Z"
39
+ />
40
+ <path
41
+ fill="currentColor"
42
+ d="M27.21,2.9c-.5-.5-1.15-.75-1.95-.75h-10.52c-.8,0-1.45.25-1.95.75-.5.5-.75,1.15-.75,1.95v10.52c0,.8.25,1.45.75,1.95.35.35.77.56,1.25.67.22.05.45.08.7.08h10.52c.2,0,.38-.02.56-.05.55-.09,1.01-.33,1.39-.71.5-.5.75-1.15.75-1.95V4.86c0-.8-.25-1.45-.75-1.95ZM25.93,16.74c-.26.14-.55.22-.86.22h-10.15s-.08-.01-.12-.01c-.25-.02-.5-.08-.74-.2-.28-.14-.45-.35-.5-.63.99-.7,2.03-1.22,3.12-1.57s2.19-.52,3.31-.52,2.27.18,3.4.55c1.13.36,2.18.88,3.16,1.54-.15.27-.36.48-.63.63ZM26.84,15.01c-1-.66-2.08-1.17-3.23-1.54-1.15-.37-2.36-.56-3.61-.56s-2.46.19-3.61.56-2.23.88-3.23,1.54V4.86c0-.44.15-.82.46-1.12s.68-.46,1.12-.46h10.52c.44,0,.82.15,1.12.46s.46.68.46,1.12v10.15Z"
43
+ />
44
+ </svg>
45
+ `
@@ -0,0 +1,2 @@
1
+ export * from './Icon.tsx'
2
+ export { CustomDappIconSvg as default } from './Icon.tsx'
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as accountsDappManifest } from './dapp.manifest.json'
2
+ export * from './Params.ts'
3
+ export * from './Payloads.ts'
4
+ export * from './UiParams.ts'
@@ -0,0 +1,19 @@
1
+ import { DappPathSwitcher, useAddDappMenuItems } from '@xyo-network/os-react-runtime'
2
+ import { ErrorRender } from '@xyo-network/react-error'
3
+ import React from 'react'
4
+
5
+ import { CustomDappPathToComponent } from '../components/index.ts'
6
+ import { CustomDappMenuPayloads } from '../Payloads.js'
7
+
8
+ export const CustomDapp = () => {
9
+ const {
10
+ menuConfig, path, error,
11
+ } = useAddDappMenuItems(CustomDappMenuPayloads)
12
+
13
+ return (
14
+ <>
15
+ <ErrorRender error={error} scope="CustomDapp" />
16
+ <DappPathSwitcher activePath={path?.path ?? menuConfig?.defaultPath} pathToComponent={CustomDappPathToComponent} />
17
+ </>
18
+ )
19
+ }
@@ -0,0 +1 @@
1
+ export * from './Dapp.tsx'
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["./src/index.ts"],
4
+ "tsconfig": "./tsconfig.typedoc.json"
5
+ }
package/xy.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
+ const config: XyTsupConfig = {
3
+ compile: {
4
+ browser: {},
5
+ node: { src: { entry: ['./src/index.ts'] } },
6
+ neutral: { src: { entry: ['./src/index.ts'] } },
7
+ },
8
+ }
9
+
10
+ export default config