@xyo-network/dapp-template 4.2.0 → 4.2.1

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 +1 @@
1
- {"version":3,"file":"DappHost.d.ts","sourceRoot":"","sources":["../../src/DappHost.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAetE,OAAO,KAEN,MAAM,OAAO,CAAA;AAMd,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,mBAAmB,CAAA;CAC1B;AA8GD,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAM5C,CAAA"}
1
+ {"version":3,"file":"DappHost.d.ts","sourceRoot":"","sources":["../../src/DappHost.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEtE,OAAO,KAAkB,MAAM,OAAO,CAAA;AAKtC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,mBAAmB,CAAA;CAC1B;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAc5C,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './registration/index.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { WindowDappNodeSet, XyOsContext } from '@xyo-network/os-model';
2
+ import type { RegisteredReactDapp } from '@xyo-network/os-react-model';
3
+ export interface DappInitializerConfig {
4
+ allowedNames: string[];
5
+ dapp: RegisteredReactDapp;
6
+ xnsNetwork: string | undefined;
7
+ xnsNodeUrl: string | undefined;
8
+ xyOs: XyOsContext;
9
+ }
10
+ export declare class DappInitializer {
11
+ private _config;
12
+ constructor(config: DappInitializerConfig);
13
+ get config(): DappInitializerConfig;
14
+ install(): Promise<WindowDappNodeSet>;
15
+ private initializeDappContext;
16
+ private installDappWallet;
17
+ }
18
+ //# sourceMappingURL=DappInitializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DappInitializer.d.ts","sourceRoot":"","sources":["../../../../src/helpers/registration/DappInitializer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAGtE,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,IAAI,EAAE,mBAAmB,CAAA;IACzB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAuB;gBAE1B,MAAM,EAAE,qBAAqB;IAIzC,IAAI,MAAM,0BAET;IAEK,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC;YAM7B,qBAAqB;YAQrB,iBAAiB;CAchC"}
@@ -0,0 +1,3 @@
1
+ export * from './DappInitializer.ts';
2
+ export * from './useInstallDapp.tsx';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/helpers/registration/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { RegisteredReactDapp } from '@xyo-network/os-react-model';
2
+ export declare const useInitializeDapp: (dapp: RegisteredReactDapp) => {
3
+ context: import("@xyo-network/os-model").XyOsContext | null | undefined;
4
+ dappMenu: import("@xyo-network/os-react-runtime").DappMenuProperties;
5
+ dappWallet: import("@xyo-network/wallet-model").WalletInstance | undefined;
6
+ errors: (Error | undefined)[];
7
+ };
8
+ //# sourceMappingURL=useInstallDapp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInstallDapp.d.ts","sourceRoot":"","sources":["../../../../src/helpers/registration/useInstallDapp.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAOtE,eAAO,MAAM,iBAAiB,SAAU,mBAAmB;;;;;CA8B1D,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"DappHost.d.ts","sourceRoot":"","sources":["../../src/DappHost.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAetE,OAAO,KAEN,MAAM,OAAO,CAAA;AAMd,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,mBAAmB,CAAA;CAC1B;AA8GD,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAM5C,CAAA"}
1
+ {"version":3,"file":"DappHost.d.ts","sourceRoot":"","sources":["../../src/DappHost.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEtE,OAAO,KAAkB,MAAM,OAAO,CAAA;AAKtC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,mBAAmB,CAAA;CAC1B;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAc5C,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './registration/index.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { WindowDappNodeSet, XyOsContext } from '@xyo-network/os-model';
2
+ import type { RegisteredReactDapp } from '@xyo-network/os-react-model';
3
+ export interface DappInitializerConfig {
4
+ allowedNames: string[];
5
+ dapp: RegisteredReactDapp;
6
+ xnsNetwork: string | undefined;
7
+ xnsNodeUrl: string | undefined;
8
+ xyOs: XyOsContext;
9
+ }
10
+ export declare class DappInitializer {
11
+ private _config;
12
+ constructor(config: DappInitializerConfig);
13
+ get config(): DappInitializerConfig;
14
+ install(): Promise<WindowDappNodeSet>;
15
+ private initializeDappContext;
16
+ private installDappWallet;
17
+ }
18
+ //# sourceMappingURL=DappInitializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DappInitializer.d.ts","sourceRoot":"","sources":["../../../../src/helpers/registration/DappInitializer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAGtE,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,IAAI,EAAE,mBAAmB,CAAA;IACzB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAuB;gBAE1B,MAAM,EAAE,qBAAqB;IAIzC,IAAI,MAAM,0BAET;IAEK,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC;YAM7B,qBAAqB;YAQrB,iBAAiB;CAchC"}
@@ -0,0 +1,3 @@
1
+ export * from './DappInitializer.ts';
2
+ export * from './useInstallDapp.tsx';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/helpers/registration/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { RegisteredReactDapp } from '@xyo-network/os-react-model';
2
+ export declare const useInitializeDapp: (dapp: RegisteredReactDapp) => {
3
+ context: import("@xyo-network/os-model").XyOsContext | null | undefined;
4
+ dappMenu: import("@xyo-network/os-react-runtime").DappMenuProperties;
5
+ dappWallet: import("@xyo-network/wallet-model").WalletInstance | undefined;
6
+ errors: (Error | undefined)[];
7
+ };
8
+ //# sourceMappingURL=useInstallDapp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInstallDapp.d.ts","sourceRoot":"","sources":["../../../../src/helpers/registration/useInstallDapp.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAOtE,eAAO,MAAM,iBAAiB,SAAU,mBAAmB;;;;;CA8B1D,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/dapp-template",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -42,14 +42,14 @@
42
42
  "@xylabs/react-promise": "^5.3.14",
43
43
  "@xyo-network/account": "^3.6.6",
44
44
  "@xyo-network/archivist-indexeddb": "^3.6.6",
45
- "@xyo-network/kernel": "^4.2.0",
46
- "@xyo-network/kernel-model": "^4.2.0",
45
+ "@xyo-network/kernel": "^4.2.1",
46
+ "@xyo-network/kernel-model": "^4.2.1",
47
47
  "@xyo-network/module-factory-locator": "^3.6.6",
48
48
  "@xyo-network/object": "^3.6.6",
49
- "@xyo-network/os-model": "^4.2.0",
50
- "@xyo-network/os-react-model": "^4.2.0",
51
- "@xyo-network/os-react-runtime": "^4.2.0",
52
- "@xyo-network/os-runtime": "^4.2.0",
49
+ "@xyo-network/os-model": "^4.2.1",
50
+ "@xyo-network/os-react-model": "^4.2.1",
51
+ "@xyo-network/os-react-runtime": "^4.2.1",
52
+ "@xyo-network/os-runtime": "^4.2.1",
53
53
  "@xyo-network/payload-model": "^3.6.6",
54
54
  "@xyo-network/react-node": "^4.3.1",
55
55
  "@xyo-network/react-sdk": "^4.3.1",
package/src/DappHost.tsx CHANGED
@@ -1,145 +1,27 @@
1
- import { Typography } from '@mui/material'
2
- import { FlexCol, FlexRow } from '@xylabs/react-flexbox'
3
- import { usePromise } from '@xylabs/react-promise'
1
+ import { FlexCol } from '@xylabs/react-flexbox'
4
2
  import type { RegisteredReactDapp } from '@xyo-network/os-react-model'
5
- import {
6
- DappAccessFlexbox,
7
- DappBar,
8
- DappBottomNavigation,
9
- DappChrome,
10
- DappMenuDrawer,
11
- useDappContextCreator,
12
- useDappMenu,
13
- useManageDappPathFromRoute, useXyOsUiContext,
14
- XyOsUiContextProvider,
15
- } from '@xyo-network/os-react-runtime'
16
- import { DappSeedPhraseRepository, NameTransforms } from '@xyo-network/os-runtime'
17
- import { NodeProvider } from '@xyo-network/react-node'
18
- import { ErrorRender, WalletProvider } from '@xyo-network/react-sdk'
19
- import React, {
20
- useMemo, useState, version,
21
- } from 'react'
3
+ import { DappRendered } from '@xyo-network/os-react-runtime'
4
+ import React, { useMemo } from 'react'
22
5
 
6
+ import { useInitializeDapp } from './helpers/index.ts'
23
7
  import { XyOsHost } from './XyOsHost.tsx'
24
8
 
25
- const allowedNames = ['Accounts']
26
-
27
9
  export interface DappHostProps {
28
10
  dapp: RegisteredReactDapp
29
11
  }
30
12
 
31
- const DappPageHost: React.FC<DappHostProps> = ({ dapp }) => {
32
- const xyOs = useXyOsUiContext()
33
- const [walletId, setWalletId] = useState<string>()
34
- const [dappWithWalletId, setDappWithWalletId] = useState<RegisteredReactDapp>(dapp)
35
-
36
- // stub the walletId for the dapp
37
- usePromise(async () => {
38
- if (xyOs) {
39
- const dappSeedPhraseRepository = new DappSeedPhraseRepository(xyOs, allowedNames)
40
- const walletId = await dappSeedPhraseRepository.findOrCreate(allowedNames[0])
41
- setWalletId(walletId)
42
- setDappWithWalletId(dapp => ({
43
- ...dapp,
44
- config: {
45
- ...dapp.config,
46
- walletId,
47
- },
48
- }))
49
- }
50
- }, [xyOs])
51
-
52
- const name = dapp?.config.name
53
- const scrollable = true
54
-
55
- // Create the dapp context
56
- const {
57
- dappWallet, context, nodeCreateError,
58
- } = useDappContextCreator('', '', dappWithWalletId, allowedNames, !!walletId)
59
-
60
- // support for routing
61
- useManageDappPathFromRoute(context, dapp.config.name)
62
-
63
- // Get the dapp component
64
- const TypedDappComponent = useMemo(() => dapp?.params.modes?.window?.component as React.FC<{
65
- name?: string
66
- }>, [])
67
-
68
- // Get the menu items
13
+ export const DappHost: React.FC<DappHostProps> = ({ dapp }) => {
69
14
  const {
70
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
- activePath, error: menuError, menuConfig, menuItemsVisible, onPathChange,
72
- } = useDappMenu(context, name)
15
+ context, dappMenu, dappWallet, errors,
16
+ } = useInitializeDapp(dapp)
73
17
 
74
- return (
75
- <FlexCol>
76
- <FlexRow>
77
- <Typography>
78
- xyOs Booted:&nbsp;
79
- {xyOs ? 'true' : 'false'}
80
- </Typography>
81
- </FlexRow>
82
- <DappChrome
83
- appBar={(
84
- <>
85
- {/* Keep DappBar outside of the Dapp's Node Provider so it can still see the intentArchivist for close and minimize */}
86
- <DappBar context={context} name={name} version={version} title={activePath ? new NameTransforms(activePath).deSlug() : ''} />
87
- </>
88
- )}
89
- height="100dvh"
90
- width="100dvw"
91
- largeScreenMenu={(
92
- <DappMenuDrawer
93
- context={context}
94
- name={name}
95
- version={version}
96
- activePath={activePath}
97
- onPathChange={onPathChange}
98
- menuConfig={menuConfig}
99
- menuItems={menuItemsVisible}
100
- />
101
- )}
102
- smallScreenMenu={(
103
- <DappBottomNavigation
104
- activePath={activePath}
105
- onPathChange={onPathChange}
106
- menuConfig={menuConfig}
107
- menuItems={menuItemsVisible}
108
- sx={{ display: menuConfig ? 'flex' : 'none' }}
109
- />
110
- )}
111
- >
112
- <ErrorRender error={nodeCreateError} scope="Accounts Stories" />
113
- <WalletProvider rootWallet={dappWallet}>
114
- <XyOsUiContextProvider value={context === null ? undefined : context}>
115
- {/* Prevent dapps from reaching out to the os node */}
116
- <NodeProvider node={context?.root}>
117
- <FlexCol
118
- alignItems="stretch"
119
- justifyContent="stretch"
120
- position="absolute"
121
- top={0}
122
- bottom={0}
123
- left={0}
124
- right={0}
125
- sx={{ overflowY: scrollable ? 'auto' : 'hidden' }}
126
- >
127
- <TypedDappComponent name="Accounts" />
128
- </FlexCol>
129
- <DappAccessFlexbox context={context} />
18
+ const dappState = useMemo(() => ({ active: true }), [])
130
19
 
131
- </NodeProvider>
132
- </XyOsUiContextProvider>
133
- </WalletProvider>
134
- </DappChrome>
135
- </FlexCol>
136
- )
137
- }
138
-
139
- export const DappHost: React.FC<DappHostProps> = ({ dapp }) => {
140
20
  return (
141
21
  <XyOsHost>
142
- <DappPageHost dapp={dapp} />
22
+ <FlexCol>
23
+ <DappRendered context={context} dapp={dapp} dappMenuProperties={dappMenu} dappState={dappState} dappWallet={dappWallet} errors={errors} />
24
+ </FlexCol>
143
25
  </XyOsHost>
144
26
  )
145
27
  }
@@ -15,7 +15,7 @@ const StorybookEntry = {
15
15
  argTypes: {},
16
16
  component: DappHost,
17
17
  parameters: { docs: { page: null } },
18
- title: 'dapps/accounts',
18
+ title: 'dapps/customDapp',
19
19
  } as Meta<typeof DappHost>
20
20
 
21
21
  const DappRoutes: React.FC<DappHostProps> = args => (
@@ -0,0 +1 @@
1
+ export * from './registration/index.ts'
@@ -0,0 +1,53 @@
1
+ import { assertEx } from '@xylabs/assert'
2
+ import type { WindowDappNodeSet, XyOsContext } from '@xyo-network/os-model'
3
+ import type { RegisteredReactDapp } from '@xyo-network/os-react-model'
4
+ import { DappSeedPhraseRepository, RunningDappCache } from '@xyo-network/os-runtime'
5
+
6
+ export interface DappInitializerConfig {
7
+ allowedNames: string[]
8
+ dapp: RegisteredReactDapp
9
+ xnsNetwork: string | undefined
10
+ xnsNodeUrl: string | undefined
11
+ xyOs: XyOsContext
12
+ }
13
+
14
+ export class DappInitializer {
15
+ private _config: DappInitializerConfig
16
+
17
+ constructor(config: DappInitializerConfig) {
18
+ this._config = config
19
+ }
20
+
21
+ get config() {
22
+ return assertEx(this._config, () => new Error('Options not set'))
23
+ }
24
+
25
+ async install(): Promise<WindowDappNodeSet> {
26
+ const dappWithWalletId = await this.installDappWallet()
27
+
28
+ return await this.initializeDappContext(dappWithWalletId)
29
+ }
30
+
31
+ private async initializeDappContext(dappWithWalletId: RegisteredReactDapp): Promise<WindowDappNodeSet> {
32
+ const {
33
+ allowedNames, xnsNetwork, xnsNodeUrl, xyOs,
34
+ } = this.config
35
+
36
+ return await RunningDappCache.findOrCreate(dappWithWalletId, xyOs, allowedNames ?? [], xnsNodeUrl, xnsNetwork)
37
+ }
38
+
39
+ private async installDappWallet(): Promise<RegisteredReactDapp> {
40
+ const { xyOs, dapp } = this.config
41
+ const dappSeedPhraseRepository = new DappSeedPhraseRepository(xyOs, [dapp.config.name])
42
+ const walletId = await dappSeedPhraseRepository.findOrCreate(dapp.config.name)
43
+
44
+ // Update the dapp with the walletId
45
+ return {
46
+ ...dapp,
47
+ config: {
48
+ ...dapp.config,
49
+ walletId,
50
+ },
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,2 @@
1
+ export * from './DappInitializer.ts'
2
+ export * from './useInstallDapp.tsx'
@@ -0,0 +1,39 @@
1
+ import { usePromise } from '@xylabs/react-promise'
2
+ import type { RegisteredReactDapp } from '@xyo-network/os-react-model'
3
+ import {
4
+ useDappMenu, useManageDappInjectableParamsFromRoute, useManageDappPathFromRoute, useXyOsUiContext,
5
+ } from '@xyo-network/os-react-runtime'
6
+
7
+ import { DappInitializer } from './DappInitializer.ts'
8
+
9
+ export const useInitializeDapp = (dapp: RegisteredReactDapp) => {
10
+ const xyOs = useXyOsUiContext()
11
+
12
+ const [installedDapp, nodeCreateError] = usePromise(async () => {
13
+ if (xyOs && dapp) {
14
+ const installer = new DappInitializer({
15
+ allowedNames: [dapp.config.name],
16
+ dapp,
17
+ xnsNetwork: undefined,
18
+ xnsNodeUrl: undefined,
19
+ xyOs,
20
+ })
21
+ return await installer.install()
22
+ }
23
+ }, [xyOs, dapp])
24
+
25
+ const { dappWallet, context } = installedDapp ?? {}
26
+
27
+ // support for routing
28
+ const routingError = useManageDappPathFromRoute(context, dapp.config.name)
29
+ const injectableErrors = useManageDappInjectableParamsFromRoute(context)
30
+
31
+ const dappMenu = useDappMenu(context, dapp.config.name)
32
+
33
+ return {
34
+ context,
35
+ dappMenu,
36
+ dappWallet,
37
+ errors: [routingError, nodeCreateError, ...injectableErrors].filter(Boolean),
38
+ }
39
+ }