@evefrontier/dapp-kit 0.1.1 → 0.1.3
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 +12 -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 +3 -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 +2 -2
- 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 +4 -4
- 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/getAdjustedBurnRate.html +6 -0
- 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/getCharacterAndOwnedObjects.html +3 -0
- package/docs/api/functions/getCharacterOwnedObjects.html +5 -0
- package/docs/api/functions/getCharacterOwnedObjectsJson.html +5 -0
- package/docs/api/functions/getCharacterOwnerCapType.html +2 -2
- package/docs/api/functions/getCharacterPlayerProfileType.html +3 -0
- 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/getEnergyConfig.html +4 -0
- package/docs/api/functions/getEnergyConfigType.html +3 -0
- package/docs/api/functions/getEnergyUsageForType.html +5 -0
- package/docs/api/functions/getEnv.html +1 -1
- package/docs/api/functions/getEveWorldPackageId.html +2 -2
- package/docs/api/functions/getFuelEfficiencyConfig.html +4 -0
- package/docs/api/functions/getFuelEfficiencyConfigType.html +3 -0
- package/docs/api/functions/getFuelEfficiencyForType.html +5 -0
- 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/getObjectOwnerAndOwnedObjectsWithJson.html +7 -0
- 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/getWalletCharacters.html +3 -0
- package/docs/api/functions/hasSponsoredTransactionFeature.html +2 -2
- package/docs/api/functions/isOwner.html +3 -3
- package/docs/api/functions/parseCharacterFromJson.html +5 -0
- 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 +5 -5
- 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/AddressWithObjects.html +3 -0
- package/docs/api/interfaces/AdjustedBurnRate.html +8 -0
- package/docs/api/interfaces/AsMoveObjectRef.html +3 -0
- package/docs/api/interfaces/AssemblyProperties.html +6 -3
- package/docs/api/interfaces/CharacterAndOwnedObjectsNode.html +2 -0
- package/docs/api/interfaces/CharacterInfo.html +3 -3
- package/docs/api/interfaces/CharacterOwnerNode.html +3 -0
- package/docs/api/interfaces/ConfigExtractDynamicFieldNode.html +3 -0
- package/docs/api/interfaces/ContentsBcs.html +2 -0
- package/docs/api/interfaces/ContentsJsonAndBcs.html +3 -0
- package/docs/api/interfaces/ContentsJsonOnly.html +3 -0
- package/docs/api/interfaces/ContentsTypeAndBcs.html +3 -0
- package/docs/api/interfaces/ContentsTypeJsonAndBcs.html +4 -0
- package/docs/api/interfaces/DatahubGameInfo.html +14 -16
- package/docs/api/interfaces/DetailedAssemblyResponse.html +6 -3
- 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/ExtractAsMoveObjectNode.html +4 -0
- package/docs/api/interfaces/GateModule.html +2 -5
- package/docs/api/interfaces/GetCharacterAndOwnedObjectsResponse.html +2 -0
- package/docs/api/interfaces/GetObjectAndCharacterOwnerResponse.html +2 -0
- 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/GetSingletonConfigObjectByTypeResponse.html +2 -0
- package/docs/api/interfaces/GetSingletonObjectByTypeResponse.html +2 -2
- package/docs/api/interfaces/GetWalletCharactersResponse.html +2 -0
- package/docs/api/interfaces/GraphQLResponse.html +2 -2
- package/docs/api/interfaces/InventoryItem.html +2 -2
- package/docs/api/interfaces/ManufacturingModule.html +1 -2
- package/docs/api/interfaces/MoveObjectContents.html +2 -2
- package/docs/api/interfaces/MoveObjectData.html +2 -2
- package/docs/api/interfaces/NetworkNodeModule.html +2 -2
- 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/ObjectNodes.html +2 -0
- 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/PreviousTransaction.html +2 -0
- package/docs/api/interfaces/RawCharacterData.html +3 -3
- package/docs/api/interfaces/RawSuiObjectData.html +10 -6
- package/docs/api/interfaces/RefineryModule.html +1 -2
- package/docs/api/interfaces/SmartAssemblyResponse.html +6 -2
- package/docs/api/interfaces/SmartObjectContextType.html +4 -6
- package/docs/api/interfaces/SponsoredTransactionInput.html +6 -7
- package/docs/api/interfaces/SponsoredTransactionOutput.html +5 -5
- package/docs/api/interfaces/StorageModule.html +2 -3
- package/docs/api/interfaces/SuiObjectResponse.html +2 -2
- package/docs/api/interfaces/TransformOptions.html +8 -4
- package/docs/api/interfaces/TurretModule.html +1 -2
- package/docs/api/interfaces/TypeRepr.html +2 -0
- package/docs/api/interfaces/TypeReprWithLayout.html +3 -0
- package/docs/api/interfaces/VaultContextType.html +3 -3
- package/docs/api/modules.html +1 -1
- package/docs/api/types/AssemblyType.html +1 -1
- package/docs/api/types/ContentsTypeAndJson.html +2 -0
- package/docs/api/types/ErrorType.html +2 -2
- package/docs/api/types/MoveObjectRefWithJson.html +2 -0
- 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 -2
- 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_CONFIG_OBJECT_BY_TYPE.html +2 -0
- package/docs/api/variables/GET_SINGLETON_OBJECT_BY_TYPE.html +2 -2
- package/docs/api/variables/GET_WALLET_CHARACTERS.html +3 -0
- 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 +119 -24
- package/graphql/index.ts +5 -39
- package/graphql/queries.ts +166 -1
- package/graphql/types.ts +192 -167
- package/hooks/index.ts +1 -0
- package/hooks/useSmartObject.ts +2 -12
- package/hooks/useSponsoredTransaction.ts +60 -9
- package/index.ts +7 -71
- package/package.json +1 -1
- package/providers/SmartObjectProvider.tsx +84 -57
- package/types/contexts.ts +1 -3
- package/types/sponsoredTransaction.ts +1 -0
- package/types/types.ts +52 -10
- package/types/worldApiReturnTypes.ts +13 -37
- package/utils/__tests__/burnRate.test.ts +121 -0
- package/utils/__tests__/character.test.ts +112 -0
- package/utils/__tests__/characterOwnedObjects.test.ts +222 -0
- package/utils/__tests__/config.test.ts +424 -0
- package/utils/__tests__/mapping.test.ts +2 -2
- package/utils/burnRate.ts +46 -0
- package/utils/character.ts +46 -0
- package/utils/characterOwnedObjects.ts +52 -0
- package/utils/config.ts +151 -0
- package/utils/constants.ts +39 -5
- package/utils/datahub.ts +3 -41
- package/utils/errors.ts +1 -1
- package/utils/index.ts +10 -1
- package/utils/mapping.ts +5 -2
- package/utils/transforms.ts +34 -31
- package/vite-env.d.ts +2 -2
- package/wallet/features.ts +7 -2
- package/docs/api/interfaces/GameTypeResponse.html +0 -13
package/hooks/useSmartObject.ts
CHANGED
|
@@ -7,17 +7,15 @@ import { SmartObjectContextType } from "../types";
|
|
|
7
7
|
*
|
|
8
8
|
* Provides reactive access to the currently selected smart assembly (Smart Storage Unit,
|
|
9
9
|
* Smart Turret, Smart Gate, Network Node, etc.) with automatic polling for updates.
|
|
10
|
-
* The assembly ID is determined from
|
|
11
|
-
* or
|
|
10
|
+
* The assembly ID is determined from URL query parameters (`?itemId=` and `?tenant=`)
|
|
11
|
+
* or environment variables as a Sui object ID (`VITE_OBJECT_ID`).
|
|
12
12
|
*
|
|
13
13
|
* @category Hooks
|
|
14
14
|
* @returns Object containing assembly state and methods:
|
|
15
15
|
* - `assembly` - The transformed assembly data (or null if not loaded)
|
|
16
16
|
* - `character` - The owner character information (or null)
|
|
17
|
-
* - `selectedObjectId` - The current assembly's Sui object ID
|
|
18
17
|
* - `loading` - Boolean indicating if data is being fetched
|
|
19
18
|
* - `error` - Error message string (or null)
|
|
20
|
-
* - `setSelectedObjectId` - Function to change the selected assembly
|
|
21
19
|
* - `refetch` - Function to manually refresh assembly data
|
|
22
20
|
* @throws {Error} If used outside of `EveFrontierProvider`
|
|
23
21
|
*
|
|
@@ -56,14 +54,6 @@ import { SmartObjectContextType } from "../types";
|
|
|
56
54
|
* );
|
|
57
55
|
* ```
|
|
58
56
|
*
|
|
59
|
-
* @example Changing the selected assembly
|
|
60
|
-
* ```tsx
|
|
61
|
-
* const { setSelectedObjectId } = useSmartObject();
|
|
62
|
-
*
|
|
63
|
-
* const handleSelectAssembly = (newId: string) => {
|
|
64
|
-
* setSelectedObjectId(newId);
|
|
65
|
-
* };
|
|
66
|
-
* ```
|
|
67
57
|
*/
|
|
68
58
|
export function useSmartObject(): SmartObjectContextType {
|
|
69
59
|
const context = useContext(SmartObjectContext);
|
|
@@ -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
|
-
* - `assembly` (required) – Full assembly object (`AssemblyType<Assemblies>`). Must include `type` and `item_id
|
|
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.
|
|
133
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.
|
|
134
187
|
* - `account` (optional) – Signer address. If omitted, the currently connected wallet account is used.
|
|
135
|
-
* - `destination` (optional) – Additional destination payload when required by the action.
|
|
136
188
|
*
|
|
137
189
|
* **Output** (on success, in `data` or resolved from `mutateAsync`):
|
|
138
190
|
* - `digest` (required) – Transaction digest.
|
|
@@ -152,6 +204,7 @@ 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
|
|
@@ -235,9 +288,6 @@ export function useSponsoredTransaction({
|
|
|
235
288
|
const queryItemId = queryParams.get(QueryParams.ITEM_ID);
|
|
236
289
|
const queryTenant = queryParams.get(QueryParams.TENANT);
|
|
237
290
|
|
|
238
|
-
console.log("queryItemId", queryItemId);
|
|
239
|
-
console.log("queryTenant", queryTenant);
|
|
240
|
-
|
|
241
291
|
return useMutation({
|
|
242
292
|
mutationKey: [
|
|
243
293
|
"evefrontier",
|
|
@@ -323,13 +373,14 @@ export function useSponsoredTransaction({
|
|
|
323
373
|
);
|
|
324
374
|
}
|
|
325
375
|
|
|
376
|
+
const assemblyId = resolveAssemblyId(args.assembly.item_id, queryItemId);
|
|
377
|
+
|
|
326
378
|
const payload: SponsoredTransactionInput = {
|
|
327
|
-
txAction: args.txAction
|
|
328
|
-
assembly:
|
|
379
|
+
txAction: args.txAction,
|
|
380
|
+
assembly: assemblyId,
|
|
329
381
|
assemblyType: getAssemblyTypeApiString(args.assembly.type),
|
|
330
|
-
chain: args.chain
|
|
382
|
+
chain: args.chain,
|
|
331
383
|
tenant,
|
|
332
|
-
...(args.destination != null ? { destination: args.destination } : {}),
|
|
333
384
|
};
|
|
334
385
|
|
|
335
386
|
console.log("payload", payload);
|
package/index.ts
CHANGED
|
@@ -44,82 +44,18 @@ export * from "./utils";
|
|
|
44
44
|
// =========================================
|
|
45
45
|
// GraphQL - Query execution & helper functions
|
|
46
46
|
// =========================================
|
|
47
|
-
export
|
|
48
|
-
executeGraphQLQuery,
|
|
49
|
-
getObjectByAddress,
|
|
50
|
-
getObjectWithDynamicFields,
|
|
51
|
-
getObjectWithJson,
|
|
52
|
-
getObjectOwnerAndOwnedObjectsByType,
|
|
53
|
-
getObjectAndCharacterOwner,
|
|
54
|
-
getOwnedObjectsByType,
|
|
55
|
-
getOwnedObjectsByPackage,
|
|
56
|
-
getSingletonObjectByType,
|
|
57
|
-
getObjectsByType,
|
|
58
|
-
// Character/owner resolution
|
|
59
|
-
getAssemblyWithOwner,
|
|
60
|
-
} from "./graphql";
|
|
61
|
-
|
|
62
|
-
// GraphQL - Query strings
|
|
63
|
-
export {
|
|
64
|
-
// Core object queries
|
|
65
|
-
GET_OBJECT_BY_ADDRESS,
|
|
66
|
-
GET_OBJECT_WITH_DYNAMIC_FIELDS,
|
|
67
|
-
GET_OBJECT_WITH_JSON,
|
|
68
|
-
// Owner & ownership queries
|
|
69
|
-
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE,
|
|
70
|
-
GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON,
|
|
71
|
-
GET_OWNED_OBJECTS_BY_TYPE,
|
|
72
|
-
GET_OWNED_OBJECTS_BY_PACKAGE,
|
|
73
|
-
// Singleton & type-based queries
|
|
74
|
-
GET_SINGLETON_OBJECT_BY_TYPE,
|
|
75
|
-
GET_OBJECTS_BY_TYPE,
|
|
76
|
-
} from "./graphql";
|
|
77
|
-
|
|
78
|
-
// GraphQL - Types
|
|
79
|
-
export type {
|
|
80
|
-
// Base types
|
|
81
|
-
GraphQLResponse,
|
|
82
|
-
PageInfo,
|
|
83
|
-
// Move object types
|
|
84
|
-
MoveObjectContents,
|
|
85
|
-
DynamicFieldNode,
|
|
86
|
-
MoveObjectData,
|
|
87
|
-
// Object response types
|
|
88
|
-
SuiObjectResponse,
|
|
89
|
-
GetObjectResponse,
|
|
90
|
-
// GetObjectByAddress types
|
|
91
|
-
GetObjectByAddressResponse,
|
|
92
|
-
// GetObjectWithJson types
|
|
93
|
-
GetObjectWithJsonResponse,
|
|
94
|
-
// Owner & owned objects types
|
|
95
|
-
OwnedObjectNode,
|
|
96
|
-
AddressOwner,
|
|
97
|
-
GetObjectOwnerAndOwnedObjectsResponse,
|
|
98
|
-
// Owner & owned objects with JSON types
|
|
99
|
-
OwnedObjectNodeWithJson,
|
|
100
|
-
AddressOwnerWithJson,
|
|
101
|
-
GetObjectOwnerAndOwnedObjectsWithJsonResponse,
|
|
102
|
-
// GetOwnedObjectsByType types
|
|
103
|
-
OwnedObjectAddressNode,
|
|
104
|
-
GetOwnedObjectsByTypeResponse,
|
|
105
|
-
// GetOwnedObjectsByPackage types
|
|
106
|
-
OwnedObjectFullNode,
|
|
107
|
-
GetOwnedObjectsByPackageResponse,
|
|
108
|
-
// Singleton & type-based types
|
|
109
|
-
GetSingletonObjectByTypeResponse,
|
|
110
|
-
ObjectWithContentsNode,
|
|
111
|
-
GetObjectsByTypeResponse,
|
|
112
|
-
// EVE Frontier specific types
|
|
113
|
-
RawSuiObjectData,
|
|
114
|
-
OwnerCapData,
|
|
115
|
-
RawCharacterData,
|
|
116
|
-
CharacterInfo,
|
|
117
|
-
} from "./graphql";
|
|
47
|
+
export * from "./graphql";
|
|
118
48
|
|
|
119
49
|
// =========================================
|
|
120
50
|
// Config
|
|
121
51
|
// =========================================
|
|
122
52
|
export { dAppKit } from "./config/dapp-kit";
|
|
53
|
+
export {
|
|
54
|
+
getEnergyConfig,
|
|
55
|
+
getFuelEfficiencyConfig,
|
|
56
|
+
getFuelEfficiencyForType,
|
|
57
|
+
getEnergyUsageForType,
|
|
58
|
+
} from "./utils/config";
|
|
123
59
|
|
|
124
60
|
// =========================================
|
|
125
61
|
// Constants & Configuration
|
package/package.json
CHANGED
|
@@ -25,14 +25,22 @@ import { getDatahubGameInfo } from "../utils/datahub";
|
|
|
25
25
|
import { useConnection } from "../hooks/useConnection";
|
|
26
26
|
import { SmartObjectContextType } from "../types";
|
|
27
27
|
|
|
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
|
+
|
|
28
38
|
/** @category Providers */
|
|
29
39
|
export const SmartObjectContext = createContext<SmartObjectContextType>({
|
|
30
40
|
assembly: null,
|
|
31
|
-
|
|
32
|
-
selectedObjectId: "",
|
|
41
|
+
assemblyOwner: null,
|
|
33
42
|
loading: true,
|
|
34
43
|
error: null,
|
|
35
|
-
setSelectedObjectId: () => {},
|
|
36
44
|
refetch: async () => {},
|
|
37
45
|
});
|
|
38
46
|
|
|
@@ -41,10 +49,10 @@ export const SmartObjectContext = createContext<SmartObjectContextType>({
|
|
|
41
49
|
* It uses GraphQL queries to fetch objects on the Sui blockchain
|
|
42
50
|
* from the EVE Frontier package, with optional polling for updates.
|
|
43
51
|
*
|
|
44
|
-
* The provider fetches both the assembly data and its owner (
|
|
52
|
+
* The provider fetches both the assembly data and its owner (assemblyOwner) information:
|
|
45
53
|
* 1. Fetches assembly data with dynamic fields
|
|
46
54
|
* 2. Uses owner_cap_id to resolve the Character OwnerCap
|
|
47
|
-
* 3. Fetches full
|
|
55
|
+
* 3. Fetches full assemblyOwner data from the Character ID
|
|
48
56
|
*
|
|
49
57
|
* @category Providers
|
|
50
58
|
*/
|
|
@@ -52,10 +60,11 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
52
60
|
const [assembly, setAssembly] = useState<AssemblyType<Assemblies> | null>(
|
|
53
61
|
null,
|
|
54
62
|
);
|
|
55
|
-
const [
|
|
63
|
+
const [assemblyOwner, setAssemblyOwner] =
|
|
56
64
|
useState<DetailedSmartCharacterResponse | null>(null);
|
|
57
65
|
const [selectedObjectId, setSelectedObjectId] = useState<string>("");
|
|
58
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.
|
|
59
68
|
const [loading, setLoading] = useState<boolean>(true);
|
|
60
69
|
const [error, setError] = useState<string | null>(null);
|
|
61
70
|
|
|
@@ -64,10 +73,16 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
64
73
|
|
|
65
74
|
const { isConnected } = useConnection();
|
|
66
75
|
|
|
67
|
-
// Fetch object data with owner/
|
|
76
|
+
// Fetch object data with owner/assemblyOwner info.
|
|
77
|
+
// Accepts either { itemId, selectedTenant } (derive Sui object ID) or { objectId } (use directly).
|
|
68
78
|
const fetchObjectData = useCallback(
|
|
69
|
-
async (
|
|
70
|
-
|
|
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
|
+
}
|
|
71
86
|
|
|
72
87
|
if (isInitialFetch) {
|
|
73
88
|
setLoading(true);
|
|
@@ -75,24 +90,30 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
75
90
|
setError(null);
|
|
76
91
|
|
|
77
92
|
try {
|
|
93
|
+
const objectId = hasItemId
|
|
94
|
+
? await getObjectId(input.itemId, input.selectedTenant)
|
|
95
|
+
: input.objectId;
|
|
78
96
|
console.log(
|
|
79
|
-
"[DappKit] SmartObjectProvider: Fetching object
|
|
80
|
-
|
|
81
|
-
|
|
97
|
+
"[DappKit] SmartObjectProvider: Fetching object:",
|
|
98
|
+
hasItemId
|
|
99
|
+
? { itemId: input.itemId, selectedTenant: input.selectedTenant }
|
|
100
|
+
: { objectId },
|
|
82
101
|
);
|
|
83
102
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
103
|
+
// Fetch both assembly and assemblyOwner data
|
|
104
|
+
const {
|
|
105
|
+
moveObject,
|
|
106
|
+
assemblyOwner: characterInfo,
|
|
107
|
+
energySource,
|
|
108
|
+
destinationGate,
|
|
109
|
+
} = await getAssemblyWithOwner(objectId);
|
|
89
110
|
|
|
90
111
|
if (!moveObject) {
|
|
91
112
|
console.warn(
|
|
92
113
|
"[DappKit] SmartObjectProvider: Object not found or not a Move object",
|
|
93
114
|
);
|
|
94
115
|
setAssembly(null);
|
|
95
|
-
|
|
116
|
+
setAssemblyOwner(null);
|
|
96
117
|
setError("Object not found or not a Move object");
|
|
97
118
|
return;
|
|
98
119
|
}
|
|
@@ -100,7 +121,8 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
100
121
|
// Create a hash of the data to check for changes
|
|
101
122
|
const dataHash = JSON.stringify({
|
|
102
123
|
moveObject,
|
|
103
|
-
|
|
124
|
+
assemblyOwner: characterInfo,
|
|
125
|
+
energySource,
|
|
104
126
|
});
|
|
105
127
|
|
|
106
128
|
// Only update state if the data changed (optimization for polling)
|
|
@@ -125,24 +147,26 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
125
147
|
);
|
|
126
148
|
}
|
|
127
149
|
|
|
128
|
-
// Transform assembly with
|
|
150
|
+
// Transform assembly with assemblyOwner and datahub info
|
|
129
151
|
const transformed = await transformToAssembly(
|
|
130
152
|
objectId,
|
|
131
153
|
moveObject as MoveObjectData,
|
|
132
154
|
{
|
|
133
155
|
character: characterInfo,
|
|
134
156
|
datahubInfo,
|
|
157
|
+
energySource: energySource,
|
|
158
|
+
destinationGate: destinationGate,
|
|
135
159
|
},
|
|
136
160
|
);
|
|
137
161
|
|
|
138
162
|
setAssembly(transformed);
|
|
139
163
|
|
|
140
|
-
// Transform and set
|
|
164
|
+
// Transform and set assemblyOwner: owner of the assembly
|
|
141
165
|
if (characterInfo) {
|
|
142
166
|
const transformedCharacter = transformToCharacter(characterInfo);
|
|
143
|
-
|
|
167
|
+
setAssemblyOwner(transformedCharacter);
|
|
144
168
|
} else {
|
|
145
|
-
|
|
169
|
+
setAssemblyOwner(null);
|
|
146
170
|
}
|
|
147
171
|
}
|
|
148
172
|
setError(null);
|
|
@@ -158,56 +182,59 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
158
182
|
[],
|
|
159
183
|
);
|
|
160
184
|
|
|
161
|
-
// Initialize the object ID
|
|
185
|
+
// Initialize the object ID (env or query params) and tenant (query params).
|
|
186
|
+
// Tenant comes from URL ?tenant= with fallback DEFAULT_TENANT.
|
|
162
187
|
useEffect(() => {
|
|
163
188
|
console.log("[DappKit] SmartObjectProvider: Checking for item ID");
|
|
164
189
|
|
|
190
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
191
|
+
const queryTenant =
|
|
192
|
+
queryParams.get(QueryParams.TENANT)?.trim() || DEFAULT_TENANT;
|
|
193
|
+
|
|
165
194
|
// Check if an object ID exists in the .env file
|
|
166
|
-
const
|
|
195
|
+
const envObjectId = import.meta.env.VITE_OBJECT_ID;
|
|
167
196
|
|
|
168
|
-
if (
|
|
197
|
+
if (envObjectId) {
|
|
169
198
|
console.log(
|
|
170
|
-
"[DappKit] SmartObjectProvider: Using
|
|
171
|
-
|
|
199
|
+
"[DappKit] SmartObjectProvider: Using Sui object ID from env:",
|
|
200
|
+
envObjectId,
|
|
172
201
|
);
|
|
173
|
-
setSelectedObjectId(
|
|
202
|
+
setSelectedObjectId(envObjectId);
|
|
203
|
+
setSelectedTenant(queryTenant);
|
|
204
|
+
setIsObjectIdDirect(true);
|
|
174
205
|
return;
|
|
175
206
|
}
|
|
176
207
|
|
|
177
|
-
//
|
|
178
|
-
const queryParams = new URLSearchParams(window.location.search);
|
|
208
|
+
// Else, derive object ID from item ID and tenant and passed via query param
|
|
179
209
|
const queryItemId = queryParams.get(QueryParams.ITEM_ID);
|
|
180
|
-
const queryTenant = queryParams.get(QueryParams.TENANT);
|
|
181
210
|
|
|
182
211
|
if (queryItemId) {
|
|
183
212
|
setSelectedObjectId(queryItemId);
|
|
213
|
+
setSelectedTenant(queryTenant);
|
|
214
|
+
setIsObjectIdDirect(false);
|
|
184
215
|
} else {
|
|
185
216
|
console.error("[DappKit] SmartObjectProvider: No object ID provided");
|
|
186
217
|
setLoading(false);
|
|
187
218
|
}
|
|
188
|
-
|
|
189
|
-
if (queryTenant) {
|
|
190
|
-
setSelectedTenant(queryTenant);
|
|
191
|
-
} else {
|
|
192
|
-
console.error("[DappKit] SmartObjectProvider: No tenant provided");
|
|
193
|
-
}
|
|
194
219
|
}, []);
|
|
195
220
|
|
|
196
221
|
// Fetch and poll for object data
|
|
197
222
|
useEffect(() => {
|
|
198
223
|
if (!selectedObjectId || !isConnected) {
|
|
199
|
-
|
|
200
|
-
setLoading(false);
|
|
201
|
-
}
|
|
224
|
+
setLoading(false);
|
|
202
225
|
return;
|
|
203
226
|
}
|
|
204
227
|
|
|
228
|
+
const input: FetchObjectDataInput = isObjectIdDirect
|
|
229
|
+
? { objectId: selectedObjectId }
|
|
230
|
+
: { itemId: selectedObjectId, selectedTenant };
|
|
231
|
+
|
|
205
232
|
// Initial fetch
|
|
206
|
-
fetchObjectData(
|
|
233
|
+
fetchObjectData(input, true);
|
|
207
234
|
|
|
208
235
|
// Set up polling
|
|
209
236
|
pollingRef.current = setInterval(() => {
|
|
210
|
-
fetchObjectData(
|
|
237
|
+
fetchObjectData(input, false);
|
|
211
238
|
}, POLLING_INTERVAL);
|
|
212
239
|
|
|
213
240
|
console.log(
|
|
@@ -223,29 +250,29 @@ const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
|
223
250
|
}
|
|
224
251
|
lastDataHashRef.current = null;
|
|
225
252
|
};
|
|
226
|
-
}, [
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
253
|
+
}, [
|
|
254
|
+
selectedObjectId,
|
|
255
|
+
selectedTenant,
|
|
256
|
+
isObjectIdDirect,
|
|
257
|
+
isConnected,
|
|
258
|
+
fetchObjectData,
|
|
259
|
+
]);
|
|
233
260
|
|
|
234
261
|
const handleRefetch = useCallback(async () => {
|
|
235
|
-
if (selectedObjectId)
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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]);
|
|
239
268
|
|
|
240
269
|
return (
|
|
241
270
|
<SmartObjectContext.Provider
|
|
242
271
|
value={{
|
|
243
272
|
assembly,
|
|
244
|
-
|
|
245
|
-
selectedObjectId,
|
|
273
|
+
assemblyOwner,
|
|
246
274
|
loading,
|
|
247
275
|
error,
|
|
248
|
-
setSelectedObjectId: handleSetSelectedObjectId,
|
|
249
276
|
refetch: handleRefetch,
|
|
250
277
|
}}
|
|
251
278
|
>
|
package/types/contexts.ts
CHANGED
|
@@ -28,11 +28,9 @@ export enum SupportedWallets {
|
|
|
28
28
|
* @category Types */
|
|
29
29
|
export interface SmartObjectContextType {
|
|
30
30
|
assembly: AssemblyType<Assemblies> | null;
|
|
31
|
-
|
|
32
|
-
selectedObjectId: string;
|
|
31
|
+
assemblyOwner: DetailedSmartCharacterResponse | null;
|
|
33
32
|
loading: boolean;
|
|
34
33
|
error: string | null;
|
|
35
|
-
setSelectedObjectId: (id: string) => void;
|
|
36
34
|
refetch: () => Promise<void>;
|
|
37
35
|
}
|
|
38
36
|
|
|
@@ -54,6 +54,7 @@ export const ASSEMBLY_TYPE_API_STRING: Record<Assemblies, string> = {
|
|
|
54
54
|
[Assemblies.NetworkNode]: "network-nodes",
|
|
55
55
|
[Assemblies.Manufacturing]: "manufacturing",
|
|
56
56
|
[Assemblies.Refinery]: "refineries",
|
|
57
|
+
[Assemblies.Assembly]: "assemblies",
|
|
57
58
|
} as const;
|
|
58
59
|
|
|
59
60
|
/** API slug for assembly type in sponsored transaction payloads (e.g. "storage-units"). */
|
package/types/types.ts
CHANGED
|
@@ -73,6 +73,7 @@ export enum Assemblies {
|
|
|
73
73
|
NetworkNode = "NetworkNode",
|
|
74
74
|
Manufacturing = "Manufacturing",
|
|
75
75
|
Refinery = "Refinery",
|
|
76
|
+
Assembly = "Assembly",
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/** @category Types */
|
|
@@ -86,16 +87,18 @@ export type AssemblyType<T extends Assemblies> = {
|
|
|
86
87
|
[K in T]: K extends Assemblies.SmartStorageUnit
|
|
87
88
|
? AssemblyProperties<K> & { storage: StorageModule }
|
|
88
89
|
: K extends Assemblies.SmartTurret
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
? AssemblyProperties<K> & { turret: TurretModule }
|
|
91
|
+
: K extends Assemblies.SmartGate
|
|
92
|
+
? AssemblyProperties<K> & { gate: GateModule }
|
|
93
|
+
: K extends Assemblies.NetworkNode
|
|
94
|
+
? AssemblyProperties<K> & { networkNode: NetworkNodeModule }
|
|
95
|
+
: K extends Assemblies.Refinery
|
|
96
|
+
? AssemblyProperties<K> & { refinery: RefineryModule }
|
|
97
|
+
: K extends Assemblies.Manufacturing
|
|
98
|
+
? AssemblyProperties<K> & { manufacturing: ManufacturingModule }
|
|
99
|
+
: K extends Assemblies.Assembly
|
|
100
|
+
? AssemblyProperties<K>
|
|
101
|
+
: never;
|
|
99
102
|
}[T];
|
|
100
103
|
|
|
101
104
|
// =========================================
|
|
@@ -111,3 +114,42 @@ export interface DetailedSmartCharacterResponse {
|
|
|
111
114
|
smartAssemblies: Assemblies[];
|
|
112
115
|
portrait: string;
|
|
113
116
|
}
|
|
117
|
+
|
|
118
|
+
// =========================================
|
|
119
|
+
// Datahub Game Info
|
|
120
|
+
// =========================================
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Game item/type information from the EVE Frontier Datahub API.
|
|
124
|
+
*
|
|
125
|
+
* Contains metadata about items, assemblies, and other game objects
|
|
126
|
+
* including display names, descriptions, icons, and physical properties.
|
|
127
|
+
*
|
|
128
|
+
* @category Types
|
|
129
|
+
*/
|
|
130
|
+
export interface DatahubGameInfo {
|
|
131
|
+
/** The type ID (matches on-chain type_id) */
|
|
132
|
+
id: number;
|
|
133
|
+
/** Display name of the item/type */
|
|
134
|
+
name: string;
|
|
135
|
+
/** Description text */
|
|
136
|
+
description: string;
|
|
137
|
+
/** Mass in kg */
|
|
138
|
+
mass: number;
|
|
139
|
+
/** Radius in meters */
|
|
140
|
+
radius: number;
|
|
141
|
+
/** Volume in cubic meters */
|
|
142
|
+
volume: number;
|
|
143
|
+
/** Portion size for stacking */
|
|
144
|
+
portionSize: number;
|
|
145
|
+
/** Category group name (e.g., "Structures") */
|
|
146
|
+
groupName: string;
|
|
147
|
+
/** Category group ID */
|
|
148
|
+
groupId: number;
|
|
149
|
+
/** Top-level category name */
|
|
150
|
+
categoryName: string;
|
|
151
|
+
/** Top-level category ID */
|
|
152
|
+
categoryId: number;
|
|
153
|
+
/** URL to the item's icon image */
|
|
154
|
+
iconUrl: string;
|
|
155
|
+
}
|