@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
@@ -1,296 +0,0 @@
1
- import {
2
- ReactNode,
3
- useState,
4
- createContext,
5
- useEffect,
6
- useCallback,
7
- useRef,
8
- } from "react";
9
-
10
- import {
11
- Assemblies,
12
- AssemblyType,
13
- QueryParams,
14
- DetailedSmartCharacterResponse,
15
- } from "../types";
16
-
17
- import { DEFAULT_TENANT, POLLING_INTERVAL } from "../utils/constants";
18
- import { getAssemblyWithOwner, MoveObjectData } from "../graphql";
19
- import {
20
- createLogger,
21
- getObjectId,
22
- transformToAssembly,
23
- transformToCharacter,
24
- } from "../utils";
25
- import { getDatahubGameInfo } from "../utils/datahub";
26
- import { useConnection } from "../hooks/useConnection";
27
- import { SmartObjectContextType } from "../types";
28
-
29
- const log = createLogger();
30
-
31
- /** Input for fetching object data: either itemId + tenant (derive object ID) or a Sui object ID directly.
32
- * @category Types
33
- */
34
- export type FetchObjectDataInput =
35
- | { itemId: string; selectedTenant: string }
36
- | { objectId: string };
37
-
38
- /** @category Providers */
39
- export const SmartObjectContext = createContext<SmartObjectContextType>({
40
- tenant: DEFAULT_TENANT,
41
- assembly: null,
42
- assemblyOwner: null,
43
- loading: true,
44
- error: null,
45
- refetch: async () => {},
46
- });
47
-
48
- /**
49
- * SmartObjectProvider component provides context for smart objects data.
50
- * It uses GraphQL queries to fetch objects on the Sui blockchain
51
- * from the EVE Frontier package, with optional polling for updates.
52
- *
53
- * The provider fetches both the assembly data and its owner (assemblyOwner) information:
54
- * 1. Fetches assembly data with dynamic fields
55
- * 2. Uses owner_cap_id to resolve the Character OwnerCap
56
- * 3. Fetches full assemblyOwner data from the Character ID
57
- *
58
- * @category Providers
59
- */
60
- const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
61
- const [assembly, setAssembly] = useState<AssemblyType<Assemblies> | null>(
62
- null,
63
- );
64
- const [assemblyOwner, setAssemblyOwner] =
65
- useState<DetailedSmartCharacterResponse | null>(null);
66
- const [selectedObjectId, setSelectedObjectId] = useState<string>("");
67
- const [selectedTenant, setSelectedTenant] = useState<string>("");
68
- const [isObjectIdDirect, setIsObjectIdDirect] = useState<boolean>(false); // Whether selectedObjectId is a Sui object ID or derived from itemId + tenant.
69
- const [loading, setLoading] = useState<boolean>(true);
70
- const [error, setError] = useState<string | null>(null);
71
-
72
- const pollingRef = useRef<ReturnType<typeof setTimeout> | null>(null);
73
- const lastDataHashRef = useRef<string | null>(null);
74
-
75
- const { isConnected } = useConnection();
76
-
77
- // Fetch object data with owner/assemblyOwner info.
78
- // Accepts either { itemId, selectedTenant } (derive Sui object ID) or { objectId } (use directly).
79
- const fetchObjectData = useCallback(
80
- async (input: FetchObjectDataInput, isInitialFetch = false) => {
81
- const hasItemId = "itemId" in input && "selectedTenant" in input;
82
- if (hasItemId) {
83
- if (!input.itemId || !input.selectedTenant) return;
84
- } else {
85
- if (!input.objectId) return;
86
- }
87
-
88
- if (isInitialFetch) {
89
- setLoading(true);
90
- }
91
- setError(null);
92
-
93
- try {
94
- const objectId = hasItemId
95
- ? await getObjectId(input.itemId, input.selectedTenant)
96
- : input.objectId;
97
- log.info(
98
- "[DappKit] SmartObjectProvider: Fetching object:",
99
- hasItemId
100
- ? { itemId: input.itemId, selectedTenant: input.selectedTenant }
101
- : { objectId },
102
- );
103
-
104
- // Fetch both assembly and assemblyOwner data
105
- const {
106
- moveObject,
107
- assemblyOwner: characterInfo,
108
- energySource,
109
- destinationGate,
110
- } = await getAssemblyWithOwner(objectId);
111
-
112
- if (!moveObject) {
113
- log.warn(
114
- "[DappKit] SmartObjectProvider: Object not found or not a Move object",
115
- );
116
- setAssembly(null);
117
- setAssemblyOwner(null);
118
- setError("Object not found or not a Move object");
119
- return;
120
- }
121
-
122
- // Create a hash of the data to check for changes
123
- const dataHash = JSON.stringify({
124
- moveObject,
125
- assemblyOwner: characterInfo,
126
- energySource,
127
- });
128
-
129
- // Only update state if the data changed (optimization for polling)
130
- if (isInitialFetch || lastDataHashRef.current !== dataHash) {
131
- log.info("[DappKit] SmartObjectProvider: Object data updated");
132
- lastDataHashRef.current = dataHash;
133
-
134
- // Extract typeId from the raw JSON to fetch datahub info
135
- const rawJson = moveObject.contents?.json as
136
- | { type_id?: string; status?: { type_id?: string } }
137
- | undefined;
138
- const typeId = rawJson?.type_id || rawJson?.status?.type_id || "0";
139
-
140
- // Fetch datahub game info (name, description, image defaults)
141
- let datahubInfo = null;
142
- try {
143
- datahubInfo = await getDatahubGameInfo(parseInt(typeId, 10));
144
- } catch (err) {
145
- log.warn(
146
- "[DappKit] SmartObjectProvider: Failed to fetch datahub info:",
147
- err,
148
- );
149
- }
150
-
151
- // Transform assembly with assemblyOwner and datahub info
152
- const transformed = await transformToAssembly(
153
- objectId,
154
- moveObject as MoveObjectData,
155
- {
156
- character: characterInfo,
157
- datahubInfo,
158
- energySource: energySource,
159
- destinationGate: destinationGate,
160
- },
161
- );
162
-
163
- setAssembly(transformed);
164
-
165
- // Transform and set assemblyOwner: owner of the assembly
166
- if (characterInfo) {
167
- const transformedCharacter = transformToCharacter(characterInfo);
168
- setAssemblyOwner(transformedCharacter);
169
- } else {
170
- setAssemblyOwner(null);
171
- }
172
- }
173
- setError(null);
174
- } catch (err: unknown) {
175
- log.error("[DappKit] SmartObjectProvider: Query error:", err);
176
- setError(err instanceof Error ? err.message : "Failed to fetch object");
177
- } finally {
178
- if (isInitialFetch) {
179
- setLoading(false);
180
- }
181
- }
182
- },
183
- [],
184
- );
185
-
186
- // Initialize the object ID (env or query params) and tenant (query params).
187
- // Tenant comes from URL ?tenant= with fallback DEFAULT_TENANT.
188
- useEffect(() => {
189
- log.info("[DappKit] SmartObjectProvider: Checking for item ID");
190
-
191
- const queryParams = new URLSearchParams(window.location.search);
192
- const queryTenant =
193
- queryParams.get(QueryParams.TENANT)?.trim() || DEFAULT_TENANT;
194
-
195
- // Check if an object ID exists in the .env file
196
- const envObjectId = import.meta.env.VITE_OBJECT_ID;
197
-
198
- if (envObjectId) {
199
- log.info(
200
- "[DappKit] SmartObjectProvider: Using Sui object ID from env:",
201
- envObjectId,
202
- );
203
- setSelectedObjectId(envObjectId);
204
- setSelectedTenant(queryTenant);
205
- setIsObjectIdDirect(true);
206
- return;
207
- }
208
-
209
- // Else, derive object ID from item ID and tenant and passed via query param
210
- const queryItemId = queryParams.get(QueryParams.ITEM_ID);
211
-
212
- if (queryItemId) {
213
- setSelectedObjectId(queryItemId);
214
- setSelectedTenant(queryTenant);
215
- setIsObjectIdDirect(false);
216
- } else {
217
- log.error("[DappKit] SmartObjectProvider: No object ID provided");
218
- setLoading(false);
219
- }
220
- }, []);
221
-
222
- // Fetch and poll for object data
223
- useEffect(() => {
224
- if (!selectedObjectId || !isConnected) {
225
- setLoading(false);
226
- return;
227
- }
228
-
229
- const input: FetchObjectDataInput = isObjectIdDirect
230
- ? { objectId: selectedObjectId }
231
- : { itemId: selectedObjectId, selectedTenant };
232
-
233
- // Initial fetch
234
- fetchObjectData(input, true);
235
-
236
- // Set up polling
237
- pollingRef.current = setInterval(() => {
238
- fetchObjectData(input, false);
239
- }, POLLING_INTERVAL);
240
-
241
- log.info(
242
- "[DappKit] SmartObjectProvider: Started polling for object:",
243
- selectedObjectId,
244
- );
245
-
246
- return () => {
247
- if (pollingRef.current) {
248
- clearInterval(pollingRef.current);
249
- pollingRef.current = null;
250
- log.info("[DappKit] SmartObjectProvider: Stopped polling");
251
- }
252
- lastDataHashRef.current = null;
253
- };
254
- }, [
255
- selectedObjectId,
256
- selectedTenant,
257
- isObjectIdDirect,
258
- isConnected,
259
- fetchObjectData,
260
- ]);
261
-
262
- const handleRefetch = useCallback(async () => {
263
- if (!selectedObjectId) return;
264
- const input: FetchObjectDataInput = isObjectIdDirect
265
- ? { objectId: selectedObjectId }
266
- : { itemId: selectedObjectId, selectedTenant };
267
- await fetchObjectData(input, true);
268
- }, [selectedObjectId, selectedTenant, isObjectIdDirect, fetchObjectData]);
269
-
270
- // Refetch with retries after a mutation (e.g. metadata save)
271
- // so the indexer can catch up.
272
- const handleRefetchWithRetries = useCallback(async () => {
273
- await handleRefetch();
274
- await new Promise<void>((resolve) => {
275
- setTimeout(resolve, 1500);
276
- });
277
- await handleRefetch();
278
- }, [handleRefetch]);
279
-
280
- return (
281
- <SmartObjectContext.Provider
282
- value={{
283
- tenant: selectedTenant,
284
- assembly,
285
- assemblyOwner,
286
- loading,
287
- error,
288
- refetch: handleRefetchWithRetries,
289
- }}
290
- >
291
- {children}
292
- </SmartObjectContext.Provider>
293
- );
294
- };
295
-
296
- export default SmartObjectProvider;
@@ -1,108 +0,0 @@
1
- import { ReactNode, useRef, useEffect, createContext } from "react";
2
- import {
3
- useCurrentAccount,
4
- useWallets,
5
- useDAppKit,
6
- } from "@mysten/dapp-kit-react";
7
- import { createLogger, STORAGE_KEYS } from "../utils";
8
- import { SupportedWallets, VaultContextType } from "../types";
9
-
10
- const log = createLogger();
11
-
12
- /** @category Providers */
13
- export const VaultContext = createContext<VaultContextType>({
14
- currentAccount: null,
15
- walletAddress: undefined,
16
- hasEveVault: false,
17
- isConnected: false,
18
- handleConnect: () => {},
19
- handleDisconnect: () => {},
20
- });
21
-
22
- /**
23
- * VaultProvider component provides a context for managing Sui wallet connections.
24
- * It uses @mysten/dapp-kit-react hooks for wallet management.
25
- */
26
- // Module-level flag to prevent auto-connect from running multiple times
27
- // (persists across component remounts caused by wallet state changes)
28
- let globalAutoConnectAttempted = false;
29
-
30
- /** @category Providers */
31
- const VaultProvider = ({ children }: { children: ReactNode }) => {
32
- // Sui dapp-kit hooks
33
- const currentAccount = useCurrentAccount();
34
- const dAppKit = useDAppKit();
35
- const { connectWallet, disconnectWallet } = dAppKit;
36
- const wallets = useWallets();
37
-
38
- // Find Eve Vault wallet if available
39
- const eveVaultWallet = wallets.find(
40
- (wallet) =>
41
- wallet.name.includes(SupportedWallets.EVE_FRONTIER_CLIENT_WALLET) ||
42
- wallet.name.includes(SupportedWallets.EVE_VAULT),
43
- );
44
-
45
- // Track if auto-connect has been attempted to prevent infinite loops
46
- const hasAttemptedAutoConnect = useRef(false);
47
-
48
- const handleConnect = () => {
49
- const walletToConnect = eveVaultWallet || wallets[0];
50
-
51
- if (!walletToConnect) {
52
- log.warn("No wallet available to connect");
53
- return;
54
- }
55
-
56
- try {
57
- connectWallet({ wallet: walletToConnect });
58
- log.info("[DappKit] Connected to wallet:", walletToConnect.name);
59
- localStorage.setItem(STORAGE_KEYS.CONNECTED, "true");
60
- } catch (error) {
61
- log.error("[DappKit] Failed to connect wallet:", error);
62
- }
63
- };
64
-
65
- const handleDisconnect = () => {
66
- disconnectWallet();
67
- localStorage.removeItem(STORAGE_KEYS.CONNECTED);
68
- log.info("[DappKit] Wallet disconnected");
69
- };
70
-
71
- // Auto-reconnect if user was previously connected (only once)
72
- useEffect(() => {
73
- // Use both local ref AND global flag for maximum protection against re-render loops
74
- if (hasAttemptedAutoConnect.current || globalAutoConnectAttempted) return;
75
-
76
- const isPreviouslyConnected =
77
- localStorage.getItem(STORAGE_KEYS.CONNECTED) === "true";
78
-
79
- if (
80
- typeof window !== "undefined" &&
81
- isPreviouslyConnected &&
82
- eveVaultWallet
83
- ) {
84
- hasAttemptedAutoConnect.current = true;
85
- globalAutoConnectAttempted = true;
86
- handleConnect();
87
- }
88
- }, [eveVaultWallet, handleConnect]);
89
-
90
- const isConnected = !!currentAccount;
91
-
92
- return (
93
- <VaultContext.Provider
94
- value={{
95
- walletAddress: currentAccount?.address,
96
- currentAccount,
97
- hasEveVault: !!eveVaultWallet,
98
- isConnected,
99
- handleConnect,
100
- handleDisconnect,
101
- }}
102
- >
103
- {children}
104
- </VaultContext.Provider>
105
- );
106
- };
107
-
108
- export default VaultProvider;
@@ -1,10 +0,0 @@
1
- export { default as EveFrontierProvider } from "./EveFrontierProvider";
2
- export { default as VaultProvider, VaultContext } from "./VaultProvider";
3
- export {
4
- default as SmartObjectProvider,
5
- SmartObjectContext,
6
- } from "./SmartObjectProvider";
7
- export {
8
- default as NotificationProvider,
9
- NotificationContext,
10
- } from "./NotificationProvider";
package/types/contexts.ts DELETED
@@ -1,67 +0,0 @@
1
- import { WalletAccount } from "@mysten/wallet-standard";
2
- import {
3
- Assemblies,
4
- AssemblyType,
5
- DetailedSmartCharacterResponse,
6
- Severity,
7
- } from "./types";
8
-
9
- /**
10
- * Vault context: account, connection state, and connect/disconnect handlers.
11
- * @category Types
12
- */
13
- export interface VaultContextType {
14
- currentAccount: WalletAccount | null;
15
- walletAddress: string | undefined;
16
- hasEveVault: boolean;
17
- isConnected: boolean;
18
- handleConnect: () => void;
19
- handleDisconnect: () => void;
20
- }
21
-
22
- export enum SupportedWallets {
23
- EVE_VAULT = "Eve Vault",
24
- EVE_FRONTIER_CLIENT_WALLET = "EVE Frontier Client Wallet",
25
- }
26
-
27
- /**
28
- * Smart object context: assembly, owner, loading, error, and refetch.
29
- * @category Types
30
- */
31
- export interface SmartObjectContextType {
32
- tenant: string;
33
- assembly: AssemblyType<Assemblies> | null;
34
- assemblyOwner: DetailedSmartCharacterResponse | null;
35
- loading: boolean;
36
- error: string | null;
37
- refetch: () => Promise<void>;
38
- }
39
-
40
- export interface NotifySuccess {
41
- type: Severity.Success;
42
- txHash?: string;
43
- message?: string;
44
- onSuccess?: () => void;
45
- }
46
-
47
- export interface NotifyOther {
48
- type: Severity.Error | Severity.Warning | Severity.Info;
49
- message?: string;
50
- }
51
-
52
- /** @category Types */
53
- export interface NotificationContextType {
54
- notify: (notification: NotifySuccess | NotifyOther) => void;
55
- notification: NotificationState;
56
- handleClose: () => void;
57
- }
58
-
59
- /** @category Types */
60
- export interface NotificationState {
61
- message: string;
62
- txHash: string;
63
- onSuccess: () => void;
64
- severity: Severity;
65
- handleClose: () => void;
66
- isOpen: boolean;
67
- }
package/types/global.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { dAppKit } from "../config/dapp-kit";
2
-
3
- declare module "@mysten/dapp-kit-react" {
4
- interface Register {
5
- dAppKit: typeof dAppKit;
6
- }
7
- }
package/types/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from "./types";
2
- export * from "./worldApiReturnTypes";
3
- export * from "./sponsoredTransaction";
4
- export * from "./contexts";
@@ -1,70 +0,0 @@
1
- import {
2
- SponsoredTransactionArgs,
3
- SponsoredTransactionOutput,
4
- } from "../wallet";
5
- import { Assemblies } from "./types";
6
-
7
- /**
8
- * Available sponsored transaction actions
9
- *
10
- * @category Types
11
- */
12
- export enum SponsoredTransactionActions {
13
- BRING_ONLINE = "online",
14
- BRING_OFFLINE = "offline",
15
- /** @deprecated Use UPDATE_METADATA instead */
16
- EDIT_UNIT = "edit-unit",
17
- UPDATE_METADATA = "update-metadata",
18
- LINK_SMART_GATE = "link-smart-gate",
19
- UNLINK_SMART_GATE = "unlink-smart-gate",
20
- }
21
-
22
- /** @category Types */
23
- export type SendSponsoredTransactionFn = (
24
- input: SponsoredTransactionArgs,
25
- options?: {
26
- onSuccess?: (data: SponsoredTransactionOutput) => void;
27
- onError?: (error: Error) => void;
28
- },
29
- ) => Promise<SponsoredTransactionOutput>;
30
-
31
- // ============================================================================
32
- // Feature Identifiers
33
- // ============================================================================
34
-
35
- /**
36
- * Feature identifier for sponsored transactions.
37
- * Wallets implementing this feature can request gas sponsorship from
38
- * the EVE Frontier sponsored-transaction backend service.
39
- *
40
- * @category Wallet
41
- */
42
- export const EVEFRONTIER_SPONSORED_TRANSACTION =
43
- "evefrontier:sponsoredTransaction" as const;
44
-
45
- // ============================================================================
46
- // Sponsored Transaction Types
47
- // ============================================================================
48
-
49
- /**
50
- * Map assembly types to API strings
51
- */
52
- export const ASSEMBLY_TYPE_API_STRING: Record<Assemblies, string> = {
53
- [Assemblies.SmartStorageUnit]: "storage-units",
54
- [Assemblies.SmartTurret]: "turrets",
55
- [Assemblies.SmartGate]: "gates",
56
- [Assemblies.NetworkNode]: "network-nodes",
57
- [Assemblies.Manufacturing]: "manufacturing",
58
- [Assemblies.Refinery]: "refineries",
59
- [Assemblies.Assembly]: "assemblies",
60
- } as const;
61
-
62
- /** API slug for assembly type in sponsored transaction payloads (e.g. "storage-units"). */
63
- export type SponsoredTransactionAssemblyType =
64
- (typeof ASSEMBLY_TYPE_API_STRING)[Assemblies];
65
-
66
- export interface SponsoredTransactionMetadata {
67
- name?: string;
68
- description?: string;
69
- url?: string;
70
- }