@evefrontier/dapp-kit 0.1.2 → 0.1.5
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/README.md +13 -0
- package/graphql/client.ts +96 -24
- package/graphql/index.ts +5 -39
- package/graphql/queries.ts +157 -1
- package/graphql/types.ts +188 -155
- package/hooks/index.ts +1 -0
- package/hooks/useSponsoredTransaction.ts +11 -4
- package/index.ts +7 -71
- package/package.json +11 -1
- package/providers/SmartObjectProvider.tsx +17 -17
- package/types/contexts.ts +1 -1
- package/types/sponsoredTransaction.ts +9 -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 +27 -31
- package/wallet/features.ts +5 -5
- package/CHANGELOG.md +0 -13
- package/docs/api/.nojekyll +0 -1
- package/docs/api/assets/hierarchy.js +0 -1
- package/docs/api/assets/highlight.css +0 -120
- package/docs/api/assets/icons.js +0 -18
- package/docs/api/assets/icons.svg +0 -1
- package/docs/api/assets/main.js +0 -60
- package/docs/api/assets/navigation.js +0 -1
- package/docs/api/assets/search.js +0 -1
- package/docs/api/assets/style.css +0 -1633
- package/docs/api/classes/WalletNoAccountSelectedError.html +0 -3
- package/docs/api/classes/WalletNotConnectedError.html +0 -3
- package/docs/api/classes/WalletSponsoredTransactionNotSupportedError.html +0 -5
- package/docs/api/enums/ActionTypes.html +0 -6
- package/docs/api/enums/Assemblies.html +0 -7
- package/docs/api/enums/QueryParams.html +0 -3
- package/docs/api/enums/Severity.html +0 -5
- package/docs/api/enums/SponsoredTransactionActions.html +0 -7
- package/docs/api/enums/State.html +0 -6
- package/docs/api/enums/SupportedWallets.html +0 -3
- package/docs/api/enums/TYPEIDS.html +0 -15
- package/docs/api/functions/EveFrontierProvider.html +0 -11
- package/docs/api/functions/NotificationProvider.html +0 -2
- package/docs/api/functions/SmartObjectProvider.html +0 -10
- package/docs/api/functions/VaultProvider.html +0 -1
- package/docs/api/functions/abbreviateAddress.html +0 -11
- package/docs/api/functions/assertAssemblyType.html +0 -9
- package/docs/api/functions/clickToCopy.html +0 -1
- package/docs/api/functions/executeGraphQLQuery.html +0 -12
- package/docs/api/functions/findOwnerByAddress.html +0 -5
- package/docs/api/functions/formatDuration.html +0 -8
- package/docs/api/functions/formatM3.html +0 -8
- package/docs/api/functions/getAssemblyType.html +0 -4
- package/docs/api/functions/getAssemblyTypeApiString.html +0 -2
- package/docs/api/functions/getAssemblyWithOwner.html +0 -18
- package/docs/api/functions/getCharacterOwnerCapType.html +0 -3
- package/docs/api/functions/getCommonItems.html +0 -1
- package/docs/api/functions/getDappUrl.html +0 -7
- package/docs/api/functions/getDatahubGameInfo.html +0 -13
- package/docs/api/functions/getEnv.html +0 -1
- package/docs/api/functions/getEveWorldPackageId.html +0 -4
- package/docs/api/functions/getObjectByAddress.html +0 -9
- package/docs/api/functions/getObjectId.html +0 -4
- package/docs/api/functions/getObjectOwnerAndOwnedObjectsByType.html +0 -10
- package/docs/api/functions/getObjectRegistryType.html +0 -3
- package/docs/api/functions/getObjectWithDynamicFields.html +0 -10
- package/docs/api/functions/getObjectWithJson.html +0 -9
- package/docs/api/functions/getObjectsByType.html +0 -12
- package/docs/api/functions/getOwnedObjectsByPackage.html +0 -10
- package/docs/api/functions/getOwnedObjectsByType.html +0 -10
- package/docs/api/functions/getRegistryAddress.html +0 -3
- package/docs/api/functions/getSingletonObjectByType.html +0 -9
- package/docs/api/functions/getSponsoredTransactionFeature.html +0 -11
- package/docs/api/functions/getSuiGraphqlEndpoint.html +0 -4
- package/docs/api/functions/getTxUrl.html +0 -8
- package/docs/api/functions/getVolumeM3.html +0 -5
- package/docs/api/functions/hasSponsoredTransactionFeature.html +0 -3
- package/docs/api/functions/isOwner.html +0 -10
- package/docs/api/functions/parseErrorFromMessage.html +0 -1
- package/docs/api/functions/parseStatus.html +0 -2
- package/docs/api/functions/parseURL.html +0 -1
- package/docs/api/functions/removeTrailingZeros.html +0 -1
- package/docs/api/functions/transformToAssembly.html +0 -5
- package/docs/api/functions/transformToCharacter.html +0 -2
- package/docs/api/functions/useConnection.html +0 -21
- package/docs/api/functions/useNotification.html +0 -28
- package/docs/api/functions/useSmartObject.html +0 -21
- package/docs/api/functions/useSponsoredTransaction.html +0 -50
- package/docs/api/functions/walletSupportsSponsoredTransaction.html +0 -13
- package/docs/api/hierarchy.html +0 -1
- package/docs/api/index.html +0 -24
- package/docs/api/interfaces/AddressOwner.html +0 -2
- package/docs/api/interfaces/AddressOwnerWithJson.html +0 -2
- package/docs/api/interfaces/AssemblyProperties.html +0 -14
- package/docs/api/interfaces/CharacterInfo.html +0 -8
- package/docs/api/interfaces/DatahubGameInfo.html +0 -30
- package/docs/api/interfaces/DetailedAssemblyResponse.html +0 -14
- package/docs/api/interfaces/DetailedSmartCharacterResponse.html +0 -7
- package/docs/api/interfaces/DynamicFieldNode.html +0 -3
- package/docs/api/interfaces/EphemeralInventory.html +0 -6
- package/docs/api/interfaces/EveFrontierSponsoredTransactionFeature.html +0 -7
- package/docs/api/interfaces/GameTypeResponse.html +0 -13
- package/docs/api/interfaces/GateModule.html +0 -5
- package/docs/api/interfaces/GetObjectByAddressResponse.html +0 -2
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsResponse.html +0 -2
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsWithJsonResponse.html +0 -2
- package/docs/api/interfaces/GetObjectResponse.html +0 -2
- package/docs/api/interfaces/GetObjectWithJsonResponse.html +0 -2
- package/docs/api/interfaces/GetObjectsByTypeResponse.html +0 -2
- package/docs/api/interfaces/GetOwnedObjectsByPackageResponse.html +0 -2
- package/docs/api/interfaces/GetOwnedObjectsByTypeResponse.html +0 -2
- package/docs/api/interfaces/GetSingletonObjectByTypeResponse.html +0 -2
- package/docs/api/interfaces/GraphQLResponse.html +0 -3
- package/docs/api/interfaces/InventoryItem.html +0 -8
- package/docs/api/interfaces/ManufacturingModule.html +0 -2
- package/docs/api/interfaces/MoveObjectContents.html +0 -4
- package/docs/api/interfaces/MoveObjectData.html +0 -3
- package/docs/api/interfaces/NetworkNodeModule.html +0 -6
- package/docs/api/interfaces/NotificationContextType.html +0 -4
- package/docs/api/interfaces/NotificationState.html +0 -6
- package/docs/api/interfaces/Notify.html +0 -6
- package/docs/api/interfaces/ObjectWithContentsNode.html +0 -4
- package/docs/api/interfaces/OwnedObjectAddressNode.html +0 -2
- package/docs/api/interfaces/OwnedObjectFullNode.html +0 -4
- package/docs/api/interfaces/OwnedObjectNode.html +0 -3
- package/docs/api/interfaces/OwnedObjectNodeWithJson.html +0 -4
- package/docs/api/interfaces/OwnerCapData.html +0 -5
- package/docs/api/interfaces/PageInfo.html +0 -3
- package/docs/api/interfaces/RawCharacterData.html +0 -8
- package/docs/api/interfaces/RawSuiObjectData.html +0 -21
- package/docs/api/interfaces/RefineryModule.html +0 -2
- package/docs/api/interfaces/SmartAssemblyResponse.html +0 -11
- package/docs/api/interfaces/SmartObjectContextType.html +0 -7
- package/docs/api/interfaces/SponsoredTransactionInput.html +0 -14
- package/docs/api/interfaces/SponsoredTransactionOutput.html +0 -8
- package/docs/api/interfaces/StorageModule.html +0 -4
- package/docs/api/interfaces/SuiObjectResponse.html +0 -5
- package/docs/api/interfaces/TransformOptions.html +0 -8
- package/docs/api/interfaces/TurretModule.html +0 -2
- package/docs/api/interfaces/VaultContextType.html +0 -8
- package/docs/api/modules.html +0 -1
- package/docs/api/types/AssemblyType.html +0 -1
- package/docs/api/types/ErrorType.html +0 -5
- package/docs/api/types/SendSponsoredTransactionFn.html +0 -1
- package/docs/api/types/SponsoredTransactionArgs.html +0 -2
- package/docs/api/types/SponsoredTransactionAssemblyType.html +0 -2
- package/docs/api/types/SponsoredTransactionMethod.html +0 -2
- package/docs/api/types/UseSponsoredTransactionArgs.html +0 -3
- package/docs/api/types/UseSponsoredTransactionError.html +0 -2
- package/docs/api/types/UseSponsoredTransactionMutationOptions.html +0 -2
- package/docs/api/variables/ASSEMBLY_TYPE_API_STRING.html +0 -2
- package/docs/api/variables/ERRORS.html +0 -1
- package/docs/api/variables/ERROR_MESSAGES.html +0 -1
- package/docs/api/variables/EVEFRONTIER_SPONSORED_TRANSACTION.html +0 -4
- package/docs/api/variables/EXCLUDED_TYPEIDS.html +0 -1
- package/docs/api/variables/GET_OBJECTS_BY_TYPE.html +0 -3
- package/docs/api/variables/GET_OBJECT_BY_ADDRESS.html +0 -3
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE.html +0 -4
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON.html +0 -3
- package/docs/api/variables/GET_OBJECT_WITH_DYNAMIC_FIELDS.html +0 -4
- package/docs/api/variables/GET_OBJECT_WITH_JSON.html +0 -3
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_PACKAGE.html +0 -3
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_TYPE.html +0 -3
- package/docs/api/variables/GET_SINGLETON_OBJECT_BY_TYPE.html +0 -3
- package/docs/api/variables/NotificationContext.html +0 -1
- package/docs/api/variables/ONE_M3.html +0 -2
- package/docs/api/variables/POLLING_INTERVAL.html +0 -2
- package/docs/api/variables/STORAGE_KEYS.html +0 -2
- package/docs/api/variables/SmartObjectContext.html +0 -1
- package/docs/api/variables/VaultContext.html +0 -1
- package/docs/api/variables/dAppKit.html +0 -2
- package/tsconfig.json +0 -22
- package/typedoc.json +0 -38
- package/vite-env.d.ts +0 -14
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CharacterInfo, RawCharacterData } from "../graphql/types";
|
|
2
|
+
|
|
3
|
+
function parseOptionalInt(value: unknown): number {
|
|
4
|
+
if (value == null) return 0;
|
|
5
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
const n = parseInt(value, 10);
|
|
8
|
+
return Number.isNaN(n) ? 0 : n;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Normalize raw character JSON (from wallet/assembly GQL responses) into CharacterInfo.
|
|
15
|
+
* Accepts varying shapes; returns null when input is not a usable object.
|
|
16
|
+
*
|
|
17
|
+
* @param json - Raw JSON (e.g. from contents.json or extract...contents.json)
|
|
18
|
+
* @returns CharacterInfo or null
|
|
19
|
+
* @category Character Helpers
|
|
20
|
+
*/
|
|
21
|
+
export function parseCharacterFromJson(json: unknown): CharacterInfo | null {
|
|
22
|
+
if (json == null || typeof json !== "object" || Array.isArray(json)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const obj = json as Record<string, unknown>;
|
|
26
|
+
const metadata =
|
|
27
|
+
obj.metadata != null &&
|
|
28
|
+
typeof obj.metadata === "object" &&
|
|
29
|
+
!Array.isArray(obj.metadata)
|
|
30
|
+
? (obj.metadata as Record<string, unknown>)
|
|
31
|
+
: undefined;
|
|
32
|
+
const key =
|
|
33
|
+
obj.key != null && typeof obj.key === "object" && !Array.isArray(obj.key)
|
|
34
|
+
? (obj.key as Record<string, unknown>)
|
|
35
|
+
: undefined;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
id: typeof obj.id === "string" ? obj.id : "",
|
|
39
|
+
address:
|
|
40
|
+
typeof obj.character_address === "string" ? obj.character_address : "",
|
|
41
|
+
name: typeof metadata?.name === "string" ? metadata.name : "",
|
|
42
|
+
tribeId: parseOptionalInt(obj.tribe_id),
|
|
43
|
+
characterId: parseOptionalInt(key?.item_id),
|
|
44
|
+
_raw: json as RawCharacterData,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getCharacterAndOwnedObjects } from "../graphql/client";
|
|
2
|
+
import type { GetCharacterAndOwnedObjectsResponse } from "../graphql/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the JSON payloads from the first character's owned objects
|
|
6
|
+
* (from getCharacterAndOwnedObjects response data).
|
|
7
|
+
*
|
|
8
|
+
* @param data - Response data from getCharacterAndOwnedObjects
|
|
9
|
+
* @returns Array of contents.json for each owned object, or undefined if missing
|
|
10
|
+
*
|
|
11
|
+
* @category Character Helpers
|
|
12
|
+
*/
|
|
13
|
+
export function getCharacterOwnedObjectsJson(
|
|
14
|
+
data: GetCharacterAndOwnedObjectsResponse | undefined,
|
|
15
|
+
): Record<string, unknown>[] | undefined {
|
|
16
|
+
const objects =
|
|
17
|
+
data?.address?.objects?.nodes?.[0]?.contents?.extract?.asAddress?.objects;
|
|
18
|
+
if (!objects?.nodes?.length) return undefined;
|
|
19
|
+
return objects.nodes.map(
|
|
20
|
+
(node) =>
|
|
21
|
+
node.contents.extract.asAddress.asObject.asMoveObject.contents.json,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Fetches the character and owned objects for an address, then returns the JSON
|
|
27
|
+
* payloads of the first character's owned objects.
|
|
28
|
+
*
|
|
29
|
+
* @param address - Wallet/signer address to query
|
|
30
|
+
* @returns Promise resolving to an array of contents.json per owned object, or undefined if none
|
|
31
|
+
*
|
|
32
|
+
* @category Character Helpers
|
|
33
|
+
*/
|
|
34
|
+
export async function getCharacterOwnedObjects(
|
|
35
|
+
address: string,
|
|
36
|
+
): Promise<Record<string, unknown>[] | undefined> {
|
|
37
|
+
const response = await getCharacterAndOwnedObjects(address).then(
|
|
38
|
+
(response) => {
|
|
39
|
+
const data = response.data;
|
|
40
|
+
if (!data) {
|
|
41
|
+
console.warn(
|
|
42
|
+
"[Dapp] No data returned from getCharacterAndOwnedObjects",
|
|
43
|
+
);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const ownedObjectsJson = getCharacterOwnedObjectsJson(data);
|
|
47
|
+
return ownedObjectsJson;
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return response;
|
|
52
|
+
}
|
package/utils/config.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { getSingletonConfigObjectByType } from "../graphql/client";
|
|
2
|
+
import { getEnergyConfigType, getFuelEfficiencyConfigType } from "./constants";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Cached energy config: type_id -> energy usage (e.g. energy_constant).
|
|
6
|
+
* Populated from the on-chain EnergyConfig singleton.
|
|
7
|
+
*/
|
|
8
|
+
let energyConfigCache: Record<number, number> | null = null;
|
|
9
|
+
let fuelEfficiencyConfigCache: Record<number, number> | null = null;
|
|
10
|
+
|
|
11
|
+
/** In-flight promise for energy config so concurrent callers share one fetch. */
|
|
12
|
+
let energyConfigInFlight: Promise<Record<number, number>> | null = null;
|
|
13
|
+
/** In-flight promise for fuel efficiency config so concurrent callers share one fetch. */
|
|
14
|
+
let fuelEfficiencyConfigInFlight: Promise<Record<number, number>> | null = null;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resets in-memory and in-flight caches. Only for use in tests.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export function resetConfigCachesForTesting(): void {
|
|
21
|
+
energyConfigCache = null;
|
|
22
|
+
fuelEfficiencyConfigCache = null;
|
|
23
|
+
energyConfigInFlight = null;
|
|
24
|
+
fuelEfficiencyConfigInFlight = null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parses EnergyConfig or FuelConfig object JSON (contents + dynamic fields) into a map of typeId -> value (e.g. energy_constant or fuel_efficiency).
|
|
29
|
+
* Supports:
|
|
30
|
+
* - Dynamic fields where name is type_id (string/number) and contents.json has value
|
|
31
|
+
* - contents.json with a table/map of type_id -> value
|
|
32
|
+
*/
|
|
33
|
+
function parseConfig(
|
|
34
|
+
configJson: Record<string, unknown> | undefined,
|
|
35
|
+
): Record<number, number> {
|
|
36
|
+
const byTypeId: Record<number, number> = {};
|
|
37
|
+
const nodes = configJson as unknown as
|
|
38
|
+
| Array<{ key: { json: string }; value: { json: string } }>
|
|
39
|
+
| undefined;
|
|
40
|
+
if (!Array.isArray(nodes) || !nodes.length) return byTypeId;
|
|
41
|
+
for (const node of nodes) {
|
|
42
|
+
const typeId = parseInt(node.key?.json ?? "", 10);
|
|
43
|
+
if (Number.isNaN(typeId)) continue;
|
|
44
|
+
const energy = parseInt(node.value?.json ?? "", 10);
|
|
45
|
+
byTypeId[typeId] = Number.isNaN(energy) ? 0 : energy;
|
|
46
|
+
}
|
|
47
|
+
return byTypeId;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Fetches the EnergyConfig singleton via GraphQL (using getEnergyConfigType), parses it,
|
|
52
|
+
* caches the result, and returns the map of type_id -> energy usage.
|
|
53
|
+
* Subsequent calls return the cached map.
|
|
54
|
+
*
|
|
55
|
+
* @category Utilities
|
|
56
|
+
*/
|
|
57
|
+
export async function getEnergyConfig(): Promise<Record<number, number>> {
|
|
58
|
+
if (energyConfigCache) {
|
|
59
|
+
return energyConfigCache;
|
|
60
|
+
}
|
|
61
|
+
if (energyConfigInFlight) {
|
|
62
|
+
return energyConfigInFlight;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
energyConfigInFlight = (async () => {
|
|
66
|
+
const result = await getSingletonConfigObjectByType(
|
|
67
|
+
getEnergyConfigType(),
|
|
68
|
+
"assembly_energy",
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const energyConfigJson = result.data?.objects?.nodes[0]?.asMoveObject
|
|
72
|
+
?.contents?.extract?.extract?.asAddress?.addressAt?.dynamicFields
|
|
73
|
+
?.nodes as Record<string, unknown> | undefined;
|
|
74
|
+
|
|
75
|
+
energyConfigCache = parseConfig(energyConfigJson);
|
|
76
|
+
return energyConfigCache;
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
return await energyConfigInFlight;
|
|
81
|
+
} finally {
|
|
82
|
+
energyConfigInFlight = null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Fetches the Fuel Efficiency Config singleton via GraphQL (using getFuelEfficiencyConfigType), parses it,
|
|
88
|
+
* caches the result, and returns the map of type_id -> fuel efficiency.
|
|
89
|
+
* Subsequent calls return the cached map.
|
|
90
|
+
*
|
|
91
|
+
* @category Utilities
|
|
92
|
+
*/
|
|
93
|
+
export async function getFuelEfficiencyConfig(): Promise<
|
|
94
|
+
Record<number, number>
|
|
95
|
+
> {
|
|
96
|
+
if (fuelEfficiencyConfigCache) {
|
|
97
|
+
return fuelEfficiencyConfigCache;
|
|
98
|
+
}
|
|
99
|
+
if (fuelEfficiencyConfigInFlight) {
|
|
100
|
+
return fuelEfficiencyConfigInFlight;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fuelEfficiencyConfigInFlight = (async () => {
|
|
104
|
+
const result = await getSingletonConfigObjectByType(
|
|
105
|
+
getFuelEfficiencyConfigType(),
|
|
106
|
+
"fuel_efficiency",
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const fuelEfficiencyConfigJson = result.data?.objects?.nodes[0]
|
|
110
|
+
?.asMoveObject?.contents?.extract?.extract?.asAddress?.addressAt
|
|
111
|
+
?.dynamicFields?.nodes as Record<string, unknown> | undefined;
|
|
112
|
+
|
|
113
|
+
fuelEfficiencyConfigCache = parseConfig(fuelEfficiencyConfigJson);
|
|
114
|
+
return fuelEfficiencyConfigCache;
|
|
115
|
+
})();
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
return await fuelEfficiencyConfigInFlight;
|
|
119
|
+
} finally {
|
|
120
|
+
fuelEfficiencyConfigInFlight = null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Returns the energy usage for a given assembly type ID from the on-chain EnergyConfig.
|
|
126
|
+
* Uses cached EnergyConfig data after the first fetch.
|
|
127
|
+
*
|
|
128
|
+
* @param typeId - In-game type ID (e.g. from rawData.type_id)
|
|
129
|
+
* @returns Energy usage (e.g. energy_constant), or 0 if not found or not yet loaded
|
|
130
|
+
* @category Utilities
|
|
131
|
+
*/
|
|
132
|
+
export async function getEnergyUsageForType(typeId: number): Promise<number> {
|
|
133
|
+
const config = await getEnergyConfig();
|
|
134
|
+
|
|
135
|
+
return config[typeId] ?? 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns the fuel efficiency for a given assembly type ID from the on-chain Fuel Efficiency Config.
|
|
140
|
+
* Uses cached Fuel Efficiency Config data after the first fetch.
|
|
141
|
+
*
|
|
142
|
+
* @param typeId - In-game type ID (e.g. from rawData.type_id)
|
|
143
|
+
* @returns Fuel efficiency (e.g. fuel_efficiency), or 0 if not found or not yet loaded
|
|
144
|
+
* @category Utilities
|
|
145
|
+
*/
|
|
146
|
+
export async function getFuelEfficiencyForType(
|
|
147
|
+
typeId: number,
|
|
148
|
+
): Promise<number> {
|
|
149
|
+
const config = await getFuelEfficiencyConfig();
|
|
150
|
+
return config[typeId] ?? 0;
|
|
151
|
+
}
|
package/utils/constants.ts
CHANGED
|
@@ -50,6 +50,16 @@ export const getCharacterOwnerCapType = (): string => {
|
|
|
50
50
|
return `${pkg}::access::OwnerCap<${pkg}::character::Character>`;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Get the Character PlayerProfile type string (derived from package ID).
|
|
55
|
+
* @returns The fully qualified type string for Character PlayerProfile
|
|
56
|
+
* @category Utilities
|
|
57
|
+
*/
|
|
58
|
+
export const getCharacterPlayerProfileType = (): string => {
|
|
59
|
+
const pkg = getEveWorldPackageId();
|
|
60
|
+
return `${pkg}::character::PlayerProfile`;
|
|
61
|
+
};
|
|
62
|
+
|
|
53
63
|
/**
|
|
54
64
|
* Get the ObjectRegistry type string (derived from package ID).
|
|
55
65
|
* @returns The fully qualified type string for ObjectRegistry
|
|
@@ -58,15 +68,37 @@ export const getCharacterOwnerCapType = (): string => {
|
|
|
58
68
|
export const getObjectRegistryType = (): string =>
|
|
59
69
|
`${getEveWorldPackageId()}::object_registry::ObjectRegistry`;
|
|
60
70
|
|
|
61
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Get the EnergyConfig type string (derived from package ID).
|
|
73
|
+
* @returns The fully qualified type string for Energy Config
|
|
74
|
+
* @category Utilities
|
|
75
|
+
*/
|
|
76
|
+
export const getEnergyConfigType = (): string =>
|
|
77
|
+
`${getEveWorldPackageId()}::energy::EnergyConfig`;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the Fuel Efficiency Config type string (derived from package ID).
|
|
81
|
+
* @returns The fully qualified type string for Fuel Efficiency Config
|
|
82
|
+
* @category Utilities
|
|
83
|
+
*/
|
|
84
|
+
export const getFuelEfficiencyConfigType = (): string =>
|
|
85
|
+
`${getEveWorldPackageId()}::fuel::FuelConfig`;
|
|
86
|
+
|
|
87
|
+
/** Polling interval in milliseconds (10 seconds).
|
|
88
|
+
* @category Constants
|
|
89
|
+
*/
|
|
62
90
|
export const POLLING_INTERVAL = 10000;
|
|
63
91
|
|
|
64
|
-
/** Local storage keys.
|
|
92
|
+
/** Local storage keys.
|
|
93
|
+
* @category Constants
|
|
94
|
+
*/
|
|
65
95
|
export const STORAGE_KEYS = {
|
|
66
96
|
CONNECTED: "eve-dapp-connected",
|
|
67
97
|
} as const;
|
|
68
98
|
|
|
69
|
-
/** Type IDs for in-game items.
|
|
99
|
+
/** Type IDs for in-game items.
|
|
100
|
+
* @category Constants
|
|
101
|
+
*/
|
|
70
102
|
/* eslint-disable @typescript-eslint/no-loss-of-precision */
|
|
71
103
|
export enum TYPEIDS {
|
|
72
104
|
LENS = 77518,
|
|
@@ -84,7 +116,7 @@ export enum TYPEIDS {
|
|
|
84
116
|
REFUGE = 87160,
|
|
85
117
|
}
|
|
86
118
|
|
|
87
|
-
/** @category
|
|
119
|
+
/** @category Constants */
|
|
88
120
|
export const EXCLUDED_TYPEIDS = [
|
|
89
121
|
TYPEIDS.PORTABLE_REFINERY,
|
|
90
122
|
TYPEIDS.PORTABLE_PRINTER,
|
|
@@ -92,5 +124,7 @@ export const EXCLUDED_TYPEIDS = [
|
|
|
92
124
|
TYPEIDS.REFUGE,
|
|
93
125
|
];
|
|
94
126
|
|
|
95
|
-
/** Volume - from wei units to m3.
|
|
127
|
+
/** Volume - from wei units to m3.
|
|
128
|
+
* @category Constants
|
|
129
|
+
*/
|
|
96
130
|
export const ONE_M3 = 1000000000000000000;
|
package/utils/datahub.ts
CHANGED
|
@@ -1,42 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Game item/type information from the EVE Frontier Datahub API.
|
|
3
|
-
*
|
|
4
|
-
* Contains metadata about items, assemblies, and other game objects
|
|
5
|
-
* including display names, descriptions, icons, and physical properties.
|
|
6
|
-
*
|
|
7
|
-
* @category Types
|
|
8
|
-
*/
|
|
9
|
-
export interface DatahubGameInfo {
|
|
10
|
-
/** The type ID (matches on-chain type_id) */
|
|
11
|
-
id: number;
|
|
12
|
-
/** Display name of the item/type */
|
|
13
|
-
name: string;
|
|
14
|
-
/** Description text */
|
|
15
|
-
description: string;
|
|
16
|
-
/** Mass in kg */
|
|
17
|
-
mass: number;
|
|
18
|
-
/** Radius in meters */
|
|
19
|
-
radius: number;
|
|
20
|
-
/** Volume in cubic meters */
|
|
21
|
-
volume: number;
|
|
22
|
-
/** Portion size for stacking */
|
|
23
|
-
portionSize: number;
|
|
24
|
-
/** Category group name (e.g., "Structures") */
|
|
25
|
-
groupName: string;
|
|
26
|
-
/** Category group ID */
|
|
27
|
-
groupId: number;
|
|
28
|
-
/** Top-level category name */
|
|
29
|
-
categoryName: string;
|
|
30
|
-
/** Top-level category ID */
|
|
31
|
-
categoryId: number;
|
|
32
|
-
/** URL to the item's icon image */
|
|
33
|
-
iconUrl: string;
|
|
34
|
-
/** Additional type-specific attributes */
|
|
35
|
-
attributes?: {
|
|
36
|
-
energyConstant?: number;
|
|
37
|
-
[key: string]: unknown;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
1
|
+
import { DatahubGameInfo } from "../types";
|
|
40
2
|
|
|
41
3
|
/**
|
|
42
4
|
* Fetch game type information from the EVE Frontier Datahub API.
|
|
@@ -65,10 +27,10 @@ export interface DatahubGameInfo {
|
|
|
65
27
|
* ```
|
|
66
28
|
*/
|
|
67
29
|
export async function getDatahubGameInfo(
|
|
68
|
-
typeId: number
|
|
30
|
+
typeId: number,
|
|
69
31
|
): Promise<DatahubGameInfo> {
|
|
70
32
|
const response = await fetch(
|
|
71
|
-
`https://world-api-stillness.live.tech.evefrontier.com/v2/types/${typeId}
|
|
33
|
+
`https://world-api-stillness.live.tech.evefrontier.com/v2/types/${typeId}`,
|
|
72
34
|
);
|
|
73
35
|
const data = await response.json();
|
|
74
36
|
|
package/utils/errors.ts
CHANGED
|
@@ -137,7 +137,7 @@ ERRORS.CALLFROM_NOT_FOUND = ERRORS[2006];
|
|
|
137
137
|
ERRORS.INSUFFICIENT_EVE = ERRORS[3002];
|
|
138
138
|
ERRORS.LENS_UNAVAILABLE = ERRORS[5001];
|
|
139
139
|
|
|
140
|
-
/** @category
|
|
140
|
+
/** @category Constants */
|
|
141
141
|
export const ERROR_MESSAGES: Record<number, string> = Object.fromEntries(
|
|
142
142
|
Object.entries(ERRORS)
|
|
143
143
|
.filter(([key]) => /^\d+$/.test(key))
|
package/utils/index.ts
CHANGED
|
@@ -5,12 +5,21 @@ export {
|
|
|
5
5
|
getObjectId,
|
|
6
6
|
getRegistryAddress,
|
|
7
7
|
} from "./mapping";
|
|
8
|
+
export { getEnergyUsageForType, getFuelEfficiencyForType } from "./config";
|
|
9
|
+
export {
|
|
10
|
+
getAdjustedBurnRate,
|
|
11
|
+
type AdjustedBurnRate,
|
|
12
|
+
} from "./burnRate";
|
|
13
|
+
export { parseCharacterFromJson } from "./character";
|
|
14
|
+
export {
|
|
15
|
+
getCharacterOwnedObjectsJson,
|
|
16
|
+
getCharacterOwnedObjects,
|
|
17
|
+
} from "./characterOwnedObjects";
|
|
8
18
|
export { transformToAssembly, transformToCharacter } from "./transforms";
|
|
9
19
|
export type { TransformOptions } from "./transforms";
|
|
10
20
|
|
|
11
21
|
// Datahub utilities
|
|
12
22
|
export { getDatahubGameInfo } from "./datahub";
|
|
13
|
-
export type { DatahubGameInfo } from "./datahub";
|
|
14
23
|
|
|
15
24
|
// General utilities
|
|
16
25
|
export {
|
package/utils/mapping.ts
CHANGED
|
@@ -54,9 +54,12 @@ export function getAssemblyType(typeRepr: string): Assemblies {
|
|
|
54
54
|
if (typeRepr.includes("::refinery::Refinery")) {
|
|
55
55
|
return Assemblies.Refinery;
|
|
56
56
|
}
|
|
57
|
+
if (typeRepr.includes("::assembly::Assembly")) {
|
|
58
|
+
return Assemblies.Assembly;
|
|
59
|
+
}
|
|
57
60
|
|
|
58
|
-
// Assembly type not found, return default
|
|
59
|
-
return Assemblies.
|
|
61
|
+
// Assembly type not found, return default Assembly
|
|
62
|
+
return Assemblies.Assembly;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
// Cache for the Registry address
|
package/utils/transforms.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
DetailedSmartCharacterResponse,
|
|
6
6
|
SmartAssemblyResponse,
|
|
7
7
|
InventoryItem,
|
|
8
|
+
DatahubGameInfo,
|
|
9
|
+
DetailedAssemblyResponse,
|
|
8
10
|
} from "../types";
|
|
9
11
|
import type {
|
|
10
12
|
MoveObjectData,
|
|
@@ -12,7 +14,8 @@ import type {
|
|
|
12
14
|
CharacterInfo,
|
|
13
15
|
} from "../graphql/types";
|
|
14
16
|
import { getAssemblyType, parseStatus } from "./mapping";
|
|
15
|
-
import { getDatahubGameInfo
|
|
17
|
+
import { getDatahubGameInfo } from "./datahub";
|
|
18
|
+
import { getEnergyConfig, getEnergyUsageForType } from "./config";
|
|
16
19
|
import { getObjectWithJson } from "../graphql";
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -43,6 +46,8 @@ export interface TransformOptions {
|
|
|
43
46
|
datahubInfo?: DatahubGameInfo | null;
|
|
44
47
|
/** Energy source information */
|
|
45
48
|
energySource?: RawSuiObjectData | null;
|
|
49
|
+
/** Destination gate information, if Smart Gate */
|
|
50
|
+
destinationGate?: RawSuiObjectData | null;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/**
|
|
@@ -86,9 +91,10 @@ export async function transformToAssembly(
|
|
|
86
91
|
// Build base assembly properties
|
|
87
92
|
const state = parseStatus(rawData.status?.status?.["@variant"]);
|
|
88
93
|
|
|
89
|
-
// Use pre-fetched datahub info for defaults
|
|
94
|
+
// Use pre-fetched datahub info for defaults (name, description, image); energy from on-chain EnergyConfig
|
|
90
95
|
const datahubInfo = options?.datahubInfo;
|
|
91
96
|
const energySource = options?.energySource;
|
|
97
|
+
const energyUsage = await getEnergyUsageForType(parseInt(typeId, 10) || 0);
|
|
92
98
|
|
|
93
99
|
const parentState = parseStatus(energySource?.status?.status?.["@variant"]);
|
|
94
100
|
|
|
@@ -99,22 +105,24 @@ export async function transformToAssembly(
|
|
|
99
105
|
name: rawData.metadata?.name || "",
|
|
100
106
|
description: rawData.metadata?.description || "",
|
|
101
107
|
dappURL: rawData.metadata?.url || "",
|
|
102
|
-
energySourceId:
|
|
108
|
+
energySourceId:
|
|
109
|
+
assemblyType === Assemblies.NetworkNode
|
|
110
|
+
? undefined
|
|
111
|
+
: energySource?.id || rawData.energy_source_id || "", // Parent network node ID
|
|
112
|
+
isParentNodeOnline:
|
|
113
|
+
assemblyType === Assemblies.NetworkNode
|
|
114
|
+
? undefined
|
|
115
|
+
: parentState === State.ONLINE, // Defined in all cases except network nodes
|
|
103
116
|
state,
|
|
104
117
|
typeId: parseInt(typeId, 10) || 0,
|
|
105
|
-
energyUsage
|
|
106
|
-
location: {
|
|
107
|
-
x: 0,
|
|
108
|
-
y: 0,
|
|
109
|
-
z: 0,
|
|
110
|
-
},
|
|
118
|
+
energyUsage,
|
|
111
119
|
typeDetails: datahubInfo,
|
|
112
120
|
// Owner information
|
|
113
121
|
character: options?.character || undefined,
|
|
114
122
|
// Include raw data for debugging/extension
|
|
115
123
|
_raw: moveObject,
|
|
116
124
|
_options: options,
|
|
117
|
-
};
|
|
125
|
+
} as DetailedAssemblyResponse;
|
|
118
126
|
|
|
119
127
|
// Add module-specific data based on assembly type
|
|
120
128
|
switch (assemblyType) {
|
|
@@ -148,30 +156,26 @@ export async function transformToAssembly(
|
|
|
148
156
|
items: inventoryItems,
|
|
149
157
|
},
|
|
150
158
|
ephemeralInventories: [],
|
|
151
|
-
isParentNodeOnline: parentState === State.ONLINE,
|
|
152
159
|
},
|
|
153
160
|
} as AssemblyType<Assemblies.SmartStorageUnit>;
|
|
154
161
|
|
|
155
162
|
case Assemblies.SmartTurret:
|
|
156
163
|
return {
|
|
157
164
|
...baseAssembly,
|
|
158
|
-
turret: {
|
|
159
|
-
isParentNodeOnline: parentState === State.ONLINE,
|
|
160
|
-
},
|
|
165
|
+
turret: {},
|
|
161
166
|
} as AssemblyType<Assemblies.SmartTurret>;
|
|
162
167
|
|
|
163
168
|
case Assemblies.SmartGate:
|
|
164
169
|
return {
|
|
165
170
|
...baseAssembly,
|
|
166
171
|
gate: {
|
|
167
|
-
linked: false,
|
|
168
172
|
destinationId: rawData.linked_gate_id,
|
|
169
|
-
|
|
170
|
-
isParentNodeOnline: parentState === State.ONLINE,
|
|
173
|
+
destinationGate: options?.destinationGate,
|
|
171
174
|
},
|
|
172
175
|
} as AssemblyType<Assemblies.SmartGate>;
|
|
173
176
|
|
|
174
177
|
case Assemblies.NetworkNode:
|
|
178
|
+
const energyConfig = await getEnergyConfig();
|
|
175
179
|
// TODO: Batch this call so that it can fetch all assemblies at once
|
|
176
180
|
const linkedAssemblies: SmartAssemblyResponse[] = await Promise.all(
|
|
177
181
|
(rawData.connected_assembly_ids || []).map(async (id) => {
|
|
@@ -184,12 +188,13 @@ export async function transformToAssembly(
|
|
|
184
188
|
parseInt(assemblyJson?.type_id || "0", 10),
|
|
185
189
|
);
|
|
186
190
|
|
|
191
|
+
const linkedTypeId = parseInt(assemblyJson?.type_id || "0", 10);
|
|
187
192
|
return {
|
|
188
193
|
id,
|
|
189
194
|
item_id: parseInt(assemblyJson?.key?.item_id || "0", 10),
|
|
190
195
|
state: parseStatus(assemblyJson?.status?.status?.["@variant"]),
|
|
191
|
-
energyUsage: 0,
|
|
192
|
-
typeId:
|
|
196
|
+
energyUsage: energyConfig[linkedTypeId] ?? 0,
|
|
197
|
+
typeId: linkedTypeId,
|
|
193
198
|
name: assemblyJson?.metadata?.name || "",
|
|
194
199
|
type: getAssemblyType(assemblyJson?.type_id || ""),
|
|
195
200
|
typeDetails: typeDetails,
|
|
@@ -201,7 +206,7 @@ export async function transformToAssembly(
|
|
|
201
206
|
...baseAssembly,
|
|
202
207
|
networkNode: {
|
|
203
208
|
fuel: {
|
|
204
|
-
|
|
209
|
+
burnTimeInMs: parseInt(rawData.fuel?.burn_rate_in_ms || "0", 10),
|
|
205
210
|
burnStartTime: parseInt(rawData.fuel?.burn_start_time || "0", 10),
|
|
206
211
|
isBurning: rawData.fuel?.is_burning || false,
|
|
207
212
|
lastUpdated: parseInt(rawData.fuel?.last_updated || "0", 10),
|
|
@@ -247,18 +252,9 @@ export async function transformToAssembly(
|
|
|
247
252
|
} as AssemblyType<Assemblies.Refinery>;
|
|
248
253
|
|
|
249
254
|
default:
|
|
250
|
-
// Default to
|
|
255
|
+
// Default to Assembly
|
|
251
256
|
return {
|
|
252
257
|
...baseAssembly,
|
|
253
|
-
|
|
254
|
-
mainInventory: {
|
|
255
|
-
capacity: "0",
|
|
256
|
-
usedCapacity: "0",
|
|
257
|
-
items: [],
|
|
258
|
-
},
|
|
259
|
-
ephemeralInventories: [],
|
|
260
|
-
isParentNodeOnline: state === State.ONLINE,
|
|
261
|
-
},
|
|
262
|
-
} as AssemblyType<Assemblies.SmartStorageUnit>;
|
|
258
|
+
} as AssemblyType<Assemblies.Assembly>;
|
|
263
259
|
}
|
|
264
260
|
}
|
package/wallet/features.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
EVEFRONTIER_SPONSORED_TRANSACTION,
|
|
13
13
|
SponsoredTransactionActions,
|
|
14
14
|
SponsoredTransactionAssemblyType,
|
|
15
|
+
SponsoredTransactionMetadata,
|
|
15
16
|
} from "../types";
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -30,7 +31,7 @@ export function getAssemblyTypeApiString(
|
|
|
30
31
|
* Takes the transformed item_id and assembly type values of the assembly object
|
|
31
32
|
* Normalization from assembly object to this flat shape is done in the hook by design;
|
|
32
33
|
* callers may pass either the full assembly or pre-flattened values.
|
|
33
|
-
* @category
|
|
34
|
+
* @category Types
|
|
34
35
|
*/
|
|
35
36
|
export interface SponsoredTransactionInput {
|
|
36
37
|
/** The transaction to be sponsored and executed */
|
|
@@ -40,8 +41,7 @@ export interface SponsoredTransactionInput {
|
|
|
40
41
|
tenant: string;
|
|
41
42
|
/** The assembly type to be sponsored and executed */
|
|
42
43
|
assemblyType: SponsoredTransactionAssemblyType;
|
|
43
|
-
|
|
44
|
-
chain: `sui:${string}`;
|
|
44
|
+
metadata?: SponsoredTransactionMetadata;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/** Sponsored tx args with assembly object; id and assemblyType are derived. Tenant is optional; the hook resolves it from args, URL query param, or default. */
|
|
@@ -53,13 +53,13 @@ export type SponsoredTransactionArgs = Omit<
|
|
|
53
53
|
account?: string;
|
|
54
54
|
tenant?: string;
|
|
55
55
|
txAction: SponsoredTransactionActions;
|
|
56
|
-
|
|
56
|
+
metadata?: SponsoredTransactionMetadata;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Output from a successful sponsored transaction
|
|
61
61
|
*
|
|
62
|
-
* @category
|
|
62
|
+
* @category Types
|
|
63
63
|
*/
|
|
64
64
|
export interface SponsoredTransactionOutput {
|
|
65
65
|
/** The transaction digest */
|
package/CHANGELOG.md
DELETED
package/docs/api/.nojekyll
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
window.hierarchyData = "eJyVkLEKwjAURf/lzqlSmzhkE/wA0VE6xPaVBtOk5MVBSv9dOigFFe3ytnPP4Q2IISSGPudSlgKRGkdVssEz9IBCTtebjqCxY6bu4u6HGHqKyRJD4Gp9Db1RW4FbdNCwPlFsTEW8fgdWbeocBCpnmKGRuM6mhexFYRTI5Vx76kxMz6kjcR880w/zR+YPuUDVWldH8tNHlCqnGqVmNXtKxjqqFwZ9w5Y2FbIcx/EBNsGWnQ=="
|