@evefrontier/dapp-kit 0.1.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 (186) hide show
  1. package/README.md +53 -0
  2. package/config/dapp-kit.ts +20 -0
  3. package/config/index.ts +1 -0
  4. package/docs/api/.nojekyll +1 -0
  5. package/docs/api/assets/hierarchy.js +1 -0
  6. package/docs/api/assets/highlight.css +120 -0
  7. package/docs/api/assets/icons.js +18 -0
  8. package/docs/api/assets/icons.svg +1 -0
  9. package/docs/api/assets/main.js +60 -0
  10. package/docs/api/assets/navigation.js +1 -0
  11. package/docs/api/assets/search.js +1 -0
  12. package/docs/api/assets/style.css +1633 -0
  13. package/docs/api/classes/WalletNoAccountSelectedError.html +3 -0
  14. package/docs/api/classes/WalletNotConnectedError.html +3 -0
  15. package/docs/api/classes/WalletSponsoredTransactionNotSupportedError.html +5 -0
  16. package/docs/api/enums/ActionTypes.html +6 -0
  17. package/docs/api/enums/Assemblies.html +7 -0
  18. package/docs/api/enums/QueryParams.html +3 -0
  19. package/docs/api/enums/Severity.html +5 -0
  20. package/docs/api/enums/SponsoredTransactionActions.html +7 -0
  21. package/docs/api/enums/State.html +6 -0
  22. package/docs/api/enums/TYPEIDS.html +15 -0
  23. package/docs/api/functions/EveFrontierProvider.html +11 -0
  24. package/docs/api/functions/NotificationProvider.html +2 -0
  25. package/docs/api/functions/SmartObjectProvider.html +10 -0
  26. package/docs/api/functions/VaultProvider.html +1 -0
  27. package/docs/api/functions/abbreviateAddress.html +11 -0
  28. package/docs/api/functions/assertAssemblyType.html +9 -0
  29. package/docs/api/functions/clickToCopy.html +1 -0
  30. package/docs/api/functions/executeGraphQLQuery.html +12 -0
  31. package/docs/api/functions/findOwnerByAddress.html +5 -0
  32. package/docs/api/functions/formatDuration.html +8 -0
  33. package/docs/api/functions/formatM3.html +8 -0
  34. package/docs/api/functions/getAssemblyType.html +4 -0
  35. package/docs/api/functions/getAssemblyTypeApiString.html +2 -0
  36. package/docs/api/functions/getAssemblyWithOwner.html +18 -0
  37. package/docs/api/functions/getCharacterOwnerCapType.html +3 -0
  38. package/docs/api/functions/getCommonItems.html +1 -0
  39. package/docs/api/functions/getDappUrl.html +7 -0
  40. package/docs/api/functions/getDatahubGameInfo.html +13 -0
  41. package/docs/api/functions/getEnv.html +1 -0
  42. package/docs/api/functions/getEveWorldPackageId.html +4 -0
  43. package/docs/api/functions/getObjectByAddress.html +9 -0
  44. package/docs/api/functions/getObjectId.html +4 -0
  45. package/docs/api/functions/getObjectOwnerAndOwnedObjectsByType.html +10 -0
  46. package/docs/api/functions/getObjectRegistryType.html +3 -0
  47. package/docs/api/functions/getObjectWithDynamicFields.html +10 -0
  48. package/docs/api/functions/getObjectWithJson.html +9 -0
  49. package/docs/api/functions/getObjectsByType.html +12 -0
  50. package/docs/api/functions/getOwnedObjectsByPackage.html +10 -0
  51. package/docs/api/functions/getOwnedObjectsByType.html +10 -0
  52. package/docs/api/functions/getRegistryAddress.html +3 -0
  53. package/docs/api/functions/getSingletonObjectByType.html +9 -0
  54. package/docs/api/functions/getSponsoredTransactionFeature.html +11 -0
  55. package/docs/api/functions/getSuiGraphqlEndpoint.html +4 -0
  56. package/docs/api/functions/getTxUrl.html +8 -0
  57. package/docs/api/functions/getVolumeM3.html +5 -0
  58. package/docs/api/functions/hasSponsoredTransactionFeature.html +3 -0
  59. package/docs/api/functions/isOwner.html +10 -0
  60. package/docs/api/functions/parseErrorFromMessage.html +1 -0
  61. package/docs/api/functions/parseStatus.html +2 -0
  62. package/docs/api/functions/parseURL.html +1 -0
  63. package/docs/api/functions/removeTrailingZeros.html +1 -0
  64. package/docs/api/functions/transformToAssembly.html +5 -0
  65. package/docs/api/functions/transformToCharacter.html +2 -0
  66. package/docs/api/functions/useConnection.html +21 -0
  67. package/docs/api/functions/useNotification.html +28 -0
  68. package/docs/api/functions/useSmartObject.html +26 -0
  69. package/docs/api/functions/useSponsoredTransaction.html +50 -0
  70. package/docs/api/functions/walletSupportsSponsoredTransaction.html +13 -0
  71. package/docs/api/hierarchy.html +1 -0
  72. package/docs/api/index.html +26 -0
  73. package/docs/api/interfaces/AddressOwner.html +2 -0
  74. package/docs/api/interfaces/AddressOwnerWithJson.html +2 -0
  75. package/docs/api/interfaces/AssemblyProperties.html +14 -0
  76. package/docs/api/interfaces/CharacterInfo.html +8 -0
  77. package/docs/api/interfaces/DatahubGameInfo.html +30 -0
  78. package/docs/api/interfaces/DetailedAssemblyResponse.html +14 -0
  79. package/docs/api/interfaces/DetailedSmartCharacterResponse.html +7 -0
  80. package/docs/api/interfaces/DynamicFieldNode.html +3 -0
  81. package/docs/api/interfaces/EphemeralInventory.html +6 -0
  82. package/docs/api/interfaces/EveFrontierSponsoredTransactionFeature.html +7 -0
  83. package/docs/api/interfaces/GameTypeResponse.html +13 -0
  84. package/docs/api/interfaces/GateModule.html +5 -0
  85. package/docs/api/interfaces/GetObjectByAddressResponse.html +2 -0
  86. package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsResponse.html +2 -0
  87. package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsWithJsonResponse.html +2 -0
  88. package/docs/api/interfaces/GetObjectResponse.html +2 -0
  89. package/docs/api/interfaces/GetObjectWithJsonResponse.html +2 -0
  90. package/docs/api/interfaces/GetObjectsByTypeResponse.html +2 -0
  91. package/docs/api/interfaces/GetOwnedObjectsByPackageResponse.html +2 -0
  92. package/docs/api/interfaces/GetOwnedObjectsByTypeResponse.html +2 -0
  93. package/docs/api/interfaces/GetSingletonObjectByTypeResponse.html +2 -0
  94. package/docs/api/interfaces/GraphQLResponse.html +3 -0
  95. package/docs/api/interfaces/InventoryItem.html +8 -0
  96. package/docs/api/interfaces/ManufacturingModule.html +2 -0
  97. package/docs/api/interfaces/MoveObjectContents.html +4 -0
  98. package/docs/api/interfaces/MoveObjectData.html +3 -0
  99. package/docs/api/interfaces/NetworkNodeModule.html +7 -0
  100. package/docs/api/interfaces/NotificationContextType.html +4 -0
  101. package/docs/api/interfaces/NotificationState.html +6 -0
  102. package/docs/api/interfaces/Notify.html +6 -0
  103. package/docs/api/interfaces/ObjectWithContentsNode.html +4 -0
  104. package/docs/api/interfaces/OwnedObjectAddressNode.html +2 -0
  105. package/docs/api/interfaces/OwnedObjectFullNode.html +4 -0
  106. package/docs/api/interfaces/OwnedObjectNode.html +3 -0
  107. package/docs/api/interfaces/OwnedObjectNodeWithJson.html +4 -0
  108. package/docs/api/interfaces/OwnerCapData.html +5 -0
  109. package/docs/api/interfaces/PageInfo.html +3 -0
  110. package/docs/api/interfaces/RawCharacterData.html +8 -0
  111. package/docs/api/interfaces/RawSuiObjectData.html +17 -0
  112. package/docs/api/interfaces/RefineryModule.html +2 -0
  113. package/docs/api/interfaces/SmartAssemblyResponse.html +11 -0
  114. package/docs/api/interfaces/SmartObjectContextType.html +8 -0
  115. package/docs/api/interfaces/SponsoredTransactionInput.html +15 -0
  116. package/docs/api/interfaces/SponsoredTransactionOutput.html +8 -0
  117. package/docs/api/interfaces/StorageModule.html +4 -0
  118. package/docs/api/interfaces/SuiObjectResponse.html +5 -0
  119. package/docs/api/interfaces/TransformOptions.html +6 -0
  120. package/docs/api/interfaces/TurretModule.html +2 -0
  121. package/docs/api/interfaces/VaultContextType.html +7 -0
  122. package/docs/api/modules.html +1 -0
  123. package/docs/api/types/AssemblyType.html +1 -0
  124. package/docs/api/types/ErrorType.html +5 -0
  125. package/docs/api/types/SendSponsoredTransactionFn.html +1 -0
  126. package/docs/api/types/SponsoredTransactionArgs.html +2 -0
  127. package/docs/api/types/SponsoredTransactionAssemblyType.html +2 -0
  128. package/docs/api/types/SponsoredTransactionMethod.html +2 -0
  129. package/docs/api/types/UseSponsoredTransactionArgs.html +3 -0
  130. package/docs/api/types/UseSponsoredTransactionError.html +2 -0
  131. package/docs/api/types/UseSponsoredTransactionMutationOptions.html +2 -0
  132. package/docs/api/variables/ERRORS.html +1 -0
  133. package/docs/api/variables/ERROR_MESSAGES.html +1 -0
  134. package/docs/api/variables/EVEFRONTIER_SPONSORED_TRANSACTION.html +4 -0
  135. package/docs/api/variables/EXCLUDED_TYPEIDS.html +1 -0
  136. package/docs/api/variables/GET_OBJECTS_BY_TYPE.html +3 -0
  137. package/docs/api/variables/GET_OBJECT_BY_ADDRESS.html +3 -0
  138. package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE.html +4 -0
  139. package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON.html +3 -0
  140. package/docs/api/variables/GET_OBJECT_WITH_DYNAMIC_FIELDS.html +4 -0
  141. package/docs/api/variables/GET_OBJECT_WITH_JSON.html +3 -0
  142. package/docs/api/variables/GET_OWNED_OBJECTS_BY_PACKAGE.html +3 -0
  143. package/docs/api/variables/GET_OWNED_OBJECTS_BY_TYPE.html +3 -0
  144. package/docs/api/variables/GET_SINGLETON_OBJECT_BY_TYPE.html +3 -0
  145. package/docs/api/variables/NotificationContext.html +1 -0
  146. package/docs/api/variables/ONE_M3.html +2 -0
  147. package/docs/api/variables/POLLING_INTERVAL.html +2 -0
  148. package/docs/api/variables/STORAGE_KEYS.html +2 -0
  149. package/docs/api/variables/SmartObjectContext.html +1 -0
  150. package/docs/api/variables/VaultContext.html +1 -0
  151. package/docs/api/variables/dAppKit.html +2 -0
  152. package/graphql/client.ts +480 -0
  153. package/graphql/index.ts +73 -0
  154. package/graphql/queries.ts +371 -0
  155. package/graphql/types.ts +443 -0
  156. package/hooks/index.ts +14 -0
  157. package/hooks/useConnection.ts +58 -0
  158. package/hooks/useNotification.ts +80 -0
  159. package/hooks/useSmartObject.ts +78 -0
  160. package/hooks/useSponsoredTransaction.ts +323 -0
  161. package/index.ts +162 -0
  162. package/package.json +48 -0
  163. package/providers/EveFrontierProvider.tsx +41 -0
  164. package/providers/NotificationProvider.tsx +115 -0
  165. package/providers/SmartObjectProvider.tsx +282 -0
  166. package/providers/VaultProvider.tsx +114 -0
  167. package/providers/index.ts +17 -0
  168. package/tsconfig.json +22 -0
  169. package/typedoc.json +38 -0
  170. package/types/global.d.ts +7 -0
  171. package/types/index.ts +4 -0
  172. package/types/sponsoredTransaction.ts +26 -0
  173. package/types/types.ts +113 -0
  174. package/types/worldApiReturnTypes.ts +166 -0
  175. package/utils/__tests__/mapping.test.ts +441 -0
  176. package/utils/constants.ts +96 -0
  177. package/utils/datahub.ts +76 -0
  178. package/utils/errors.ts +171 -0
  179. package/utils/index.ts +38 -0
  180. package/utils/mapping.ts +115 -0
  181. package/utils/transforms.ts +258 -0
  182. package/utils/utils.ts +270 -0
  183. package/vite-env.d.ts +16 -0
  184. package/wallet/features.ts +165 -0
  185. package/wallet/index.ts +28 -0
  186. package/wallet/utils.ts +117 -0
