@evefrontier/dapp-kit 0.1.0 → 0.1.2
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.
- package/CHANGELOG.md +13 -0
- package/README.md +2 -2
- package/docs/api/assets/hierarchy.js +1 -1
- package/docs/api/assets/navigation.js +1 -1
- package/docs/api/assets/search.js +1 -1
- package/docs/api/classes/WalletNoAccountSelectedError.html +3 -3
- package/docs/api/classes/WalletNotConnectedError.html +3 -3
- package/docs/api/classes/WalletSponsoredTransactionNotSupportedError.html +3 -3
- package/docs/api/enums/ActionTypes.html +2 -2
- package/docs/api/enums/Assemblies.html +2 -2
- package/docs/api/enums/QueryParams.html +2 -2
- package/docs/api/enums/Severity.html +2 -2
- package/docs/api/enums/SponsoredTransactionActions.html +3 -3
- package/docs/api/enums/State.html +2 -2
- package/docs/api/enums/SupportedWallets.html +3 -0
- package/docs/api/enums/TYPEIDS.html +3 -3
- package/docs/api/functions/EveFrontierProvider.html +2 -2
- package/docs/api/functions/NotificationProvider.html +2 -2
- package/docs/api/functions/SmartObjectProvider.html +2 -2
- package/docs/api/functions/VaultProvider.html +1 -1
- package/docs/api/functions/abbreviateAddress.html +2 -2
- package/docs/api/functions/assertAssemblyType.html +2 -2
- package/docs/api/functions/clickToCopy.html +1 -1
- package/docs/api/functions/executeGraphQLQuery.html +2 -2
- package/docs/api/functions/findOwnerByAddress.html +2 -2
- package/docs/api/functions/formatDuration.html +2 -2
- package/docs/api/functions/formatM3.html +2 -2
- package/docs/api/functions/getAssemblyType.html +2 -2
- package/docs/api/functions/getAssemblyTypeApiString.html +2 -2
- package/docs/api/functions/getAssemblyWithOwner.html +3 -3
- package/docs/api/functions/getCharacterOwnerCapType.html +2 -2
- package/docs/api/functions/getCommonItems.html +1 -1
- package/docs/api/functions/getDappUrl.html +2 -2
- package/docs/api/functions/getDatahubGameInfo.html +2 -2
- package/docs/api/functions/getEnv.html +1 -1
- package/docs/api/functions/getEveWorldPackageId.html +2 -2
- package/docs/api/functions/getObjectByAddress.html +2 -2
- package/docs/api/functions/getObjectId.html +2 -2
- package/docs/api/functions/getObjectOwnerAndOwnedObjectsByType.html +2 -2
- package/docs/api/functions/getObjectRegistryType.html +2 -2
- package/docs/api/functions/getObjectWithDynamicFields.html +2 -2
- package/docs/api/functions/getObjectWithJson.html +2 -2
- package/docs/api/functions/getObjectsByType.html +2 -2
- package/docs/api/functions/getOwnedObjectsByPackage.html +2 -2
- package/docs/api/functions/getOwnedObjectsByType.html +2 -2
- package/docs/api/functions/getRegistryAddress.html +2 -2
- package/docs/api/functions/getSingletonObjectByType.html +2 -2
- package/docs/api/functions/getSponsoredTransactionFeature.html +2 -2
- package/docs/api/functions/getSuiGraphqlEndpoint.html +2 -2
- package/docs/api/functions/getTxUrl.html +2 -2
- package/docs/api/functions/getVolumeM3.html +2 -2
- package/docs/api/functions/hasSponsoredTransactionFeature.html +2 -2
- package/docs/api/functions/isOwner.html +2 -2
- package/docs/api/functions/parseErrorFromMessage.html +1 -1
- package/docs/api/functions/parseStatus.html +2 -2
- package/docs/api/functions/parseURL.html +1 -1
- package/docs/api/functions/removeTrailingZeros.html +1 -1
- package/docs/api/functions/transformToAssembly.html +2 -2
- package/docs/api/functions/transformToCharacter.html +2 -2
- package/docs/api/functions/useConnection.html +2 -2
- package/docs/api/functions/useNotification.html +2 -2
- package/docs/api/functions/useSmartObject.html +4 -9
- package/docs/api/functions/useSponsoredTransaction.html +9 -9
- package/docs/api/functions/walletSupportsSponsoredTransaction.html +2 -2
- package/docs/api/hierarchy.html +1 -1
- package/docs/api/index.html +3 -5
- package/docs/api/interfaces/AddressOwner.html +2 -2
- package/docs/api/interfaces/AddressOwnerWithJson.html +2 -2
- package/docs/api/interfaces/AssemblyProperties.html +2 -2
- package/docs/api/interfaces/CharacterInfo.html +3 -3
- package/docs/api/interfaces/DatahubGameInfo.html +15 -15
- package/docs/api/interfaces/DetailedAssemblyResponse.html +2 -2
- package/docs/api/interfaces/DetailedSmartCharacterResponse.html +2 -2
- package/docs/api/interfaces/DynamicFieldNode.html +2 -2
- package/docs/api/interfaces/EphemeralInventory.html +2 -2
- package/docs/api/interfaces/EveFrontierSponsoredTransactionFeature.html +3 -3
- package/docs/api/interfaces/GameTypeResponse.html +2 -2
- package/docs/api/interfaces/GateModule.html +2 -2
- package/docs/api/interfaces/GetObjectByAddressResponse.html +2 -2
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsResponse.html +2 -2
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsWithJsonResponse.html +2 -2
- package/docs/api/interfaces/GetObjectResponse.html +2 -2
- package/docs/api/interfaces/GetObjectWithJsonResponse.html +2 -2
- package/docs/api/interfaces/GetObjectsByTypeResponse.html +2 -2
- package/docs/api/interfaces/GetOwnedObjectsByPackageResponse.html +2 -2
- package/docs/api/interfaces/GetOwnedObjectsByTypeResponse.html +2 -2
- package/docs/api/interfaces/GetSingletonObjectByTypeResponse.html +2 -2
- package/docs/api/interfaces/GraphQLResponse.html +2 -2
- package/docs/api/interfaces/InventoryItem.html +2 -2
- package/docs/api/interfaces/ManufacturingModule.html +2 -2
- package/docs/api/interfaces/MoveObjectContents.html +2 -2
- package/docs/api/interfaces/MoveObjectData.html +2 -2
- package/docs/api/interfaces/NetworkNodeModule.html +2 -3
- package/docs/api/interfaces/NotificationContextType.html +2 -2
- package/docs/api/interfaces/NotificationState.html +2 -2
- package/docs/api/interfaces/Notify.html +2 -2
- package/docs/api/interfaces/ObjectWithContentsNode.html +2 -2
- package/docs/api/interfaces/OwnedObjectAddressNode.html +2 -2
- package/docs/api/interfaces/OwnedObjectFullNode.html +2 -2
- package/docs/api/interfaces/OwnedObjectNode.html +2 -2
- package/docs/api/interfaces/OwnedObjectNodeWithJson.html +2 -2
- package/docs/api/interfaces/OwnerCapData.html +3 -3
- package/docs/api/interfaces/PageInfo.html +2 -2
- package/docs/api/interfaces/RawCharacterData.html +3 -3
- package/docs/api/interfaces/RawSuiObjectData.html +10 -6
- package/docs/api/interfaces/RefineryModule.html +2 -2
- package/docs/api/interfaces/SmartAssemblyResponse.html +2 -2
- package/docs/api/interfaces/SmartObjectContextType.html +3 -4
- package/docs/api/interfaces/SponsoredTransactionInput.html +7 -8
- package/docs/api/interfaces/SponsoredTransactionOutput.html +5 -5
- package/docs/api/interfaces/StorageModule.html +2 -2
- package/docs/api/interfaces/SuiObjectResponse.html +2 -2
- package/docs/api/interfaces/TransformOptions.html +6 -4
- package/docs/api/interfaces/TurretModule.html +2 -2
- package/docs/api/interfaces/VaultContextType.html +3 -2
- package/docs/api/modules.html +1 -1
- package/docs/api/types/AssemblyType.html +1 -1
- package/docs/api/types/ErrorType.html +2 -2
- package/docs/api/types/SendSponsoredTransactionFn.html +1 -1
- package/docs/api/types/SponsoredTransactionArgs.html +2 -2
- package/docs/api/types/SponsoredTransactionAssemblyType.html +2 -2
- package/docs/api/types/SponsoredTransactionMethod.html +2 -2
- package/docs/api/types/UseSponsoredTransactionArgs.html +2 -2
- package/docs/api/types/UseSponsoredTransactionError.html +2 -2
- package/docs/api/types/UseSponsoredTransactionMutationOptions.html +2 -2
- package/docs/api/variables/ASSEMBLY_TYPE_API_STRING.html +2 -0
- package/docs/api/variables/ERRORS.html +1 -1
- package/docs/api/variables/ERROR_MESSAGES.html +1 -1
- package/docs/api/variables/EVEFRONTIER_SPONSORED_TRANSACTION.html +2 -2
- package/docs/api/variables/EXCLUDED_TYPEIDS.html +1 -1
- package/docs/api/variables/GET_OBJECTS_BY_TYPE.html +2 -2
- package/docs/api/variables/GET_OBJECT_BY_ADDRESS.html +2 -2
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE.html +2 -2
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON.html +2 -2
- package/docs/api/variables/GET_OBJECT_WITH_DYNAMIC_FIELDS.html +2 -2
- package/docs/api/variables/GET_OBJECT_WITH_JSON.html +2 -2
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_PACKAGE.html +2 -2
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_TYPE.html +2 -2
- package/docs/api/variables/GET_SINGLETON_OBJECT_BY_TYPE.html +2 -2
- package/docs/api/variables/NotificationContext.html +1 -1
- package/docs/api/variables/ONE_M3.html +2 -2
- package/docs/api/variables/POLLING_INTERVAL.html +2 -2
- package/docs/api/variables/STORAGE_KEYS.html +2 -2
- package/docs/api/variables/SmartObjectContext.html +1 -1
- package/docs/api/variables/VaultContext.html +1 -1
- package/docs/api/variables/dAppKit.html +2 -2
- package/graphql/client.ts +26 -3
- package/graphql/queries.ts +9 -0
- package/graphql/types.ts +10 -18
- package/hooks/useConnection.ts +2 -1
- package/hooks/useNotification.ts +5 -3
- package/hooks/useSmartObject.ts +4 -16
- package/hooks/useSponsoredTransaction.ts +85 -16
- package/index.ts +0 -10
- package/package.json +1 -1
- package/providers/NotificationProvider.tsx +1 -20
- package/providers/SmartObjectProvider.tsx +69 -67
- package/providers/VaultProvider.tsx +6 -14
- package/providers/index.ts +1 -8
- package/types/contexts.ts +55 -0
- package/types/index.ts +1 -1
- package/types/sponsoredTransaction.ts +35 -0
- package/types/worldApiReturnTypes.ts +6 -4
- package/utils/transforms.ts +18 -12
- package/utils/utils.ts +1 -1
- package/vite-env.d.ts +2 -4
- package/wallet/features.ts +9 -38
- package/wallet/index.ts +0 -2
- package/wallet/utils.ts +1 -1
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
type SponsoredTransactionOutput,
|
|
18
18
|
SponsoredTransactionArgs,
|
|
19
19
|
} from "../wallet";
|
|
20
|
-
import { SponsoredTransactionActions } from "../types";
|
|
20
|
+
import { QueryParams, SponsoredTransactionActions } from "../types";
|
|
21
21
|
|
|
22
22
|
/** Wallet-like shape from dApp Kit (UiWallet or connection store). */
|
|
23
23
|
type ResolvableWallet = {
|
|
@@ -74,6 +74,58 @@ export class WalletNoAccountSelectedError extends Error {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Error thrown when assembly ID cannot be resolved or is invalid.
|
|
79
|
+
* Assembly ID must come from the assembly object (item_id) or the URL query param (itemId), and must be a valid non-negative integer.
|
|
80
|
+
*
|
|
81
|
+
* @category Errors
|
|
82
|
+
*/
|
|
83
|
+
export class AssemblyIdRequiredError extends Error {
|
|
84
|
+
constructor(reason?: string) {
|
|
85
|
+
super(
|
|
86
|
+
reason ??
|
|
87
|
+
"Assembly ID is required: pass an assembly object with item_id or set the itemId query param to a valid non-negative integer",
|
|
88
|
+
);
|
|
89
|
+
this.name = "AssemblyIdRequiredError";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ============================================================================
|
|
94
|
+
// Assembly ID resolution
|
|
95
|
+
// ============================================================================
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolves assembly ID to a non-negative integer from the assembly object or query param.
|
|
99
|
+
* Fails fast with {@link AssemblyIdRequiredError} if neither source provides a valid id.
|
|
100
|
+
*/
|
|
101
|
+
function resolveAssemblyId(
|
|
102
|
+
assemblyItemId: number | undefined,
|
|
103
|
+
queryItemId: string | null,
|
|
104
|
+
): number {
|
|
105
|
+
const fromAssembly =
|
|
106
|
+
typeof assemblyItemId === "number" &&
|
|
107
|
+
Number.isInteger(assemblyItemId) &&
|
|
108
|
+
assemblyItemId >= 0
|
|
109
|
+
? assemblyItemId
|
|
110
|
+
: undefined;
|
|
111
|
+
|
|
112
|
+
if (fromAssembly !== undefined) {
|
|
113
|
+
return fromAssembly;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (queryItemId != null && queryItemId.trim() !== "") {
|
|
117
|
+
const parsed = parseInt(queryItemId.trim(), 10);
|
|
118
|
+
if (Number.isNaN(parsed) || parsed < 0) {
|
|
119
|
+
throw new AssemblyIdRequiredError(
|
|
120
|
+
`Query param itemId must be a non-negative integer; got "${queryItemId}"`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return parsed;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
throw new AssemblyIdRequiredError();
|
|
127
|
+
}
|
|
128
|
+
|
|
77
129
|
// ============================================================================
|
|
78
130
|
// Hook Types
|
|
79
131
|
// ============================================================================
|
|
@@ -87,6 +139,7 @@ export type UseSponsoredTransactionError =
|
|
|
87
139
|
| WalletSponsoredTransactionNotSupportedError
|
|
88
140
|
| WalletNotConnectedError
|
|
89
141
|
| WalletNoAccountSelectedError
|
|
142
|
+
| AssemblyIdRequiredError
|
|
90
143
|
| Error;
|
|
91
144
|
|
|
92
145
|
/**
|
|
@@ -129,10 +182,9 @@ export type UseSponsoredTransactionMutationOptions = Omit<
|
|
|
129
182
|
* **Input** (passed to `mutate` / `mutateAsync`):
|
|
130
183
|
* - `txAction` (required) – The sponsored action to run (e.g. BRING_ONLINE, BRING_OFFLINE).
|
|
131
184
|
* - `chain` (required) – Sui chain id, e.g. `"sui:testnet"` or `"sui:mainnet"`.
|
|
132
|
-
* - `
|
|
133
|
-
* - `
|
|
134
|
-
* - `
|
|
135
|
-
* - `account` (optional) – Signer account override; defaults to current connected account.
|
|
185
|
+
* - `assembly` (required) – Full assembly object (`AssemblyType<Assemblies>`). Must include `type` and `item_id` (number). If `item_id` is missing or invalid, the hook falls back to the URL query param `itemId` (parsed as a non-negative integer). Fails with {@link AssemblyIdRequiredError} if neither source provides a valid id.
|
|
186
|
+
* - `tenant` (optional) – Tenant ID. When omitted, the hook resolves it from the URL query param (e.g. `tenant`) with fallback to `"testevenet"`. Pass explicitly to override.
|
|
187
|
+
* - `account` (optional) – Signer address. If omitted, the currently connected wallet account is used.
|
|
136
188
|
*
|
|
137
189
|
* **Output** (on success, in `data` or resolved from `mutateAsync`):
|
|
138
190
|
* - `digest` (required) – Transaction digest.
|
|
@@ -152,21 +204,23 @@ export type UseSponsoredTransactionMutationOptions = Omit<
|
|
|
152
204
|
* @throws {WalletNotConnectedError} If no wallet is connected
|
|
153
205
|
* @throws {WalletNoAccountSelectedError} If no account is selected
|
|
154
206
|
* @throws {WalletSponsoredTransactionNotSupportedError} If wallet doesn't support sponsored transactions
|
|
207
|
+
* @throws {AssemblyIdRequiredError} If assembly ID is missing or invalid (neither assembly.item_id nor itemId query param is a valid non-negative integer)
|
|
155
208
|
*
|
|
156
209
|
* @example Basic bring online transaction
|
|
157
210
|
* ```tsx
|
|
158
|
-
* import { useSponsoredTransaction, SponsoredTransactionActions } from "@evefrontier/dapp-kit";
|
|
211
|
+
* import { useSponsoredTransaction, SponsoredTransactionActions, useSmartObject } from "@evefrontier/dapp-kit";
|
|
159
212
|
*
|
|
160
213
|
* const BringOnlineButton = () => {
|
|
214
|
+
* const { assembly } = useSmartObject();
|
|
161
215
|
* const { mutateAsync: sendTx, isPending } = useSponsoredTransaction();
|
|
162
216
|
*
|
|
163
217
|
* const handleBringOnline = async () => {
|
|
218
|
+
* if (!assembly) return;
|
|
164
219
|
* try {
|
|
165
220
|
* const result = await sendTx({
|
|
166
221
|
* txAction: SponsoredTransactionActions.BRING_ONLINE,
|
|
167
|
-
* assembly
|
|
222
|
+
* assembly,
|
|
168
223
|
* chain: "sui:testnet",
|
|
169
|
-
* ownerId: "0x...",
|
|
170
224
|
* });
|
|
171
225
|
* console.log("Transaction digest:", result.digest);
|
|
172
226
|
* } catch (error) {
|
|
@@ -175,7 +229,7 @@ export type UseSponsoredTransactionMutationOptions = Omit<
|
|
|
175
229
|
* };
|
|
176
230
|
*
|
|
177
231
|
* return (
|
|
178
|
-
* <button onClick={handleBringOnline} disabled={isPending}>
|
|
232
|
+
* <button onClick={handleBringOnline} disabled={isPending || !assembly}>
|
|
179
233
|
* {isPending ? "Processing..." : "Bring Online"}
|
|
180
234
|
* </button>
|
|
181
235
|
* );
|
|
@@ -184,13 +238,13 @@ export type UseSponsoredTransactionMutationOptions = Omit<
|
|
|
184
238
|
*
|
|
185
239
|
* @example With callbacks
|
|
186
240
|
* ```tsx
|
|
241
|
+
* const { assembly } = useSmartObject();
|
|
187
242
|
* const { mutate: sendTx } = useSponsoredTransaction();
|
|
188
243
|
*
|
|
189
244
|
* sendTx(
|
|
190
245
|
* {
|
|
191
246
|
* txAction: SponsoredTransactionActions.BRING_ONLINE,
|
|
192
|
-
* assembly
|
|
193
|
-
* ownerId: "0x...",
|
|
247
|
+
* assembly,
|
|
194
248
|
* chain: "sui:testnet",
|
|
195
249
|
* },
|
|
196
250
|
* {
|
|
@@ -204,13 +258,13 @@ export type UseSponsoredTransactionMutationOptions = Omit<
|
|
|
204
258
|
* );
|
|
205
259
|
* ```
|
|
206
260
|
*
|
|
207
|
-
* @example With assembly
|
|
261
|
+
* @example With assembly and optional account
|
|
208
262
|
* ```tsx
|
|
209
263
|
* const result = await sendTx({
|
|
210
264
|
* txAction: SponsoredTransactionActions.BRING_ONLINE,
|
|
265
|
+
* assembly, // full AssemblyType from useSmartObject() or similar
|
|
211
266
|
* chain: "sui:testnet",
|
|
212
|
-
*
|
|
213
|
-
* assembly: "0x123...",
|
|
267
|
+
* account: "0x...", // optional; defaults to connected wallet account
|
|
214
268
|
* });
|
|
215
269
|
* ```
|
|
216
270
|
*
|
|
@@ -230,6 +284,10 @@ export function useSponsoredTransaction({
|
|
|
230
284
|
const wallets = useWallets();
|
|
231
285
|
const currentAccount = useCurrentAccount();
|
|
232
286
|
|
|
287
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
288
|
+
const queryItemId = queryParams.get(QueryParams.ITEM_ID);
|
|
289
|
+
const queryTenant = queryParams.get(QueryParams.TENANT);
|
|
290
|
+
|
|
233
291
|
return useMutation({
|
|
234
292
|
mutationKey: [
|
|
235
293
|
"evefrontier",
|
|
@@ -308,14 +366,25 @@ export function useSponsoredTransaction({
|
|
|
308
366
|
);
|
|
309
367
|
}
|
|
310
368
|
|
|
369
|
+
const tenant = (args.tenant ?? queryTenant ?? "testevenet").trim();
|
|
370
|
+
if (!tenant) {
|
|
371
|
+
throw new Error(
|
|
372
|
+
"Tenant could not be resolved; pass tenant or set the tenant query param",
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const assemblyId = resolveAssemblyId(args.assembly.item_id, queryItemId);
|
|
377
|
+
|
|
311
378
|
const payload: SponsoredTransactionInput = {
|
|
312
379
|
txAction: args.txAction,
|
|
313
|
-
assembly:
|
|
380
|
+
assembly: assemblyId,
|
|
314
381
|
assemblyType: getAssemblyTypeApiString(args.assembly.type),
|
|
315
382
|
chain: args.chain,
|
|
316
|
-
|
|
383
|
+
tenant,
|
|
317
384
|
};
|
|
318
385
|
|
|
386
|
+
console.log("payload", payload);
|
|
387
|
+
|
|
319
388
|
return await signSponsoredTransaction(payload);
|
|
320
389
|
},
|
|
321
390
|
...mutationOptions,
|
package/index.ts
CHANGED
|
@@ -31,14 +31,6 @@ export {
|
|
|
31
31
|
NotificationContext,
|
|
32
32
|
} from "./providers";
|
|
33
33
|
|
|
34
|
-
// Types from providers
|
|
35
|
-
export type {
|
|
36
|
-
VaultContextType,
|
|
37
|
-
SmartObjectContextType,
|
|
38
|
-
NotificationContextType,
|
|
39
|
-
NotificationState,
|
|
40
|
-
} from "./providers";
|
|
41
|
-
|
|
42
34
|
// =========================================
|
|
43
35
|
// Types (re-exported from ./types)
|
|
44
36
|
// =========================================
|
|
@@ -145,7 +137,6 @@ export {
|
|
|
145
137
|
// Wallet Standard Extensions
|
|
146
138
|
// =========================================
|
|
147
139
|
export {
|
|
148
|
-
EVEFRONTIER_SPONSORED_TRANSACTION,
|
|
149
140
|
getAssemblyTypeApiString,
|
|
150
141
|
hasSponsoredTransactionFeature,
|
|
151
142
|
walletSupportsSponsoredTransaction,
|
|
@@ -155,7 +146,6 @@ export {
|
|
|
155
146
|
export type {
|
|
156
147
|
EveFrontierSponsoredTransactionFeature,
|
|
157
148
|
SponsoredTransactionArgs,
|
|
158
|
-
SponsoredTransactionAssemblyType,
|
|
159
149
|
SponsoredTransactionInput,
|
|
160
150
|
SponsoredTransactionOutput,
|
|
161
151
|
SponsoredTransactionMethod,
|
package/package.json
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import { ReactNode, createContext, useCallback, useState } from "react";
|
|
2
2
|
|
|
3
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
|
-
}
|
|
4
|
+
import { NotificationContextType, NotificationState } from "../types";
|
|
24
5
|
|
|
25
6
|
/** @category Providers */
|
|
26
7
|
export const NotificationContext = createContext<NotificationContextType>({
|
|
@@ -23,26 +23,24 @@ import {
|
|
|
23
23
|
} from "../utils";
|
|
24
24
|
import { getDatahubGameInfo } from "../utils/datahub";
|
|
25
25
|
import { useConnection } from "../hooks/useConnection";
|
|
26
|
+
import { SmartObjectContextType } from "../types";
|
|
26
27
|
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
28
|
+
/** Tenant when not provided via URL ?tenant= (e.g. dev/default chain). */
|
|
29
|
+
const DEFAULT_TENANT = "testevenet";
|
|
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
37
|
|
|
38
38
|
/** @category Providers */
|
|
39
39
|
export const SmartObjectContext = createContext<SmartObjectContextType>({
|
|
40
40
|
assembly: null,
|
|
41
41
|
character: null,
|
|
42
|
-
selectedObjectId: "",
|
|
43
42
|
loading: true,
|
|
44
43
|
error: null,
|
|
45
|
-
setSelectedObjectId: () => {},
|
|
46
44
|
refetch: async () => {},
|
|
47
45
|
});
|
|
48
46
|
|
|
@@ -66,6 +64,7 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
66
64
|
useState<DetailedSmartCharacterResponse | null>(null);
|
|
67
65
|
const [selectedObjectId, setSelectedObjectId] = useState<string>("");
|
|
68
66
|
const [selectedTenant, setSelectedTenant] = useState<string>("");
|
|
67
|
+
const [isObjectIdDirect, setIsObjectIdDirect] = useState<boolean>(false); // Whether selectedObjectId is a Sui object ID or derived from itemId + tenant.
|
|
69
68
|
const [loading, setLoading] = useState<boolean>(true);
|
|
70
69
|
const [error, setError] = useState<string | null>(null);
|
|
71
70
|
|
|
@@ -74,10 +73,16 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
74
73
|
|
|
75
74
|
const { isConnected } = useConnection();
|
|
76
75
|
|
|
77
|
-
// Fetch object data with owner/character info
|
|
76
|
+
// Fetch object data with owner/character info.
|
|
77
|
+
// Accepts either { itemId, selectedTenant } (derive Sui object ID) or { objectId } (use directly).
|
|
78
78
|
const fetchObjectData = useCallback(
|
|
79
|
-
async (
|
|
80
|
-
|
|
79
|
+
async (input: FetchObjectDataInput, isInitialFetch = false) => {
|
|
80
|
+
const hasItemId = "itemId" in input && "selectedTenant" in input;
|
|
81
|
+
if (hasItemId) {
|
|
82
|
+
if (!input.itemId || !input.selectedTenant) return;
|
|
83
|
+
} else {
|
|
84
|
+
if (!input.objectId) return;
|
|
85
|
+
}
|
|
81
86
|
|
|
82
87
|
if (isInitialFetch) {
|
|
83
88
|
setLoading(true);
|
|
@@ -85,17 +90,22 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
85
90
|
setError(null);
|
|
86
91
|
|
|
87
92
|
try {
|
|
93
|
+
const objectId = hasItemId
|
|
94
|
+
? await getObjectId(input.itemId, input.selectedTenant)
|
|
95
|
+
: input.objectId;
|
|
88
96
|
console.log(
|
|
89
|
-
"[DappKit] SmartObjectProvider: Fetching object
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
"[DappKit] SmartObjectProvider: Fetching object:",
|
|
98
|
+
hasItemId
|
|
99
|
+
? { itemId: input.itemId, selectedTenant: input.selectedTenant }
|
|
100
|
+
: { objectId },
|
|
92
101
|
);
|
|
93
102
|
|
|
94
|
-
const objectId = await getObjectId(itemId, selectedTenant);
|
|
95
|
-
|
|
96
103
|
// Fetch both assembly and character data
|
|
97
|
-
const {
|
|
98
|
-
|
|
104
|
+
const {
|
|
105
|
+
moveObject,
|
|
106
|
+
character: characterInfo,
|
|
107
|
+
energySource,
|
|
108
|
+
} = await getAssemblyWithOwner(objectId);
|
|
99
109
|
|
|
100
110
|
if (!moveObject) {
|
|
101
111
|
console.warn(
|
|
@@ -111,6 +121,7 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
111
121
|
const dataHash = JSON.stringify({
|
|
112
122
|
moveObject,
|
|
113
123
|
character: characterInfo,
|
|
124
|
+
energySource,
|
|
114
125
|
});
|
|
115
126
|
|
|
116
127
|
// Only update state if the data changed (optimization for polling)
|
|
@@ -142,6 +153,7 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
142
153
|
{
|
|
143
154
|
character: characterInfo,
|
|
144
155
|
datahubInfo,
|
|
156
|
+
energySource: energySource,
|
|
145
157
|
},
|
|
146
158
|
);
|
|
147
159
|
|
|
@@ -168,54 +180,40 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
168
180
|
[],
|
|
169
181
|
);
|
|
170
182
|
|
|
171
|
-
// Initialize the object ID
|
|
183
|
+
// Initialize the object ID (env or query params) and tenant (query params).
|
|
184
|
+
// Tenant comes from URL ?tenant= with fallback DEFAULT_TENANT.
|
|
172
185
|
useEffect(() => {
|
|
173
186
|
console.log("[DappKit] SmartObjectProvider: Checking for item ID");
|
|
174
187
|
|
|
188
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
189
|
+
const queryTenant =
|
|
190
|
+
queryParams.get(QueryParams.TENANT)?.trim() || DEFAULT_TENANT;
|
|
191
|
+
|
|
175
192
|
// Check if an object ID exists in the .env file
|
|
176
|
-
const
|
|
177
|
-
const envTenant = import.meta.env.VITE_EVE_WORLD_TENANT;
|
|
193
|
+
const envObjectId = import.meta.env.VITE_OBJECT_ID;
|
|
178
194
|
|
|
179
|
-
if (
|
|
195
|
+
if (envObjectId) {
|
|
180
196
|
console.log(
|
|
181
|
-
"[DappKit] SmartObjectProvider: Using
|
|
182
|
-
|
|
197
|
+
"[DappKit] SmartObjectProvider: Using Sui object ID from env:",
|
|
198
|
+
envObjectId,
|
|
183
199
|
);
|
|
184
|
-
setSelectedObjectId(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
console.log(
|
|
188
|
-
"[DappKit] SmartObjectProvider: Using tenant from env:",
|
|
189
|
-
envTenant,
|
|
190
|
-
);
|
|
191
|
-
setSelectedTenant(envTenant);
|
|
192
|
-
} else {
|
|
193
|
-
console.error(
|
|
194
|
-
"[DappKit] SmartObjectProvider: VITE_ITEM_ID is set but VITE_EVE_WORLD_TENANT is missing. " +
|
|
195
|
-
"Both are required when using env-based configuration.",
|
|
196
|
-
);
|
|
197
|
-
setLoading(false);
|
|
198
|
-
}
|
|
200
|
+
setSelectedObjectId(envObjectId);
|
|
201
|
+
setSelectedTenant(queryTenant);
|
|
202
|
+
setIsObjectIdDirect(true);
|
|
199
203
|
return;
|
|
200
204
|
}
|
|
201
205
|
|
|
202
|
-
//
|
|
203
|
-
const queryParams = new URLSearchParams(window.location.search);
|
|
206
|
+
// Else, derive object ID from item ID and tenant and passed via query param
|
|
204
207
|
const queryItemId = queryParams.get(QueryParams.ITEM_ID);
|
|
205
|
-
const queryTenant = queryParams.get(QueryParams.TENANT);
|
|
206
208
|
|
|
207
209
|
if (queryItemId) {
|
|
208
210
|
setSelectedObjectId(queryItemId);
|
|
211
|
+
setSelectedTenant(queryTenant);
|
|
212
|
+
setIsObjectIdDirect(false);
|
|
209
213
|
} else {
|
|
210
214
|
console.error("[DappKit] SmartObjectProvider: No object ID provided");
|
|
211
215
|
setLoading(false);
|
|
212
216
|
}
|
|
213
|
-
|
|
214
|
-
if (queryTenant) {
|
|
215
|
-
setSelectedTenant(queryTenant);
|
|
216
|
-
} else {
|
|
217
|
-
console.error("[DappKit] SmartObjectProvider: No tenant provided");
|
|
218
|
-
}
|
|
219
217
|
}, []);
|
|
220
218
|
|
|
221
219
|
// Fetch and poll for object data
|
|
@@ -227,12 +225,16 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
227
225
|
return;
|
|
228
226
|
}
|
|
229
227
|
|
|
228
|
+
const input: FetchObjectDataInput = isObjectIdDirect
|
|
229
|
+
? { objectId: selectedObjectId }
|
|
230
|
+
: { itemId: selectedObjectId, selectedTenant };
|
|
231
|
+
|
|
230
232
|
// Initial fetch
|
|
231
|
-
fetchObjectData(
|
|
233
|
+
fetchObjectData(input, true);
|
|
232
234
|
|
|
233
235
|
// Set up polling
|
|
234
236
|
pollingRef.current = setInterval(() => {
|
|
235
|
-
fetchObjectData(
|
|
237
|
+
fetchObjectData(input, false);
|
|
236
238
|
}, POLLING_INTERVAL);
|
|
237
239
|
|
|
238
240
|
console.log(
|
|
@@ -248,29 +250,29 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
248
250
|
}
|
|
249
251
|
lastDataHashRef.current = null;
|
|
250
252
|
};
|
|
251
|
-
}, [
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
253
|
+
}, [
|
|
254
|
+
selectedObjectId,
|
|
255
|
+
selectedTenant,
|
|
256
|
+
isObjectIdDirect,
|
|
257
|
+
isConnected,
|
|
258
|
+
fetchObjectData,
|
|
259
|
+
]);
|
|
258
260
|
|
|
259
261
|
const handleRefetch = useCallback(async () => {
|
|
260
|
-
if (selectedObjectId)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
if (!selectedObjectId) return;
|
|
263
|
+
const input: FetchObjectDataInput = isObjectIdDirect
|
|
264
|
+
? { objectId: selectedObjectId }
|
|
265
|
+
: { itemId: selectedObjectId, selectedTenant };
|
|
266
|
+
await fetchObjectData(input, true);
|
|
267
|
+
}, [selectedObjectId, selectedTenant, isObjectIdDirect, fetchObjectData]);
|
|
264
268
|
|
|
265
269
|
return (
|
|
266
270
|
<SmartObjectContext.Provider
|
|
267
271
|
value={{
|
|
268
272
|
assembly,
|
|
269
273
|
character,
|
|
270
|
-
selectedObjectId,
|
|
271
274
|
loading,
|
|
272
275
|
error,
|
|
273
|
-
setSelectedObjectId: handleSetSelectedObjectId,
|
|
274
276
|
refetch: handleRefetch,
|
|
275
277
|
}}
|
|
276
278
|
>
|
|
@@ -4,18 +4,8 @@ import {
|
|
|
4
4
|
useWallets,
|
|
5
5
|
useDAppKit,
|
|
6
6
|
} from "@mysten/dapp-kit-react";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
/** @category Types */
|
|
11
|
-
export interface VaultContextType {
|
|
12
|
-
currentAccount: WalletAccount | null;
|
|
13
|
-
walletAddress: string | undefined;
|
|
14
|
-
hasEveVault: boolean;
|
|
15
|
-
isConnected: boolean;
|
|
16
|
-
handleConnect: () => void;
|
|
17
|
-
handleDisconnect: () => void;
|
|
18
|
-
}
|
|
7
|
+
import { STORAGE_KEYS } from "../utils";
|
|
8
|
+
import { SupportedWallets, VaultContextType } from "../types";
|
|
19
9
|
|
|
20
10
|
/** @category Providers */
|
|
21
11
|
export const VaultContext = createContext<VaultContextType>({
|
|
@@ -44,8 +34,10 @@ const VaultProvider = ({ children }: { children: ReactNode }) => {
|
|
|
44
34
|
const wallets = useWallets();
|
|
45
35
|
|
|
46
36
|
// Find Eve Vault wallet if available
|
|
47
|
-
const eveVaultWallet = wallets.find(
|
|
48
|
-
wallet
|
|
37
|
+
const eveVaultWallet = wallets.find(
|
|
38
|
+
(wallet) =>
|
|
39
|
+
wallet.name.includes(SupportedWallets.EVE_FRONTIER_CLIENT_WALLET) ||
|
|
40
|
+
wallet.name.includes(SupportedWallets.EVE_VAULT),
|
|
49
41
|
);
|
|
50
42
|
|
|
51
43
|
// Track if auto-connect has been attempted to prevent infinite loops
|
package/providers/index.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
export { default as EveFrontierProvider } from "./EveFrontierProvider";
|
|
2
|
-
export {
|
|
3
|
-
default as VaultProvider,
|
|
4
|
-
VaultContext,
|
|
5
|
-
type VaultContextType,
|
|
6
|
-
} from "./VaultProvider";
|
|
2
|
+
export { default as VaultProvider, VaultContext } from "./VaultProvider";
|
|
7
3
|
export {
|
|
8
4
|
default as SmartObjectProvider,
|
|
9
5
|
SmartObjectContext,
|
|
10
|
-
type SmartObjectContextType,
|
|
11
6
|
} from "./SmartObjectProvider";
|
|
12
7
|
export {
|
|
13
8
|
default as NotificationProvider,
|
|
14
9
|
NotificationContext,
|
|
15
|
-
type NotificationContextType,
|
|
16
|
-
type NotificationState,
|
|
17
10
|
} from "./NotificationProvider";
|
|
@@ -0,0 +1,55 @@
|
|
|
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 Type
|
|
11
|
+
* @category Types */
|
|
12
|
+
export interface VaultContextType {
|
|
13
|
+
currentAccount: WalletAccount | null;
|
|
14
|
+
walletAddress: string | undefined;
|
|
15
|
+
hasEveVault: boolean;
|
|
16
|
+
isConnected: boolean;
|
|
17
|
+
handleConnect: () => void;
|
|
18
|
+
handleDisconnect: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum SupportedWallets {
|
|
22
|
+
EVE_VAULT = "Eve Vault",
|
|
23
|
+
EVE_FRONTIER_CLIENT_WALLET = "EVE Frontier Client Wallet",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Smart Object Context Type
|
|
28
|
+
* @category Types */
|
|
29
|
+
export interface SmartObjectContextType {
|
|
30
|
+
assembly: AssemblyType<Assemblies> | null;
|
|
31
|
+
character: DetailedSmartCharacterResponse | null;
|
|
32
|
+
loading: boolean;
|
|
33
|
+
error: string | null;
|
|
34
|
+
refetch: () => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @category Types */
|
|
38
|
+
export interface NotificationContextType {
|
|
39
|
+
notify: (notification: {
|
|
40
|
+
type: Severity;
|
|
41
|
+
txHash?: string;
|
|
42
|
+
message?: string;
|
|
43
|
+
}) => void;
|
|
44
|
+
notification: NotificationState;
|
|
45
|
+
handleClose: () => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @category Types */
|
|
49
|
+
export interface NotificationState {
|
|
50
|
+
message: string;
|
|
51
|
+
txHash: string;
|
|
52
|
+
severity: Severity;
|
|
53
|
+
handleClose: () => void;
|
|
54
|
+
isOpen: boolean;
|
|
55
|
+
}
|
package/types/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
SponsoredTransactionArgs,
|
|
3
3
|
SponsoredTransactionOutput,
|
|
4
4
|
} from "../wallet";
|
|
5
|
+
import { Assemblies } from "./types";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Available sponsored transaction actions
|
|
@@ -24,3 +25,37 @@ export type SendSponsoredTransactionFn = (
|
|
|
24
25
|
onError?: (error: Error) => void;
|
|
25
26
|
},
|
|
26
27
|
) => Promise<SponsoredTransactionOutput>;
|
|
28
|
+
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Feature Identifiers
|
|
31
|
+
// ============================================================================
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Feature identifier for sponsored transactions.
|
|
35
|
+
* Wallets implementing this feature can request gas sponsorship from
|
|
36
|
+
* the EVE Frontier sponsored-transaction backend service.
|
|
37
|
+
*
|
|
38
|
+
* @category Wallet
|
|
39
|
+
*/
|
|
40
|
+
export const EVEFRONTIER_SPONSORED_TRANSACTION =
|
|
41
|
+
"evefrontier:sponsoredTransaction" as const;
|
|
42
|
+
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Sponsored Transaction Types
|
|
45
|
+
// ============================================================================
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Map assembly types to API strings
|
|
49
|
+
*/
|
|
50
|
+
export const ASSEMBLY_TYPE_API_STRING: Record<Assemblies, string> = {
|
|
51
|
+
[Assemblies.SmartStorageUnit]: "storage-units",
|
|
52
|
+
[Assemblies.SmartTurret]: "turrets",
|
|
53
|
+
[Assemblies.SmartGate]: "gates",
|
|
54
|
+
[Assemblies.NetworkNode]: "network-nodes",
|
|
55
|
+
[Assemblies.Manufacturing]: "manufacturing",
|
|
56
|
+
[Assemblies.Refinery]: "refineries",
|
|
57
|
+
} as const;
|
|
58
|
+
|
|
59
|
+
/** API slug for assembly type in sponsored transaction payloads (e.g. "storage-units"). */
|
|
60
|
+
export type SponsoredTransactionAssemblyType =
|
|
61
|
+
(typeof ASSEMBLY_TYPE_API_STRING)[Assemblies];
|