@evefrontier/dapp-kit 0.1.9 → 0.2.0-alpha.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.
Files changed (211) hide show
  1. package/README.md +28 -25
  2. package/dist/config/dapp-kit.d.ts +4 -0
  3. package/dist/config/dapp-kit.d.ts.map +1 -0
  4. package/dist/config/dapp-kit.js +14 -0
  5. package/dist/config/index.d.ts +2 -0
  6. package/dist/config/index.d.ts.map +1 -0
  7. package/dist/config/index.js +1 -0
  8. package/dist/graphql/client.d.ts +277 -0
  9. package/dist/graphql/client.d.ts.map +1 -0
  10. package/dist/graphql/client.js +346 -0
  11. package/dist/graphql/index.d.ts +4 -0
  12. package/dist/graphql/index.d.ts.map +1 -0
  13. package/dist/graphql/index.js +16 -0
  14. package/dist/graphql/queries.d.ts +103 -0
  15. package/dist/graphql/queries.d.ts.map +1 -0
  16. package/{graphql/queries.ts → dist/graphql/queries.js} +113 -223
  17. package/dist/graphql/types.d.ts +396 -0
  18. package/dist/graphql/types.d.ts.map +1 -0
  19. package/dist/graphql/types.js +4 -0
  20. package/dist/hooks/index.d.ts +10 -0
  21. package/dist/hooks/index.d.ts.map +1 -0
  22. package/dist/hooks/index.js +8 -0
  23. package/dist/hooks/useCharacterDirectory.d.ts +16 -0
  24. package/dist/hooks/useCharacterDirectory.d.ts.map +1 -0
  25. package/dist/hooks/useCharacterDirectory.js +23 -0
  26. package/dist/hooks/useCharacterSearch.d.ts +24 -0
  27. package/dist/hooks/useCharacterSearch.d.ts.map +1 -0
  28. package/dist/hooks/useCharacterSearch.js +24 -0
  29. package/dist/hooks/useConnection.d.ts +51 -0
  30. package/dist/hooks/useConnection.d.ts.map +1 -0
  31. package/{hooks/useConnection.ts → dist/hooks/useConnection.js} +8 -10
  32. package/dist/hooks/useEntityRole.d.ts +26 -0
  33. package/dist/hooks/useEntityRole.d.ts.map +1 -0
  34. package/dist/hooks/useEntityRole.js +91 -0
  35. package/dist/hooks/useNotification.d.ts +72 -0
  36. package/dist/hooks/useNotification.d.ts.map +1 -0
  37. package/{hooks/useNotification.ts → dist/hooks/useNotification.js} +8 -12
  38. package/dist/hooks/useSmartObject.d.ts +44 -0
  39. package/dist/hooks/useSmartObject.d.ts.map +1 -0
  40. package/dist/hooks/useSmartObject.js +50 -0
  41. package/dist/hooks/useSponsoredTransaction.d.ts +147 -0
  42. package/dist/hooks/useSponsoredTransaction.d.ts.map +1 -0
  43. package/dist/hooks/useSponsoredTransaction.js +240 -0
  44. package/dist/hooks/useTypeNames.d.ts +11 -0
  45. package/dist/hooks/useTypeNames.d.ts.map +1 -0
  46. package/dist/hooks/useTypeNames.js +24 -0
  47. package/dist/index.d.ts +11 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +29 -0
  50. package/dist/providers/EveFrontierProvider.d.ts +23 -0
  51. package/dist/providers/EveFrontierProvider.d.ts.map +1 -0
  52. package/dist/providers/EveFrontierProvider.js +23 -0
  53. package/dist/providers/NotificationProvider.d.ts +14 -0
  54. package/dist/providers/NotificationProvider.d.ts.map +1 -0
  55. package/dist/providers/NotificationProvider.js +66 -0
  56. package/dist/providers/SmartObjectProvider.d.ts +31 -0
  57. package/dist/providers/SmartObjectProvider.d.ts.map +1 -0
  58. package/dist/providers/SmartObjectProvider.js +80 -0
  59. package/dist/providers/VaultProvider.d.ts +10 -0
  60. package/dist/providers/VaultProvider.d.ts.map +1 -0
  61. package/dist/providers/VaultProvider.js +79 -0
  62. package/dist/providers/index.d.ts +5 -0
  63. package/dist/providers/index.d.ts.map +1 -0
  64. package/dist/providers/index.js +4 -0
  65. package/dist/providers/smartObject/useEntityData.d.ts +29 -0
  66. package/dist/providers/smartObject/useEntityData.d.ts.map +1 -0
  67. package/dist/providers/smartObject/useEntityData.js +135 -0
  68. package/dist/providers/smartObject/useEntitySubscription.d.ts +14 -0
  69. package/dist/providers/smartObject/useEntitySubscription.d.ts.map +1 -0
  70. package/dist/providers/smartObject/useEntitySubscription.js +58 -0
  71. package/dist/providers/smartObject/useObjectSelection.d.ts +11 -0
  72. package/dist/providers/smartObject/useObjectSelection.d.ts.map +1 -0
  73. package/dist/providers/smartObject/useObjectSelection.js +27 -0
  74. package/dist/providers/smartObject/usePollingBackstop.d.ts +18 -0
  75. package/dist/providers/smartObject/usePollingBackstop.d.ts.map +1 -0
  76. package/dist/providers/smartObject/usePollingBackstop.js +38 -0
  77. package/dist/types/character.d.ts +21 -0
  78. package/dist/types/character.d.ts.map +1 -0
  79. package/dist/types/character.js +1 -0
  80. package/dist/types/contexts.d.ts +61 -0
  81. package/dist/types/contexts.d.ts.map +1 -0
  82. package/dist/types/contexts.js +6 -0
  83. package/dist/types/entity.d.ts +245 -0
  84. package/dist/types/entity.d.ts.map +1 -0
  85. package/dist/types/entity.js +6 -0
  86. package/dist/types/index.d.ts +6 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/index.js +5 -0
  89. package/dist/types/sponsoredTransaction.d.ts +26 -0
  90. package/dist/types/sponsoredTransaction.d.ts.map +1 -0
  91. package/dist/types/sponsoredTransaction.js +10 -0
  92. package/dist/types/types.d.ts +110 -0
  93. package/dist/types/types.d.ts.map +1 -0
  94. package/dist/types/types.js +41 -0
  95. package/dist/types/worldApiReturnTypes.d.ts +68 -0
  96. package/dist/types/worldApiReturnTypes.d.ts.map +1 -0
  97. package/dist/types/worldApiReturnTypes.js +1 -0
  98. package/{utils/burnRate.ts → dist/utils/burnRate.d.ts} +4 -29
  99. package/dist/utils/burnRate.d.ts.map +1 -0
  100. package/dist/utils/burnRate.js +25 -0
  101. package/dist/utils/characters.d.ts +26 -0
  102. package/dist/utils/characters.d.ts.map +1 -0
  103. package/dist/utils/characters.js +84 -0
  104. package/dist/utils/constants.d.ts +153 -0
  105. package/dist/utils/constants.d.ts.map +1 -0
  106. package/dist/utils/constants.js +190 -0
  107. package/dist/utils/datahub.d.ts +40 -0
  108. package/dist/utils/datahub.d.ts.map +1 -0
  109. package/{utils/datahub.ts → dist/utils/datahub.js} +32 -25
  110. package/dist/utils/entity.d.ts +58 -0
  111. package/dist/utils/entity.d.ts.map +1 -0
  112. package/dist/utils/entity.js +386 -0
  113. package/dist/utils/errors.d.ts +18 -0
  114. package/dist/utils/errors.d.ts.map +1 -0
  115. package/dist/utils/errors.js +128 -0
  116. package/dist/utils/events/entityEvents.d.ts +44 -0
  117. package/dist/utils/events/entityEvents.d.ts.map +1 -0
  118. package/dist/utils/events/entityEvents.js +95 -0
  119. package/dist/utils/events/entitySubscription.d.ts +30 -0
  120. package/dist/utils/events/entitySubscription.d.ts.map +1 -0
  121. package/dist/utils/events/entitySubscription.js +84 -0
  122. package/dist/utils/events/graphqlEventStream.d.ts +90 -0
  123. package/dist/utils/events/graphqlEventStream.d.ts.map +1 -0
  124. package/dist/utils/events/graphqlEventStream.js +198 -0
  125. package/dist/utils/events/refetchScheduler.d.ts +30 -0
  126. package/dist/utils/events/refetchScheduler.d.ts.map +1 -0
  127. package/dist/utils/events/refetchScheduler.js +57 -0
  128. package/dist/utils/events/sseClient.d.ts +42 -0
  129. package/dist/utils/events/sseClient.d.ts.map +1 -0
  130. package/dist/utils/events/sseClient.js +97 -0
  131. package/dist/utils/fuel.d.ts +231 -0
  132. package/dist/utils/fuel.d.ts.map +1 -0
  133. package/dist/utils/fuel.js +652 -0
  134. package/dist/utils/grid.d.ts +115 -0
  135. package/dist/utils/grid.d.ts.map +1 -0
  136. package/dist/utils/grid.js +115 -0
  137. package/dist/utils/index.d.ts +15 -0
  138. package/dist/utils/index.d.ts.map +1 -0
  139. package/dist/utils/index.js +22 -0
  140. package/dist/utils/inventory.d.ts +3 -0
  141. package/dist/utils/inventory.d.ts.map +1 -0
  142. package/dist/utils/inventory.js +12 -0
  143. package/dist/utils/logger.d.ts +25 -0
  144. package/dist/utils/logger.d.ts.map +1 -0
  145. package/dist/utils/logger.js +228 -0
  146. package/dist/utils/mapping.d.ts +30 -0
  147. package/dist/utils/mapping.d.ts.map +1 -0
  148. package/dist/utils/mapping.js +73 -0
  149. package/dist/utils/mvr/worldTypes.d.ts +35 -0
  150. package/dist/utils/mvr/worldTypes.d.ts.map +1 -0
  151. package/dist/utils/mvr/worldTypes.js +54 -0
  152. package/dist/utils/role.d.ts +116 -0
  153. package/dist/utils/role.d.ts.map +1 -0
  154. package/dist/utils/role.js +120 -0
  155. package/dist/utils/smartObject.d.ts +24 -0
  156. package/dist/utils/smartObject.d.ts.map +1 -0
  157. package/dist/utils/smartObject.js +24 -0
  158. package/dist/utils/utils.d.ts +133 -0
  159. package/dist/utils/utils.d.ts.map +1 -0
  160. package/dist/utils/utils.js +213 -0
  161. package/dist/wallet/features.d.ts +28 -0
  162. package/dist/wallet/features.d.ts.map +1 -0
  163. package/dist/wallet/features.js +22 -0
  164. package/dist/wallet/index.d.ts +9 -0
  165. package/dist/wallet/index.d.ts.map +1 -0
  166. package/dist/wallet/index.js +9 -0
  167. package/dist/wallet/utils.d.ts +71 -0
  168. package/dist/wallet/utils.d.ts.map +1 -0
  169. package/dist/wallet/utils.js +79 -0
  170. package/package.json +69 -35
  171. package/config/dapp-kit.ts +0 -20
  172. package/config/index.ts +0 -1
  173. package/graphql/client.ts +0 -578
  174. package/graphql/index.ts +0 -39
  175. package/graphql/types.ts +0 -468
  176. package/hooks/index.ts +0 -15
  177. package/hooks/useSmartObject.ts +0 -66
  178. package/hooks/useSponsoredTransaction.ts +0 -442
  179. package/index.ts +0 -88
  180. package/providers/EveFrontierProvider.tsx +0 -41
  181. package/providers/NotificationProvider.tsx +0 -108
  182. package/providers/SmartObjectProvider.tsx +0 -296
  183. package/providers/VaultProvider.tsx +0 -108
  184. package/providers/index.ts +0 -10
  185. package/types/contexts.ts +0 -67
  186. package/types/global.d.ts +0 -7
  187. package/types/index.ts +0 -4
  188. package/types/sponsoredTransaction.ts +0 -70
  189. package/types/types.ts +0 -198
  190. package/types/worldApiReturnTypes.ts +0 -144
  191. package/utils/__tests__/burnRate.test.ts +0 -121
  192. package/utils/__tests__/character.test.ts +0 -112
  193. package/utils/__tests__/characterOwnedObjects.test.ts +0 -225
  194. package/utils/__tests__/config.test.ts +0 -424
  195. package/utils/__tests__/datahub.test.ts +0 -58
  196. package/utils/__tests__/logger.test.ts +0 -145
  197. package/utils/__tests__/mapping.test.ts +0 -439
  198. package/utils/__tests__/utils.test.ts +0 -299
  199. package/utils/character.ts +0 -46
  200. package/utils/characterOwnedObjects.ts +0 -53
  201. package/utils/config.ts +0 -151
  202. package/utils/constants.ts +0 -254
  203. package/utils/errors.ts +0 -171
  204. package/utils/index.ts +0 -47
  205. package/utils/logger.ts +0 -300
  206. package/utils/mapping.ts +0 -118
  207. package/utils/transforms.ts +0 -263
  208. package/utils/utils.ts +0 -270
  209. package/wallet/features.ts +0 -136
  210. package/wallet/index.ts +0 -26
  211. package/wallet/utils.ts +0 -117