@@ -0,0 +1,323 @@
1
+ import { getWallets } from "@mysten/wallet-standard";
2
+ import {
3
+ useCurrentAccount,
4
+ useWallets,
5
+ useDAppKit,
6
+ } from "@mysten/dapp-kit-react";
7
+ import {
8
+ useMutation,
9
+ UseMutationResult,
10
+ type UseMutationOptions,
11
+ } from "@tanstack/react-query";
12
+ import {
13
+ getAssemblyTypeApiString,
14
+ supportsSponsoredTransaction,
15
+ getSponsoredTransactionMethod,
16
+ type SponsoredTransactionInput,
17
+ type SponsoredTransactionOutput,
18
+ SponsoredTransactionArgs,
19
+ } from "../wallet";
20
+ import { SponsoredTransactionActions } from "../types";
21
+
22
+ /** Wallet-like shape from dApp Kit (UiWallet or connection store). */
23
+ type ResolvableWallet = {
24
+ features: unknown;
25
+ name?: string;
26
+ version?: string;
27
+ [key: string]: unknown;
28
+ };
29
+
30
+ // ============================================================================
31
+ // Error Types
32
+ // ============================================================================
33
+
34
+ /**
35
+ * Error thrown when the connected wallet doesn't support EVE Frontier sponsored transactions.
36
+ *
37
+ * This occurs when the wallet doesn't implement the `evefrontier:sponsoredTransaction` feature.
38
+ * Currently, only EVE Vault wallet supports this feature.
39
+ *
40
+ * @category Errors
41
+ */
42
+ export class WalletSponsoredTransactionNotSupportedError extends Error {
43
+ constructor(walletName?: string) {
44
+ super(
45
+ walletName
46
+ ? `Wallet "${walletName}" does not support sponsored transactions`
47
+ : "Connected wallet does not support sponsored transactions",
48
+ );
49
+ this.name = "WalletSponsoredTransactionNotSupportedError";
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Error thrown when attempting a sponsored transaction without a connected wallet.
55
+ *
56
+ * @category Errors
57
+ */
58
+ export class WalletNotConnectedError extends Error {
59
+ constructor() {
60
+ super("No wallet connected");
61
+ this.name = "WalletNotConnectedError";
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Error thrown when no account is selected in the connected wallet.
67
+ *
68
+ * @category Errors
69
+ */
70
+ export class WalletNoAccountSelectedError extends Error {
71
+ constructor() {
72
+ super("No account selected in wallet");
73
+ this.name = "WalletNoAccountSelectedError";
74
+ }
75
+ }
76
+
77
+ // ============================================================================
78
+ // Hook Types
79
+ // ============================================================================
80
+
81
+ /**
82
+ * Error union type for {@link useSponsoredTransaction} mutation failures.
83
+ *
84
+ * @category Hooks
85
+ */
86
+ export type UseSponsoredTransactionError =
87
+ | WalletSponsoredTransactionNotSupportedError
88
+ | WalletNotConnectedError
89
+ | WalletNoAccountSelectedError
90
+ | Error;
91
+
92
+ /**
93
+ * Arguments passed to {@link useSponsoredTransaction} mutate/mutateAsync.
94
+ * With assembly object (id and type derived).
95
+ *
96
+ * @category Hooks
97
+ */
98
+ export type UseSponsoredTransactionArgs = SponsoredTransactionArgs;
99
+
100
+ /**
101
+ * React Query mutation options for {@link useSponsoredTransaction}.
102
+ *
103
+ * @category Hooks
104
+ */
105
+ export type UseSponsoredTransactionMutationOptions = Omit<
106
+ UseMutationOptions<
107
+ SponsoredTransactionOutput,
108
+ UseSponsoredTransactionError,
109
+ UseSponsoredTransactionArgs
110
+ >,
111
+ "mutationFn"
112
+ >;
113
+
114
+ // ============================================================================
115
+ // Hook Implementation
116
+ // ============================================================================
117
+
118
+ /**
119
+ * Hook for executing gas-sponsored transactions via EVE Frontier.
120
+ *
121
+ * This mutation hook enables dApps to send transactions where gas fees are paid
122
+ * by the EVE Frontier backend service, eliminating the need for users to have SUI
123
+ * tokens for gas. The wallet must support the `evefrontier:sponsoredTransaction` feature
124
+ * (currently only EVE Vault).
125
+ *
126
+ * The hook automatically uses the currently connected wallet and account (unless overridden)
127
+ * and handles wallet feature detection and validation.
128
+ *
129
+ * **Input** (passed to `mutate` / `mutateAsync`):
130
+ * - `txAction` (required) – The sponsored action to run (e.g. BRING_ONLINE, BRING_OFFLINE).
131
+ * - `chain` (required) – Sui chain id, e.g. `"sui:testnet"` or `"sui:mainnet"`.
132
+ * - `ownerId` (required) – Assembly owner ID.
133
+ * - `assembly` (optional) – Assembly ID; omit to use context-specific default.
134
+ * - `destination` (optional) – Destination for gate linking (LINK_SMART_GATE / UNLINK_SMART_GATE).
135
+ * - `account` (optional) – Signer account override; defaults to current connected account.
136
+ *
137
+ * **Output** (on success, in `data` or resolved from `mutateAsync`):
138
+ * - `digest` (required) – Transaction digest.
139
+ * - `effects` (optional) – Transaction effects, BCS encoded.
140
+ * - `rawEffects` (optional) – Raw effects bytes.
141
+ *
142
+ * @category Hooks
143
+ * @param options - React Query mutation options (optional)
144
+ * @returns React Query mutation result with:
145
+ * - `mutate(args, options?)` - Trigger transaction (fire-and-forget)
146
+ * - `mutateAsync(args)` - Trigger transaction (returns Promise<SponsoredTransactionOutput>)
147
+ * - `isPending` - True while the transaction is in progress
148
+ * - `isError` - True if the last mutation failed
149
+ * - `error` - Error from the last failed mutation
150
+ * - `data` - Last successful result (`SponsoredTransactionOutput`)
151
+ *
152
+ * @throws {WalletNotConnectedError} If no wallet is connected
153
+ * @throws {WalletNoAccountSelectedError} If no account is selected
154
+ * @throws {WalletSponsoredTransactionNotSupportedError} If wallet doesn't support sponsored transactions
155
+ *
156
+ * @example Basic bring online transaction
157
+ * ```tsx
158
+ * import { useSponsoredTransaction, SponsoredTransactionActions } from "@evefrontier/dapp-kit";
159
+ *
160
+ * const BringOnlineButton = () => {
161
+ * const { mutateAsync: sendTx, isPending } = useSponsoredTransaction();
162
+ *
163
+ * const handleBringOnline = async () => {
164
+ * try {
165
+ * const result = await sendTx({
166
+ * txAction: SponsoredTransactionActions.BRING_ONLINE,
167
+ * assembly: "0x123...",
168
+ * chain: "sui:testnet",
169
+ * ownerId: "0x...",
170
+ * });
171
+ * console.log("Transaction digest:", result.digest);
172
+ * } catch (error) {
173
+ * console.error("Transaction failed:", error);
174
+ * }
175
+ * };
176
+ *
177
+ * return (
178
+ * <button onClick={handleBringOnline} disabled={isPending}>
179
+ * {isPending ? "Processing..." : "Bring Online"}
180
+ * </button>
181
+ * );
182
+ * };
183
+ * ```
184
+ *
185
+ * @example With callbacks
186
+ * ```tsx
187
+ * const { mutate: sendTx } = useSponsoredTransaction();
188
+ *
189
+ * sendTx(
190
+ * {
191
+ * txAction: SponsoredTransactionActions.BRING_ONLINE,
192
+ * assembly: "0x123...",
193
+ * ownerId: "0x...",
194
+ * chain: "sui:testnet",
195
+ * },
196
+ * {
197
+ * onSuccess: (result) => {
198
+ * notify({ type: Severity.Success, txHash: result.digest });
199
+ * },
200
+ * onError: (error) => {
201
+ * notify({ type: Severity.Error, message: error.message });
202
+ * },
203
+ * }
204
+ * );
205
+ * ```
206
+ *
207
+ * @example With assembly
208
+ * ```tsx
209
+ * const result = await sendTx({
210
+ * txAction: SponsoredTransactionActions.BRING_ONLINE,
211
+ * chain: "sui:testnet",
212
+ * ownerId: "0x...",
213
+ * assembly: "0x123...",
214
+ * });
215
+ * ```
216
+ *
217
+ * @see {@link SponsoredTransactionActions} for available transaction actions
218
+ * @see {@link SponsoredTransactionInput} for full input type
219
+ * @see {@link SponsoredTransactionOutput} for full output type
220
+ */
221
+ export function useSponsoredTransaction({
222
+ mutationKey,
223
+ ...mutationOptions
224
+ }: UseSponsoredTransactionMutationOptions = {}): UseMutationResult<
225
+ SponsoredTransactionOutput,
226
+ UseSponsoredTransactionError,
227
+ UseSponsoredTransactionArgs
228
+ > {
229
+ const dAppKit = useDAppKit();
230
+ const wallets = useWallets();
231
+ const currentAccount = useCurrentAccount();
232
+
233
+ return useMutation({
234
+ mutationKey: [
235
+ "evefrontier",
236
+ "sponsored-transaction",
237
+ ...(mutationKey ?? []),
238
+ ],
239
+ mutationFn: async (args): Promise<SponsoredTransactionOutput> => {
240
+ // Resolve wallet at call time
241
+ const connection =
242
+ typeof dAppKit.stores?.$connection?.get === "function"
243
+ ? (dAppKit.stores.$connection.get() as { wallet?: ResolvableWallet })
244
+ : null;
245
+ const walletFromStore = connection?.wallet;
246
+ const wallet = walletFromStore ?? null;
247
+
248
+ if (!wallet) {
249
+ throw new WalletNotConnectedError();
250
+ }
251
+
252
+ const signerAccount = args.account ?? currentAccount?.address;
253
+ if (!signerAccount) {
254
+ throw new WalletNoAccountSelectedError();
255
+ }
256
+
257
+ if (!supportsSponsoredTransaction(wallet.features)) {
258
+ throw new WalletSponsoredTransactionNotSupportedError(
259
+ (wallet as ResolvableWallet).name,
260
+ );
261
+ }
262
+
263
+ // Resolve method: prefer raw Wallet Standard wallets (object-shaped features), then store/current/list
264
+ const walletName = (wallet as ResolvableWallet).name;
265
+ const walletVersion = (wallet as ResolvableWallet).version;
266
+ const rawWallets =
267
+ typeof getWallets === "function" ? getWallets().get() : [];
268
+ const rawWallet = rawWallets.find(
269
+ (w) =>
270
+ w.name === walletName &&
271
+ (walletVersion == null || w.version === walletVersion),
272
+ );
273
+ let signSponsoredTransaction =
274
+ (rawWallet != null
275
+ ? getSponsoredTransactionMethod(
276
+ rawWallet as Parameters<typeof getSponsoredTransactionMethod>[0],
277
+ )
278
+ : undefined) ??
279
+ (walletFromStore != null
280
+ ? getSponsoredTransactionMethod(
281
+ walletFromStore as Parameters<
282
+ typeof getSponsoredTransactionMethod
283
+ >[0],
284
+ )
285
+ : undefined) ??
286
+ getSponsoredTransactionMethod(
287
+ wallet as Parameters<typeof getSponsoredTransactionMethod>[0],
288
+ );
289
+ if (!signSponsoredTransaction) {
290
+ const walletFromList = wallets.find(
291
+ (w) =>
292
+ w.name === (wallet as ResolvableWallet).name &&
293
+ ((wallet as ResolvableWallet).version == null ||
294
+ w.version === (wallet as ResolvableWallet).version),
295
+ );
296
+ signSponsoredTransaction =
297
+ walletFromList != null
298
+ ? getSponsoredTransactionMethod(
299
+ walletFromList as Parameters<
300
+ typeof getSponsoredTransactionMethod
301
+ >[0],
302
+ )
303
+ : undefined;
304
+ }
305
+ if (!signSponsoredTransaction) {
306
+ throw new WalletSponsoredTransactionNotSupportedError(
307
+ (wallet as ResolvableWallet).name,
308
+ );
309
+ }
310
+
311
+ const payload: SponsoredTransactionInput = {
312
+ txAction: args.txAction,
313
+ assembly: args.assembly.item_id,
314
+ assemblyType: getAssemblyTypeApiString(args.assembly.type),
315
+ chain: args.chain,
316
+ ...(args.destination != null ? { destination: args.destination } : {}),
317
+ };
318
+
319
+ return await signSponsoredTransaction(payload);
320
+ },
321
+ ...mutationOptions,
322
+ });
323
+ }
package/index.ts ADDED
@@ -0,0 +1,162 @@
1
+ // Main provider
2
+ export { EveFrontierProvider } from "./providers";
3
+
4
+ // Hooks
5
+ export {
6
+ useConnection,
7
+ useSmartObject,
8
+ useNotification,
9
+ useSponsoredTransaction,
10
+ } from "./hooks";
11
+
12
+ // Hook error types and sponsored transaction types
13
+ export {
14
+ WalletSponsoredTransactionNotSupportedError,
15
+ WalletNotConnectedError,
16
+ WalletNoAccountSelectedError,
17
+ } from "./hooks";
18
+ export type {
19
+ UseSponsoredTransactionError,
20
+ UseSponsoredTransactionArgs,
21
+ UseSponsoredTransactionMutationOptions,
22
+ } from "./hooks";
23
+
24
+ // Providers (for advanced usage)
25
+ export {
26
+ VaultProvider,
27
+ VaultContext,
28
+ SmartObjectProvider,
29
+ SmartObjectContext,
30
+ NotificationProvider,
31
+ NotificationContext,
32
+ } from "./providers";
33
+
34
+ // Types from providers
35
+ export type {
36
+ VaultContextType,
37
+ SmartObjectContextType,
38
+ NotificationContextType,
39
+ NotificationState,
40
+ } from "./providers";
41
+
42
+ // =========================================
43
+ // Types (re-exported from ./types)
44
+ // =========================================
45
+ export * from "./types";
46
+
47
+ // =========================================
48
+ // Utils (re-exported from ./utils)
49
+ // =========================================
50
+ export * from "./utils";
51
+
52
+ // =========================================
53
+ // GraphQL - Query execution & helper functions
54
+ // =========================================
55
+ export {
56
+ executeGraphQLQuery,
57
+ getObjectByAddress,
58
+ getObjectWithDynamicFields,
59
+ getObjectWithJson,
60
+ getObjectOwnerAndOwnedObjectsByType,
61
+ getObjectAndCharacterOwner,
62
+ getOwnedObjectsByType,
63
+ getOwnedObjectsByPackage,
64
+ getSingletonObjectByType,
65
+ getObjectsByType,
66
+ // Character/owner resolution
67
+ getAssemblyWithOwner,
68
+ } from "./graphql";
69
+
70
+ // GraphQL - Query strings
71
+ export {
72
+ // Core object queries
73
+ GET_OBJECT_BY_ADDRESS,
74
+ GET_OBJECT_WITH_DYNAMIC_FIELDS,
75
+ GET_OBJECT_WITH_JSON,
76
+ // Owner & ownership queries
77
+ GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE,
78
+ GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON,
79
+ GET_OWNED_OBJECTS_BY_TYPE,
80
+ GET_OWNED_OBJECTS_BY_PACKAGE,
81
+ // Singleton & type-based queries
82
+ GET_SINGLETON_OBJECT_BY_TYPE,
83
+ GET_OBJECTS_BY_TYPE,
84
+ } from "./graphql";
85
+
86
+ // GraphQL - Types
87
+ export type {
88
+ // Base types
89
+ GraphQLResponse,
90
+ PageInfo,
91
+ // Move object types
92
+ MoveObjectContents,
93
+ DynamicFieldNode,
94
+ MoveObjectData,
95
+ // Object response types
96
+ SuiObjectResponse,
97
+ GetObjectResponse,
98
+ // GetObjectByAddress types
99
+ GetObjectByAddressResponse,
100
+ // GetObjectWithJson types
101
+ GetObjectWithJsonResponse,
102
+ // Owner & owned objects types
103
+ OwnedObjectNode,
104
+ AddressOwner,
105
+ GetObjectOwnerAndOwnedObjectsResponse,
106
+ // Owner & owned objects with JSON types
107
+ OwnedObjectNodeWithJson,
108
+ AddressOwnerWithJson,
109
+ GetObjectOwnerAndOwnedObjectsWithJsonResponse,
110
+ // GetOwnedObjectsByType types
111
+ OwnedObjectAddressNode,
112
+ GetOwnedObjectsByTypeResponse,
113
+ // GetOwnedObjectsByPackage types
114
+ OwnedObjectFullNode,
115
+ GetOwnedObjectsByPackageResponse,
116
+ // Singleton & type-based types
117
+ GetSingletonObjectByTypeResponse,
118
+ ObjectWithContentsNode,
119
+ GetObjectsByTypeResponse,
120
+ // EVE Frontier specific types
121
+ RawSuiObjectData,
122
+ OwnerCapData,
123
+ RawCharacterData,
124
+ CharacterInfo,
125
+ } from "./graphql";
126
+
127
+ // =========================================
128
+ // Config
129
+ // =========================================
130
+ export { dAppKit } from "./config/dapp-kit";
131
+
132
+ // =========================================
133
+ // Constants & Configuration
134
+ // =========================================
135
+ export {
136
+ getSuiGraphqlEndpoint,
137
+ getEveWorldPackageId,
138
+ getCharacterOwnerCapType,
139
+ getObjectRegistryType,
140
+ POLLING_INTERVAL,
141
+ STORAGE_KEYS,
142
+ } from "./utils/constants";
143
+
144
+ // =========================================
145
+ // Wallet Standard Extensions
146
+ // =========================================
147
+ export {
148
+ EVEFRONTIER_SPONSORED_TRANSACTION,
149
+ getAssemblyTypeApiString,
150
+ hasSponsoredTransactionFeature,
151
+ walletSupportsSponsoredTransaction,
152
+ getSponsoredTransactionFeature,
153
+ } from "./wallet";
154
+
155
+ export type {
156
+ EveFrontierSponsoredTransactionFeature,
157
+ SponsoredTransactionArgs,
158
+ SponsoredTransactionAssemblyType,
159
+ SponsoredTransactionInput,
160
+ SponsoredTransactionOutput,
161
+ SponsoredTransactionMethod,
162
+ } from "./wallet";
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@evefrontier/dapp-kit",
3
+ "version": "0.1.0",
4
+ "description": "React SDK for EVE Frontier dApps on Sui",
5
+ "main": "index.ts",
6
+ "author": "",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": "./index.ts",
11
+ "./types": "./types/index.ts",
12
+ "./utils": "./utils/index.ts",
13
+ "./graphql": "./graphql/index.ts",
14
+ "./providers": "./providers/index.ts",
15
+ "./hooks": "./hooks/index.ts",
16
+ "./config": "./config/index.ts"
17
+ },
18
+ "dependencies": {
19
+ "@mysten/dapp-kit-core": "^1.0.4",
20
+ "@mysten/dapp-kit-react": "^1.0.2",
21
+ "@mysten/sui": "^2.4.0",
22
+ "@mysten/wallet-standard": "^0.19.9",
23
+ "@tanstack/react-query": "^5.90.16",
24
+ "react": "^19.2.4"
25
+ },
26
+ "devDependencies": {
27
+ "@types/react": "^19.2.14",
28
+ "@vitejs/plugin-react-swc": "3.4.0",
29
+ "typedoc": "^0.28.17",
30
+ "typedoc-plugin-markdown": "^4.4.0",
31
+ "typescript": "^5.5.3",
32
+ "vite": "^5.4.6",
33
+ "vite-plugin-svgr": "^3.3.0",
34
+ "vitest": "^4.0.14"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc --noEmit",
38
+ "ts:clean": "tsc --build --clean",
39
+ "docs": "typedoc",
40
+ "docs:md": "typedoc --plugin typedoc-plugin-markdown --out docs/markdown",
41
+ "docs:serve": "typedoc && npx serve docs/api",
42
+ "lint": "prettier . --check && eslint --report-unused-disable-directives --max-warnings 0",
43
+ "lint:fix": "prettier . --write && eslint --fix --report-unused-disable-directives --max-warnings 0",
44
+ "test": "vitest",
45
+ "test:ui": "vitest --ui",
46
+ "test:run": "vitest run"
47
+ }
48
+ }
@@ -0,0 +1,41 @@
1
+ import { ReactNode } from "react";
2
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3
+ import { DAppKitProvider } from "@mysten/dapp-kit-react";
4
+ import { dAppKit } from "../config/dapp-kit";
5
+
6
+ import NotificationProvider from "./NotificationProvider";
7
+ import SmartObjectProvider from "./SmartObjectProvider";
8
+ import VaultProvider from "./VaultProvider";
9
+ /**
10
+ * EveFrontierProvider wraps the application with all necessary providers
11
+ * for the EVE Frontier dApp kit.
12
+ *
13
+ * Provider hierarchy:
14
+ * 1. QueryClientProvider - React Query for async state management
15
+ * 2. DAppKitProvider - Sui blockchain client
16
+ * 3. VaultProvider - Eve-specific wallet configuration (from @evefrontier/dapp-kit)
17
+ * 4. SmartObjectProvider - Smart object data via GraphQL
18
+ * 5. NotificationProvider - User notifications
19
+ * @category Providers
20
+ */
21
+ const EveFrontierProvider = ({
22
+ children,
23
+ queryClient,
24
+ }: {
25
+ children: ReactNode;
26
+ queryClient: QueryClient;
27
+ }) => {
28
+ return (
29
+ <QueryClientProvider client={queryClient}>
30
+ <DAppKitProvider dAppKit={dAppKit}>
31
+ <VaultProvider>
32
+ <SmartObjectProvider>
33
+ <NotificationProvider>{children}</NotificationProvider>
34
+ </SmartObjectProvider>
35
+ </VaultProvider>
36
+ </DAppKitProvider>
37
+ </QueryClientProvider>
38
+ );
39
+ };
40
+
41
+ export default EveFrontierProvider;
@@ -0,0 +1,115 @@
1
+ import { ReactNode, createContext, useCallback, useState } from "react";
2
+
3
+ import { Severity } from "../types";
4
+
5
+ /** @category Types */
6
+ export interface NotificationState {
7
+ message: string;
8
+ txHash: string;
9
+ severity: Severity;
10
+ handleClose: () => void;
11
+ isOpen: boolean;
12
+ }
13
+
14
+ /** @category Types */
15
+ export interface NotificationContextType {
16
+ notify: (notification: {
17
+ type: Severity;
18
+ txHash?: string;
19
+ message?: string;
20
+ }) => void;
21
+ notification: NotificationState;
22
+ handleClose: () => void;
23
+ }
24
+
25
+ /** @category Providers */
26
+ export const NotificationContext = createContext<NotificationContextType>({
27
+ notify: () => {},
28
+ notification: {
29
+ message: "",
30
+ txHash: "",
31
+ severity: Severity.Success,
32
+ handleClose: () => {},
33
+ isOpen: false,
34
+ },
35
+ handleClose: () => {},
36
+ });
37
+
38
+ /**
39
+ * NotificationProvider manages notifications for transactions and messages.
40
+ *
41
+ * @category Providers
42
+ */
43
+ const NotificationProvider = ({ children }: { children: ReactNode }) => {
44
+ const [isOpen, setIsOpen] = useState<boolean>(false);
45
+ const [message, setMessage] = useState<string>("");
46
+ const [severity, setSeverity] = useState<Severity>(Severity.Info);
47
+ const [txHash, setTxHash] = useState<string>("");
48
+
49
+ const handleClose = useCallback(() => {
50
+ setIsOpen(false);
51
+ }, []);
52
+
53
+ const notify = useCallback(
54
+ ({
55
+ type,
56
+ message,
57
+ txHash,
58
+ }: {
59
+ type: Severity;
60
+ message?: string;
61
+ txHash?: string;
62
+ }) => {
63
+ setSeverity(type);
64
+ setIsOpen(true);
65
+
66
+ // If success with txHash, show success message with transaction hash
67
+ if (type === Severity.Success && txHash) {
68
+ setMessage(
69
+ `Transaction was successful. ${message ?? ""} Transaction hash: ${txHash}`,
70
+ );
71
+ setTxHash(txHash);
72
+ return;
73
+ }
74
+
75
+ // Otherwise, show the passed message or a default based on severity
76
+ if (message) {
77
+ setMessage(message);
78
+ } else {
79
+ switch (type) {
80
+ case Severity.Success:
81
+ setMessage("Operation completed successfully.");
82
+ break;
83
+ case Severity.Error:
84
+ setMessage("An error occurred.");
85
+ break;
86
+ case Severity.Warning:
87
+ setMessage("Warning.");
88
+ break;
89
+ case Severity.Info:
90
+ default:
91
+ setMessage("Processing...");
92
+ break;
93
+ }
94
+ }
95
+ setTxHash(txHash ?? "");
96
+ },
97
+ [],
98
+ );
99
+
100
+ const notification: NotificationState = {
101
+ message,
102
+ txHash,
103
+ severity,
104
+ handleClose,
105
+ isOpen,
106
+ };
107
+
108
+ return (
109
+ <NotificationContext.Provider value={{ notify, handleClose, notification }}>
110
+ {children}
111
+ </NotificationContext.Provider>
112
+ );
113
+ };
114
+
115
+ export default NotificationProvider;