@@ -0,0 +1,79 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCurrentAccount, useDAppKit, useWallets, } from '@mysten/dapp-kit-react';
3
+ import { createContext, useEffect, useRef } from 'react';
4
+ import { SupportedWallets } from '../types/index.js';
5
+ import { createLogger, STORAGE_KEYS } from '../utils/index.js';
6
+ const log = createLogger();
7
+ /** @category Providers */
8
+ export const VaultContext = createContext({
9
+ currentAccount: null,
10
+ walletAddress: undefined,
11
+ hasEveVault: false,
12
+ isConnected: false,
13
+ handleConnect: () => { },
14
+ handleDisconnect: () => { },
15
+ });
16
+ /**
17
+ * VaultProvider component provides a context for managing Sui wallet connections.
18
+ * It uses @mysten/dapp-kit-react hooks for wallet management.
19
+ */
20
+ // Module-level flag to prevent auto-connect from running multiple times
21
+ // (persists across component remounts caused by wallet state changes)
22
+ let globalAutoConnectAttempted = false;
23
+ /** @category Providers */
24
+ const VaultProvider = ({ children }) => {
25
+ // Sui dapp-kit hooks
26
+ const currentAccount = useCurrentAccount();
27
+ const dAppKit = useDAppKit();
28
+ const { connectWallet, disconnectWallet } = dAppKit;
29
+ const wallets = useWallets();
30
+ // Find Eve Vault wallet if available
31
+ const eveVaultWallet = wallets.find((wallet) => wallet.name.includes(SupportedWallets.EVE_FRONTIER_CLIENT_WALLET) ||
32
+ wallet.name.includes(SupportedWallets.EVE_VAULT));
33
+ // Track if auto-connect has been attempted to prevent infinite loops
34
+ const hasAttemptedAutoConnect = useRef(false);
35
+ const handleConnect = () => {
36
+ const walletToConnect = eveVaultWallet || wallets[0];
37
+ if (!walletToConnect) {
38
+ log.warn('No wallet available to connect');
39
+ return;
40
+ }
41
+ try {
42
+ connectWallet({ wallet: walletToConnect });
43
+ log.info('[DappKit] Connected to wallet:', walletToConnect.name);
44
+ localStorage.setItem(STORAGE_KEYS.CONNECTED, 'true');
45
+ }
46
+ catch (error) {
47
+ log.error('[DappKit] Failed to connect wallet:', error);
48
+ }
49
+ };
50
+ const handleDisconnect = () => {
51
+ disconnectWallet();
52
+ localStorage.removeItem(STORAGE_KEYS.CONNECTED);
53
+ log.info('[DappKit] Wallet disconnected');
54
+ };
55
+ // Auto-reconnect if user was previously connected (only once)
56
+ useEffect(() => {
57
+ // Use both local ref AND global flag for maximum protection against re-render loops
58
+ if (hasAttemptedAutoConnect.current || globalAutoConnectAttempted)
59
+ return;
60
+ const isPreviouslyConnected = localStorage.getItem(STORAGE_KEYS.CONNECTED) === 'true';
61
+ if (typeof window !== 'undefined' &&
62
+ isPreviouslyConnected &&
63
+ eveVaultWallet) {
64
+ hasAttemptedAutoConnect.current = true;
65
+ globalAutoConnectAttempted = true;
66
+ handleConnect();
67
+ }
68
+ }, [eveVaultWallet, handleConnect]);
69
+ const isConnected = !!currentAccount;
70
+ return (_jsx(VaultContext.Provider, { value: {
71
+ walletAddress: currentAccount?.address,
72
+ currentAccount,
73
+ hasEveVault: !!eveVaultWallet,
74
+ isConnected,
75
+ handleConnect,
76
+ handleDisconnect,
77
+ }, children: children }));
78
+ };
79
+ export default VaultProvider;
@@ -0,0 +1,5 @@
1
+ export { default as EveFrontierProvider } from './EveFrontierProvider.js';
2
+ export { default as NotificationProvider, NotificationContext, } from './NotificationProvider.js';
3
+ export { default as SmartObjectProvider, SmartObjectContext, } from './SmartObjectProvider.js';
4
+ export { default as VaultProvider, VaultContext } from './VaultProvider.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EACL,OAAO,IAAI,oBAAoB,EAC/B,mBAAmB,GACpB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,OAAO,IAAI,mBAAmB,EAC9B,kBAAkB,GACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { default as EveFrontierProvider } from './EveFrontierProvider.js';
2
+ export { default as NotificationProvider, NotificationContext, } from './NotificationProvider.js';
3
+ export { default as SmartObjectProvider, SmartObjectContext, } from './SmartObjectProvider.js';
4
+ export { default as VaultProvider, VaultContext } from './VaultProvider.js';
@@ -0,0 +1,29 @@
1
+ import { type Dispatch, type SetStateAction } from 'react';
2
+ import type { EntityData, EntityOwner } from '../../types/index.js';
3
+ import type { FetchObjectDataInput } from '../../utils/smartObject.js';
4
+ /** How a refetch that is not the initial fetch behaves. */
5
+ export interface RefetchOptions {
6
+ /**
7
+ * Fetch the entity even when its latest version looks unchanged, e.g. after
8
+ * an event about it. Everything else stays as for a poll: a fetch already
9
+ * running is left to finish, a transient miss keeps the last good entity,
10
+ * and loading is not shown.
11
+ */
12
+ skipVersionCheck?: boolean;
13
+ }
14
+ /**
15
+ * Holds the selected world entity, its owner, and loading/error state, and
16
+ * fetches them. Refetches first compare the object's latest version and skip
17
+ * the full fetch when it hasn't changed.
18
+ */
19
+ export declare function useEntityData(): {
20
+ entity: EntityData | null;
21
+ entityOwner: EntityOwner | null;
22
+ loading: boolean;
23
+ setLoading: Dispatch<SetStateAction<boolean>>;
24
+ error: string | null;
25
+ fetchObjectData: (input: FetchObjectDataInput, isInitialFetch?: boolean, options?: RefetchOptions) => Promise<void>;
26
+ /** Forgets the last fetched version and owner, e.g. when the selection changes. */
27
+ resetTracking: () => void;
28
+ };
29
+ //# sourceMappingURL=useEntityData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEntityData.d.ts","sourceRoot":"","sources":["../../../providers/smartObject/useEntityData.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,EAIpB,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAS1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AA4BnE,2DAA2D;AAC3D,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI;IAC/B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;IACzB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAA;IAC/B,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;IAC7C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,eAAe,EAAE,CACf,KAAK,EAAE,oBAAoB,EAC3B,cAAc,CAAC,EAAE,OAAO,EACxB,OAAO,CAAC,EAAE,cAAc,KACrB,OAAO,CAAC,IAAI,CAAC,CAAA;IAClB,mFAAmF;IACnF,aAAa,EAAE,MAAM,IAAI,CAAA;CAC1B,CAsHA"}
@@ -0,0 +1,135 @@
1
+ import { useCallback, useRef, useState, } from 'react';
2
+ import { getObjectLatestVersion } from '../../graphql/index.js';
3
+ import { createLogger, fetchEntity, fetchEntityOwner, getObjectId, isEntity, parseEntity, } from '../../utils/index.js';
4
+ const log = createLogger();
5
+ /** Resolves the Sui object ID for a complete input (see isCompleteInput). */
6
+ async function resolveObjectId(input) {
7
+ if (!('itemId' in input)) {
8
+ log.info('[DappKit] SmartObjectProvider: Fetching entity:', {
9
+ objectId: input.objectId,
10
+ });
11
+ return input.objectId;
12
+ }
13
+ const objectId = await getObjectId(input.itemId, input.selectedTenant);
14
+ log.info('[DappKit] SmartObjectProvider: Fetching entity:', {
15
+ itemId: input.itemId,
16
+ selectedTenant: input.selectedTenant,
17
+ objectId,
18
+ });
19
+ return objectId;
20
+ }
21
+ function isCompleteInput(input) {
22
+ return 'itemId' in input
23
+ ? !!input.itemId && !!input.selectedTenant
24
+ : !!input.objectId;
25
+ }
26
+ /**
27
+ * Holds the selected world entity, its owner, and loading/error state, and
28
+ * fetches them. Refetches first compare the object's latest version and skip
29
+ * the full fetch when it hasn't changed.
30
+ */
31
+ export function useEntityData() {
32
+ const [entity, setEntity] = useState(null);
33
+ const [entityOwner, setEntityOwner] = useState(null);
34
+ const [loading, setLoading] = useState(true);
35
+ const [error, setError] = useState(null);
36
+ const lastVersionRef = useRef(null);
37
+ const lastAccessCapIdRef = useRef(undefined);
38
+ const lastOwnerRef = useRef(null);
39
+ // Bumped per fetch and on reset; a fetch only commits while it is the latest
40
+ const requestIdRef = useRef(0);
41
+ const inFlightRef = useRef(false);
42
+ const fetchObjectData = useCallback(async (input, isInitialFetch = false, { skipVersionCheck = false } = {}) => {
43
+ if (!isCompleteInput(input))
44
+ return;
45
+ // Let a slow fetch finish rather than superseding it with the next poll
46
+ if (!isInitialFetch && inFlightRef.current)
47
+ return;
48
+ const requestId = ++requestIdRef.current;
49
+ const isStale = () => requestId !== requestIdRef.current;
50
+ inFlightRef.current = true;
51
+ if (isInitialFetch) {
52
+ setLoading(true);
53
+ setError(null);
54
+ }
55
+ try {
56
+ const objectId = await resolveObjectId(input);
57
+ // Only refetch everything if the object changed (optimization for polling)
58
+ if (!isInitialFetch &&
59
+ !skipVersionCheck &&
60
+ lastVersionRef.current !== null) {
61
+ const latest = await getObjectLatestVersion(objectId);
62
+ const version = latest.data?.latestVersion.nodes[0]?.version;
63
+ if (version === lastVersionRef.current)
64
+ return;
65
+ }
66
+ const raw = await fetchEntity(objectId);
67
+ if (isStale())
68
+ return;
69
+ if (!raw || !isEntity(raw)) {
70
+ // Keep the last good entity through a transient miss while polling
71
+ // (e.g. the indexer lagging); retry on the next tick
72
+ if (!isInitialFetch && lastVersionRef.current !== null) {
73
+ log.warn('[DappKit] SmartObjectProvider: Entity missing on poll');
74
+ return;
75
+ }
76
+ log.warn('[DappKit] SmartObjectProvider: Object is not an entity');
77
+ setEntity(null);
78
+ setEntityOwner(null);
79
+ setError('Object not found or not an entity');
80
+ lastVersionRef.current = null;
81
+ return;
82
+ }
83
+ const parsed = parseEntity(raw);
84
+ // Re-check the cap holder when the entity changes; the Character is
85
+ // refetched only when the holder differs. TODO: a cap move alone isn't
86
+ // seen, as it doesn't change the entity's version
87
+ const previousOwner = parsed.accessCapId === lastAccessCapIdRef.current
88
+ ? lastOwnerRef.current
89
+ : null;
90
+ const owner = parsed.accessCapId
91
+ ? await fetchEntityOwner(parsed.accessCapId, previousOwner)
92
+ : null;
93
+ if (isStale())
94
+ return;
95
+ log.info('[DappKit] SmartObjectProvider: Entity data updated', parsed);
96
+ setEntity(parsed);
97
+ setEntityOwner(owner);
98
+ setError(null);
99
+ // Recorded only once the owner resolved, so a failed lookup is retried
100
+ lastVersionRef.current = parsed.version;
101
+ lastAccessCapIdRef.current = parsed.accessCapId;
102
+ lastOwnerRef.current = owner;
103
+ }
104
+ catch (err) {
105
+ if (isStale())
106
+ return;
107
+ log.error('[DappKit] SmartObjectProvider: Query error:', err);
108
+ setError(err instanceof Error ? err.message : 'Failed to fetch entity');
109
+ }
110
+ finally {
111
+ if (!isStale()) {
112
+ inFlightRef.current = false;
113
+ if (isInitialFetch) {
114
+ setLoading(false);
115
+ }
116
+ }
117
+ }
118
+ }, []);
119
+ const resetTracking = useCallback(() => {
120
+ requestIdRef.current++;
121
+ inFlightRef.current = false;
122
+ lastVersionRef.current = null;
123
+ lastAccessCapIdRef.current = undefined;
124
+ lastOwnerRef.current = null;
125
+ }, []);
126
+ return {
127
+ entity,
128
+ entityOwner,
129
+ loading,
130
+ setLoading,
131
+ error,
132
+ fetchObjectData,
133
+ resetTracking,
134
+ };
135
+ }
@@ -0,0 +1,14 @@
1
+ import { type SubscriptionStatus, type UpdateTransport } from '../../utils/constants.js';
2
+ /**
3
+ * Subscribes to the selected entity's inventory and power events over the
4
+ * GraphQL subscription endpoint and refetches when one arrives. `off` with
5
+ * the `polling` transport or before the entity has loaded; `failed` once the
6
+ * subscription has failed, until the entity or transport changes.
7
+ */
8
+ export declare function useEntitySubscription({ transport, entityId, tenant, refetch, }: {
9
+ transport: UpdateTransport;
10
+ entityId: string | null;
11
+ tenant: string | undefined;
12
+ refetch: () => Promise<void>;
13
+ }): SubscriptionStatus;
14
+ //# sourceMappingURL=useEntitySubscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEntitySubscription.d.ts","sourceRoot":"","sources":["../../../providers/smartObject/useEntitySubscription.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAA;AAQ9B;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,SAAS,EACT,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE;IACD,SAAS,EAAE,eAAe,CAAA;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B,GAAG,kBAAkB,CAkDrB"}
@@ -0,0 +1,58 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { getGraphqlSubscriptionAuthToken, getSuiGraphqlSubscriptionEndpoint, } from '../../utils/constants.js';
3
+ import { entityEventTypes } from '../../utils/events/entityEvents.js';
4
+ import { startEntitySubscription } from '../../utils/events/entitySubscription.js';
5
+ import { createGraphqlSseEventStreamClient } from '../../utils/events/sseClient.js';
6
+ import { createLogger } from '../../utils/logger.js';
7
+ const log = createLogger();
8
+ /**
9
+ * Subscribes to the selected entity's inventory and power events over the
10
+ * GraphQL subscription endpoint and refetches when one arrives. `off` with
11
+ * the `polling` transport or before the entity has loaded; `failed` once the
12
+ * subscription has failed, until the entity or transport changes.
13
+ */
14
+ export function useEntitySubscription({ transport, entityId, tenant, refetch, }) {
15
+ const [status, setStatus] = useState('off');
16
+ // The latest refetch, without resubscribing when its identity changes
17
+ const refetchRef = useRef(refetch);
18
+ refetchRef.current = refetch;
19
+ useEffect(() => {
20
+ if (transport !== 'subscription' || !entityId) {
21
+ setStatus('off');
22
+ return;
23
+ }
24
+ let eventTypes;
25
+ try {
26
+ eventTypes = entityEventTypes(tenant);
27
+ }
28
+ catch (error) {
29
+ log.warn('[DappKit] No world packages to subscribe to; falling back to polling', error);
30
+ setStatus('failed');
31
+ return;
32
+ }
33
+ let subscription = null;
34
+ const client = createGraphqlSseEventStreamClient({
35
+ url: getSuiGraphqlSubscriptionEndpoint(),
36
+ authToken: getGraphqlSubscriptionAuthToken(),
37
+ onUnsupported: (error) => subscription?.fail(error),
38
+ });
39
+ subscription = startEntitySubscription({
40
+ client,
41
+ eventTypes,
42
+ entityId,
43
+ refetch: () => refetchRef.current(),
44
+ onStatus: (s) => {
45
+ setStatus(s);
46
+ // Catch up on any transactions that arrived between the initial fetch
47
+ // and the subscription connecting.
48
+ if (s === 'live')
49
+ refetchRef.current();
50
+ },
51
+ });
52
+ return () => {
53
+ subscription?.stop();
54
+ client.dispose();
55
+ };
56
+ }, [transport, entityId, tenant]);
57
+ return status;
58
+ }
@@ -0,0 +1,11 @@
1
+ import { type FetchObjectDataInput, type ObjectSelection } from '../../utils/smartObject.js';
2
+ /**
3
+ * Reads the object to show once on mount: a Sui object ID from VITE_OBJECT_ID,
4
+ * else ?itemId= with ?tenant= (fallback DEFAULT_TENANT).
5
+ */
6
+ export declare function useObjectSelection(): {
7
+ selection: ObjectSelection | null;
8
+ /** Fetch input for the selection, or null until an object is selected. */
9
+ input: FetchObjectDataInput | null;
10
+ };
11
+ //# sourceMappingURL=useObjectSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useObjectSelection.d.ts","sourceRoot":"","sources":["../../../providers/smartObject/useObjectSelection.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAGrB,MAAM,yBAAyB,CAAA;AAIhC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI;IACpC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAA;IACjC,0EAA0E;IAC1E,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAAA;CACnC,CAsCA"}
@@ -0,0 +1,27 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { createLogger } from '../../utils/index.js';
3
+ import { readObjectSelection, toFetchObjectDataInput, } from '../../utils/smartObject.js';
4
+ const log = createLogger();
5
+ /**
6
+ * Reads the object to show once on mount: a Sui object ID from VITE_OBJECT_ID,
7
+ * else ?itemId= with ?tenant= (fallback DEFAULT_TENANT).
8
+ */
9
+ export function useObjectSelection() {
10
+ const [selection, setSelection] = useState(null);
11
+ useEffect(() => {
12
+ log.info('[DappKit] SmartObjectProvider: Checking for item ID');
13
+ const next = readObjectSelection(window.location.search, import.meta.env.VITE_OBJECT_ID);
14
+ if (!next) {
15
+ log.error('[DappKit] SmartObjectProvider: No object ID provided');
16
+ return;
17
+ }
18
+ if (next.isObjectIdDirect) {
19
+ log.info('[DappKit] SmartObjectProvider: Using Sui object ID from env:', next.objectId);
20
+ }
21
+ setSelection(next);
22
+ }, []);
23
+ const input = useMemo(() => selection
24
+ ? toFetchObjectDataInput(selection.objectId, selection.tenant, selection.isObjectIdDirect)
25
+ : null, [selection]);
26
+ return { selection, input };
27
+ }
@@ -0,0 +1,18 @@
1
+ import type { FetchObjectDataInput } from '../../utils/smartObject.js';
2
+ /**
3
+ * Fetches the selected object, then polls it for updates every `intervalMs`.
4
+ * Reads are public, so no wallet needs to be connected. Each tick is a cheap
5
+ * version check until the object changes; an interval of 0 disables polling.
6
+ *
7
+ * The interval can change while mounted (the subscription coming up or
8
+ * failing); that only restarts the timer, not the initial fetch.
9
+ */
10
+ export declare function usePollingBackstop({ input, fetchObjectData, setLoading, resetTracking, intervalMs, }: {
11
+ input: FetchObjectDataInput | null;
12
+ fetchObjectData: (input: FetchObjectDataInput, isInitialFetch?: boolean) => Promise<void>;
13
+ setLoading: (loading: boolean) => void;
14
+ resetTracking: () => void;
15
+ /** Polling interval in ms; 0 disables it */
16
+ intervalMs: number;
17
+ }): void;
18
+ //# sourceMappingURL=usePollingBackstop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePollingBackstop.d.ts","sourceRoot":"","sources":["../../../providers/smartObject/usePollingBackstop.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAInE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,eAAe,EACf,UAAU,EACV,aAAa,EACb,UAAU,GACX,EAAE;IACD,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAAA;IAClC,eAAe,EAAE,CACf,KAAK,EAAE,oBAAoB,EAC3B,cAAc,CAAC,EAAE,OAAO,KACrB,OAAO,CAAC,IAAI,CAAC,CAAA;IAClB,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,aAAa,EAAE,MAAM,IAAI,CAAA;IACzB,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,IAAI,CAoCP"}
@@ -0,0 +1,38 @@
1
+ import { useEffect } from 'react';
2
+ import { createLogger } from '../../utils/index.js';
3
+ const log = createLogger();
4
+ /**
5
+ * Fetches the selected object, then polls it for updates every `intervalMs`.
6
+ * Reads are public, so no wallet needs to be connected. Each tick is a cheap
7
+ * version check until the object changes; an interval of 0 disables polling.
8
+ *
9
+ * The interval can change while mounted (the subscription coming up or
10
+ * failing); that only restarts the timer, not the initial fetch.
11
+ */
12
+ export function usePollingBackstop({ input, fetchObjectData, setLoading, resetTracking, intervalMs, }) {
13
+ useEffect(() => {
14
+ if (!input) {
15
+ setLoading(false);
16
+ return;
17
+ }
18
+ fetchObjectData(input, true);
19
+ return resetTracking;
20
+ }, [input, fetchObjectData, setLoading, resetTracking]);
21
+ useEffect(() => {
22
+ if (!input)
23
+ return;
24
+ const selectedObjectId = 'itemId' in input ? input.itemId : input.objectId;
25
+ if (intervalMs <= 0) {
26
+ log.info('[DappKit] SmartObjectProvider: Polling backstop disabled', selectedObjectId);
27
+ return;
28
+ }
29
+ const intervalId = setInterval(() => {
30
+ fetchObjectData(input, false);
31
+ }, intervalMs);
32
+ log.info('[DappKit] SmartObjectProvider: Started polling for object:', selectedObjectId, { pollingInterval: intervalMs });
33
+ return () => {
34
+ clearInterval(intervalId);
35
+ log.info('[DappKit] SmartObjectProvider: Stopped polling');
36
+ };
37
+ }, [input, fetchObjectData, intervalMs]);
38
+ }
@@ -0,0 +1,21 @@
1
+ /** Nested `metadata` fields we read when present. */
2
+ type CharacterJsonMetadata = {
3
+ name?: unknown;
4
+ };
5
+ /** Nested `key` fields we read when present. */
6
+ type CharacterJsonKey = {
7
+ item_id?: unknown;
8
+ };
9
+ /**
10
+ * Top-level JSON shape from wallet/assembly responses (all keys optional).
11
+ * No index signature — enables dot access under `noPropertyAccessFromIndexSignature`.
12
+ */
13
+ type LooseCharacterJson = {
14
+ id?: unknown;
15
+ character_address?: unknown;
16
+ metadata?: unknown;
17
+ key?: unknown;
18
+ tribe_id?: unknown;
19
+ };
20
+ export type { CharacterJsonKey, CharacterJsonMetadata, LooseCharacterJson };
21
+ //# sourceMappingURL=character.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"character.d.ts","sourceRoot":"","sources":["../../types/character.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,KAAK,qBAAqB,GAAG;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,gDAAgD;AAChD,KAAK,gBAAgB,GAAG;IACtB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;;GAGG;AACH,KAAK,kBAAkB,GAAG;IACxB,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,YAAY,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ import type { WalletAccount } from '@mysten/wallet-standard';
2
+ import type { EntityData, EntityOwner } from './entity.js';
3
+ import { type DetailedSmartCharacterResponse, Severity } from './types.js';
4
+ /**
5
+ * Vault context: account, connection state, and connect/disconnect handlers.
6
+ * @category Types
7
+ */
8
+ export interface VaultContextType {
9
+ currentAccount: WalletAccount | null;
10
+ walletAddress: string | undefined;
11
+ hasEveVault: boolean;
12
+ isConnected: boolean;
13
+ handleConnect: () => void;
14
+ handleDisconnect: () => void;
15
+ }
16
+ export declare enum SupportedWallets {
17
+ EVE_VAULT = "Eve Vault",
18
+ EVE_FRONTIER_CLIENT_WALLET = "EVE Frontier Client Wallet"
19
+ }
20
+ /**
21
+ * Smart object context: entity, owner, loading, error, and refetch.
22
+ * @category Types
23
+ */
24
+ export interface SmartObjectContextType {
25
+ tenant: string;
26
+ /** The selected world entity and its components */
27
+ entity: EntityData | null;
28
+ /** Who controls the entity, resolved from its AccessCap */
29
+ entityOwner: EntityOwner | null;
30
+ /** @deprecated Always null; the provider now reads world entities. Use `entityOwner`. */
31
+ assemblyOwner: DetailedSmartCharacterResponse | null;
32
+ loading: boolean;
33
+ error: string | null;
34
+ refetch: () => Promise<void>;
35
+ }
36
+ export interface NotifySuccess {
37
+ type: Severity.Success;
38
+ txHash?: string;
39
+ message?: string;
40
+ onSuccess?: () => void;
41
+ }
42
+ export interface NotifyOther {
43
+ type: Severity.Error | Severity.Warning | Severity.Info;
44
+ message?: string;
45
+ }
46
+ /** @category Types */
47
+ export interface NotificationContextType {
48
+ notify: (notification: NotifySuccess | NotifyOther) => void;
49
+ notification: NotificationState;
50
+ handleClose: () => void;
51
+ }
52
+ /** @category Types */
53
+ export interface NotificationState {
54
+ message: string;
55
+ txHash: string;
56
+ onSuccess: () => void;
57
+ severity: Severity;
58
+ handleClose: () => void;
59
+ isOpen: boolean;
60
+ }
61
+ //# sourceMappingURL=contexts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../types/contexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,EAAE,KAAK,8BAA8B,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvE;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,aAAa,GAAG,IAAI,CAAA;IACpC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,WAAW,EAAE,OAAO,CAAA;IACpB,WAAW,EAAE,OAAO,CAAA;IACpB,aAAa,EAAE,MAAM,IAAI,CAAA;IACzB,gBAAgB,EAAE,MAAM,IAAI,CAAA;CAC7B;AAED,oBAAY,gBAAgB;IAC1B,SAAS,cAAc;IACvB,0BAA0B,+BAA+B;CAC1D;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAA;IACd,mDAAmD;IACnD,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;IACzB,2DAA2D;IAC3D,WAAW,EAAE,WAAW,GAAG,IAAI,CAAA;IAC/B,yFAAyF;IACzF,aAAa,EAAE,8BAA8B,GAAG,IAAI,CAAA;IACpD,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAA;IACvD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,sBAAsB;AACtB,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,CAAC,YAAY,EAAE,aAAa,GAAG,WAAW,KAAK,IAAI,CAAA;IAC3D,YAAY,EAAE,iBAAiB,CAAA;IAC/B,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB;AAED,sBAAsB;AACtB,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,QAAQ,EAAE,QAAQ,CAAA;IAClB,WAAW,EAAE,MAAM,IAAI,CAAA;IACvB,MAAM,EAAE,OAAO,CAAA;CAChB"}
@@ -0,0 +1,6 @@
1
+ import { Severity } from './types.js';
2
+ export var SupportedWallets;
3
+ (function (SupportedWallets) {
4
+ SupportedWallets["EVE_VAULT"] = "Eve Vault";
5
+ SupportedWallets["EVE_FRONTIER_CLIENT_WALLET"] = "EVE Frontier Client Wallet";
6
+ })(SupportedWallets || (SupportedWallets = {}));