@evefrontier/dapp-kit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -0
- package/config/dapp-kit.ts +20 -0
- package/config/index.ts +1 -0
- package/docs/api/.nojekyll +1 -0
- package/docs/api/assets/hierarchy.js +1 -0
- package/docs/api/assets/highlight.css +120 -0
- package/docs/api/assets/icons.js +18 -0
- package/docs/api/assets/icons.svg +1 -0
- package/docs/api/assets/main.js +60 -0
- package/docs/api/assets/navigation.js +1 -0
- package/docs/api/assets/search.js +1 -0
- package/docs/api/assets/style.css +1633 -0
- package/docs/api/classes/WalletNoAccountSelectedError.html +3 -0
- package/docs/api/classes/WalletNotConnectedError.html +3 -0
- package/docs/api/classes/WalletSponsoredTransactionNotSupportedError.html +5 -0
- package/docs/api/enums/ActionTypes.html +6 -0
- package/docs/api/enums/Assemblies.html +7 -0
- package/docs/api/enums/QueryParams.html +3 -0
- package/docs/api/enums/Severity.html +5 -0
- package/docs/api/enums/SponsoredTransactionActions.html +7 -0
- package/docs/api/enums/State.html +6 -0
- package/docs/api/enums/TYPEIDS.html +15 -0
- package/docs/api/functions/EveFrontierProvider.html +11 -0
- package/docs/api/functions/NotificationProvider.html +2 -0
- package/docs/api/functions/SmartObjectProvider.html +10 -0
- package/docs/api/functions/VaultProvider.html +1 -0
- package/docs/api/functions/abbreviateAddress.html +11 -0
- package/docs/api/functions/assertAssemblyType.html +9 -0
- package/docs/api/functions/clickToCopy.html +1 -0
- package/docs/api/functions/executeGraphQLQuery.html +12 -0
- package/docs/api/functions/findOwnerByAddress.html +5 -0
- package/docs/api/functions/formatDuration.html +8 -0
- package/docs/api/functions/formatM3.html +8 -0
- package/docs/api/functions/getAssemblyType.html +4 -0
- package/docs/api/functions/getAssemblyTypeApiString.html +2 -0
- package/docs/api/functions/getAssemblyWithOwner.html +18 -0
- package/docs/api/functions/getCharacterOwnerCapType.html +3 -0
- package/docs/api/functions/getCommonItems.html +1 -0
- package/docs/api/functions/getDappUrl.html +7 -0
- package/docs/api/functions/getDatahubGameInfo.html +13 -0
- package/docs/api/functions/getEnv.html +1 -0
- package/docs/api/functions/getEveWorldPackageId.html +4 -0
- package/docs/api/functions/getObjectByAddress.html +9 -0
- package/docs/api/functions/getObjectId.html +4 -0
- package/docs/api/functions/getObjectOwnerAndOwnedObjectsByType.html +10 -0
- package/docs/api/functions/getObjectRegistryType.html +3 -0
- package/docs/api/functions/getObjectWithDynamicFields.html +10 -0
- package/docs/api/functions/getObjectWithJson.html +9 -0
- package/docs/api/functions/getObjectsByType.html +12 -0
- package/docs/api/functions/getOwnedObjectsByPackage.html +10 -0
- package/docs/api/functions/getOwnedObjectsByType.html +10 -0
- package/docs/api/functions/getRegistryAddress.html +3 -0
- package/docs/api/functions/getSingletonObjectByType.html +9 -0
- package/docs/api/functions/getSponsoredTransactionFeature.html +11 -0
- package/docs/api/functions/getSuiGraphqlEndpoint.html +4 -0
- package/docs/api/functions/getTxUrl.html +8 -0
- package/docs/api/functions/getVolumeM3.html +5 -0
- package/docs/api/functions/hasSponsoredTransactionFeature.html +3 -0
- package/docs/api/functions/isOwner.html +10 -0
- package/docs/api/functions/parseErrorFromMessage.html +1 -0
- package/docs/api/functions/parseStatus.html +2 -0
- package/docs/api/functions/parseURL.html +1 -0
- package/docs/api/functions/removeTrailingZeros.html +1 -0
- package/docs/api/functions/transformToAssembly.html +5 -0
- package/docs/api/functions/transformToCharacter.html +2 -0
- package/docs/api/functions/useConnection.html +21 -0
- package/docs/api/functions/useNotification.html +28 -0
- package/docs/api/functions/useSmartObject.html +26 -0
- package/docs/api/functions/useSponsoredTransaction.html +50 -0
- package/docs/api/functions/walletSupportsSponsoredTransaction.html +13 -0
- package/docs/api/hierarchy.html +1 -0
- package/docs/api/index.html +26 -0
- package/docs/api/interfaces/AddressOwner.html +2 -0
- package/docs/api/interfaces/AddressOwnerWithJson.html +2 -0
- package/docs/api/interfaces/AssemblyProperties.html +14 -0
- package/docs/api/interfaces/CharacterInfo.html +8 -0
- package/docs/api/interfaces/DatahubGameInfo.html +30 -0
- package/docs/api/interfaces/DetailedAssemblyResponse.html +14 -0
- package/docs/api/interfaces/DetailedSmartCharacterResponse.html +7 -0
- package/docs/api/interfaces/DynamicFieldNode.html +3 -0
- package/docs/api/interfaces/EphemeralInventory.html +6 -0
- package/docs/api/interfaces/EveFrontierSponsoredTransactionFeature.html +7 -0
- package/docs/api/interfaces/GameTypeResponse.html +13 -0
- package/docs/api/interfaces/GateModule.html +5 -0
- package/docs/api/interfaces/GetObjectByAddressResponse.html +2 -0
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsResponse.html +2 -0
- package/docs/api/interfaces/GetObjectOwnerAndOwnedObjectsWithJsonResponse.html +2 -0
- package/docs/api/interfaces/GetObjectResponse.html +2 -0
- package/docs/api/interfaces/GetObjectWithJsonResponse.html +2 -0
- package/docs/api/interfaces/GetObjectsByTypeResponse.html +2 -0
- package/docs/api/interfaces/GetOwnedObjectsByPackageResponse.html +2 -0
- package/docs/api/interfaces/GetOwnedObjectsByTypeResponse.html +2 -0
- package/docs/api/interfaces/GetSingletonObjectByTypeResponse.html +2 -0
- package/docs/api/interfaces/GraphQLResponse.html +3 -0
- package/docs/api/interfaces/InventoryItem.html +8 -0
- package/docs/api/interfaces/ManufacturingModule.html +2 -0
- package/docs/api/interfaces/MoveObjectContents.html +4 -0
- package/docs/api/interfaces/MoveObjectData.html +3 -0
- package/docs/api/interfaces/NetworkNodeModule.html +7 -0
- package/docs/api/interfaces/NotificationContextType.html +4 -0
- package/docs/api/interfaces/NotificationState.html +6 -0
- package/docs/api/interfaces/Notify.html +6 -0
- package/docs/api/interfaces/ObjectWithContentsNode.html +4 -0
- package/docs/api/interfaces/OwnedObjectAddressNode.html +2 -0
- package/docs/api/interfaces/OwnedObjectFullNode.html +4 -0
- package/docs/api/interfaces/OwnedObjectNode.html +3 -0
- package/docs/api/interfaces/OwnedObjectNodeWithJson.html +4 -0
- package/docs/api/interfaces/OwnerCapData.html +5 -0
- package/docs/api/interfaces/PageInfo.html +3 -0
- package/docs/api/interfaces/RawCharacterData.html +8 -0
- package/docs/api/interfaces/RawSuiObjectData.html +17 -0
- package/docs/api/interfaces/RefineryModule.html +2 -0
- package/docs/api/interfaces/SmartAssemblyResponse.html +11 -0
- package/docs/api/interfaces/SmartObjectContextType.html +8 -0
- package/docs/api/interfaces/SponsoredTransactionInput.html +15 -0
- package/docs/api/interfaces/SponsoredTransactionOutput.html +8 -0
- package/docs/api/interfaces/StorageModule.html +4 -0
- package/docs/api/interfaces/SuiObjectResponse.html +5 -0
- package/docs/api/interfaces/TransformOptions.html +6 -0
- package/docs/api/interfaces/TurretModule.html +2 -0
- package/docs/api/interfaces/VaultContextType.html +7 -0
- package/docs/api/modules.html +1 -0
- package/docs/api/types/AssemblyType.html +1 -0
- package/docs/api/types/ErrorType.html +5 -0
- package/docs/api/types/SendSponsoredTransactionFn.html +1 -0
- package/docs/api/types/SponsoredTransactionArgs.html +2 -0
- package/docs/api/types/SponsoredTransactionAssemblyType.html +2 -0
- package/docs/api/types/SponsoredTransactionMethod.html +2 -0
- package/docs/api/types/UseSponsoredTransactionArgs.html +3 -0
- package/docs/api/types/UseSponsoredTransactionError.html +2 -0
- package/docs/api/types/UseSponsoredTransactionMutationOptions.html +2 -0
- package/docs/api/variables/ERRORS.html +1 -0
- package/docs/api/variables/ERROR_MESSAGES.html +1 -0
- package/docs/api/variables/EVEFRONTIER_SPONSORED_TRANSACTION.html +4 -0
- package/docs/api/variables/EXCLUDED_TYPEIDS.html +1 -0
- package/docs/api/variables/GET_OBJECTS_BY_TYPE.html +3 -0
- package/docs/api/variables/GET_OBJECT_BY_ADDRESS.html +3 -0
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_BY_TYPE.html +4 -0
- package/docs/api/variables/GET_OBJECT_OWNER_AND_OWNED_OBJECTS_WITH_JSON.html +3 -0
- package/docs/api/variables/GET_OBJECT_WITH_DYNAMIC_FIELDS.html +4 -0
- package/docs/api/variables/GET_OBJECT_WITH_JSON.html +3 -0
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_PACKAGE.html +3 -0
- package/docs/api/variables/GET_OWNED_OBJECTS_BY_TYPE.html +3 -0
- package/docs/api/variables/GET_SINGLETON_OBJECT_BY_TYPE.html +3 -0
- package/docs/api/variables/NotificationContext.html +1 -0
- package/docs/api/variables/ONE_M3.html +2 -0
- package/docs/api/variables/POLLING_INTERVAL.html +2 -0
- package/docs/api/variables/STORAGE_KEYS.html +2 -0
- package/docs/api/variables/SmartObjectContext.html +1 -0
- package/docs/api/variables/VaultContext.html +1 -0
- package/docs/api/variables/dAppKit.html +2 -0
- package/graphql/client.ts +480 -0
- package/graphql/index.ts +73 -0
- package/graphql/queries.ts +371 -0
- package/graphql/types.ts +443 -0
- package/hooks/index.ts +14 -0
- package/hooks/useConnection.ts +58 -0
- package/hooks/useNotification.ts +80 -0
- package/hooks/useSmartObject.ts +78 -0
- package/hooks/useSponsoredTransaction.ts +323 -0
- package/index.ts +162 -0
- package/package.json +48 -0
- package/providers/EveFrontierProvider.tsx +41 -0
- package/providers/NotificationProvider.tsx +115 -0
- package/providers/SmartObjectProvider.tsx +282 -0
- package/providers/VaultProvider.tsx +114 -0
- package/providers/index.ts +17 -0
- package/tsconfig.json +22 -0
- package/typedoc.json +38 -0
- package/types/global.d.ts +7 -0
- package/types/index.ts +4 -0
- package/types/sponsoredTransaction.ts +26 -0
- package/types/types.ts +113 -0
- package/types/worldApiReturnTypes.ts +166 -0
- package/utils/__tests__/mapping.test.ts +441 -0
- package/utils/constants.ts +96 -0
- package/utils/datahub.ts +76 -0
- package/utils/errors.ts +171 -0
- package/utils/index.ts +38 -0
- package/utils/mapping.ts +115 -0
- package/utils/transforms.ts +258 -0
- package/utils/utils.ts +270 -0
- package/vite-env.d.ts +16 -0
- package/wallet/features.ts +165 -0
- package/wallet/index.ts +28 -0
- package/wallet/utils.ts +117 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReactNode,
|
|
3
|
+
useState,
|
|
4
|
+
createContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useCallback,
|
|
7
|
+
useRef,
|
|
8
|
+
} from "react";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
Assemblies,
|
|
12
|
+
AssemblyType,
|
|
13
|
+
QueryParams,
|
|
14
|
+
DetailedSmartCharacterResponse,
|
|
15
|
+
} from "../types";
|
|
16
|
+
|
|
17
|
+
import { POLLING_INTERVAL } from "../utils/constants";
|
|
18
|
+
import { getAssemblyWithOwner, MoveObjectData } from "../graphql";
|
|
19
|
+
import {
|
|
20
|
+
getObjectId,
|
|
21
|
+
transformToAssembly,
|
|
22
|
+
transformToCharacter,
|
|
23
|
+
} from "../utils";
|
|
24
|
+
import { getDatahubGameInfo } from "../utils/datahub";
|
|
25
|
+
import { useConnection } from "../hooks/useConnection";
|
|
26
|
+
|
|
27
|
+
/** @category Types */
|
|
28
|
+
export interface SmartObjectContextType {
|
|
29
|
+
assembly: AssemblyType<Assemblies> | null;
|
|
30
|
+
character: DetailedSmartCharacterResponse | null;
|
|
31
|
+
selectedObjectId: string;
|
|
32
|
+
loading: boolean;
|
|
33
|
+
error: string | null;
|
|
34
|
+
setSelectedObjectId: (id: string) => void;
|
|
35
|
+
refetch: () => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @category Providers */
|
|
39
|
+
export const SmartObjectContext = createContext<SmartObjectContextType>({
|
|
40
|
+
assembly: null,
|
|
41
|
+
character: null,
|
|
42
|
+
selectedObjectId: "",
|
|
43
|
+
loading: true,
|
|
44
|
+
error: null,
|
|
45
|
+
setSelectedObjectId: () => {},
|
|
46
|
+
refetch: async () => {},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* SmartObjectProvider component provides context for smart objects data.
|
|
51
|
+
* It uses GraphQL queries to fetch objects on the Sui blockchain
|
|
52
|
+
* from the EVE Frontier package, with optional polling for updates.
|
|
53
|
+
*
|
|
54
|
+
* The provider fetches both the assembly data and its owner (character) information:
|
|
55
|
+
* 1. Fetches assembly data with dynamic fields
|
|
56
|
+
* 2. Uses owner_cap_id to resolve the Character OwnerCap
|
|
57
|
+
* 3. Fetches full character data from the Character ID
|
|
58
|
+
*
|
|
59
|
+
* @category Providers
|
|
60
|
+
*/
|
|
61
|
+
const SmartObjectProvider = ({ children }: { children: ReactNode }) => {
|
|
62
|
+
const [assembly, setAssembly] = useState<AssemblyType<Assemblies> | null>(
|
|
63
|
+
null,
|
|
64
|
+
);
|
|
65
|
+
const [character, setCharacter] =
|
|
66
|
+
useState<DetailedSmartCharacterResponse | null>(null);
|
|
67
|
+
const [selectedObjectId, setSelectedObjectId] = useState<string>("");
|
|
68
|
+
const [selectedTenant, setSelectedTenant] = useState<string>("");
|
|
69
|
+
const [loading, setLoading] = useState<boolean>(true);
|
|
70
|
+
const [error, setError] = useState<string | null>(null);
|
|
71
|
+
|
|
72
|
+
const pollingRef = useRef<NodeJS.Timeout | null>(null);
|
|
73
|
+
const lastDataHashRef = useRef<string | null>(null);
|
|
74
|
+
|
|
75
|
+
const { isConnected } = useConnection();
|
|
76
|
+
|
|
77
|
+
// Fetch object data with owner/character info
|
|
78
|
+
const fetchObjectData = useCallback(
|
|
79
|
+
async (itemId: string, selectedTenant: string, isInitialFetch = false) => {
|
|
80
|
+
if (!itemId || !selectedTenant) return;
|
|
81
|
+
|
|
82
|
+
if (isInitialFetch) {
|
|
83
|
+
setLoading(true);
|
|
84
|
+
}
|
|
85
|
+
setError(null);
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
console.log(
|
|
89
|
+
"[DappKit] SmartObjectProvider: Fetching object with item ID and tenant:",
|
|
90
|
+
itemId,
|
|
91
|
+
selectedTenant,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const objectId = await getObjectId(itemId, selectedTenant);
|
|
95
|
+
|
|
96
|
+
// Fetch both assembly and character data
|
|
97
|
+
const { moveObject, character: characterInfo } =
|
|
98
|
+
await getAssemblyWithOwner(objectId);
|
|
99
|
+
|
|
100
|
+
if (!moveObject) {
|
|
101
|
+
console.warn(
|
|
102
|
+
"[DappKit] SmartObjectProvider: Object not found or not a Move object",
|
|
103
|
+
);
|
|
104
|
+
setAssembly(null);
|
|
105
|
+
setCharacter(null);
|
|
106
|
+
setError("Object not found or not a Move object");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Create a hash of the data to check for changes
|
|
111
|
+
const dataHash = JSON.stringify({
|
|
112
|
+
moveObject,
|
|
113
|
+
character: characterInfo,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Only update state if the data changed (optimization for polling)
|
|
117
|
+
if (isInitialFetch || lastDataHashRef.current !== dataHash) {
|
|
118
|
+
console.log("[DappKit] SmartObjectProvider: Object data updated");
|
|
119
|
+
lastDataHashRef.current = dataHash;
|
|
120
|
+
|
|
121
|
+
// Extract typeId from the raw JSON to fetch datahub info
|
|
122
|
+
const rawJson = moveObject.contents?.json as
|
|
123
|
+
| { type_id?: string; status?: { type_id?: string } }
|
|
124
|
+
| undefined;
|
|
125
|
+
const typeId = rawJson?.type_id || rawJson?.status?.type_id || "0";
|
|
126
|
+
|
|
127
|
+
// Fetch datahub game info (name, description, image defaults)
|
|
128
|
+
let datahubInfo = null;
|
|
129
|
+
try {
|
|
130
|
+
datahubInfo = await getDatahubGameInfo(parseInt(typeId, 10));
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.warn(
|
|
133
|
+
"[DappKit] SmartObjectProvider: Failed to fetch datahub info:",
|
|
134
|
+
err,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Transform assembly with character and datahub info
|
|
139
|
+
const transformed = await transformToAssembly(
|
|
140
|
+
objectId,
|
|
141
|
+
moveObject as MoveObjectData,
|
|
142
|
+
{
|
|
143
|
+
character: characterInfo,
|
|
144
|
+
datahubInfo,
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
setAssembly(transformed);
|
|
149
|
+
|
|
150
|
+
// Transform and set character
|
|
151
|
+
if (characterInfo) {
|
|
152
|
+
const transformedCharacter = transformToCharacter(characterInfo);
|
|
153
|
+
setCharacter(transformedCharacter);
|
|
154
|
+
} else {
|
|
155
|
+
setCharacter(null);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
setError(null);
|
|
159
|
+
} catch (err: unknown) {
|
|
160
|
+
console.error("[DappKit] SmartObjectProvider: Query error:", err);
|
|
161
|
+
setError(err instanceof Error ? err.message : "Failed to fetch object");
|
|
162
|
+
} finally {
|
|
163
|
+
if (isInitialFetch) {
|
|
164
|
+
setLoading(false);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
[],
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// Initialize the object ID from env or query params
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
console.log("[DappKit] SmartObjectProvider: Checking for item ID");
|
|
174
|
+
|
|
175
|
+
// Check if an object ID exists in the .env file
|
|
176
|
+
const envItemId = import.meta.env.VITE_ITEM_ID;
|
|
177
|
+
const envTenant = import.meta.env.VITE_EVE_WORLD_TENANT;
|
|
178
|
+
|
|
179
|
+
if (envItemId) {
|
|
180
|
+
console.log(
|
|
181
|
+
"[DappKit] SmartObjectProvider: Using item ID from env:",
|
|
182
|
+
envItemId,
|
|
183
|
+
);
|
|
184
|
+
setSelectedObjectId(envItemId);
|
|
185
|
+
|
|
186
|
+
if (envTenant) {
|
|
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
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Check if an object ID has been passed via query param
|
|
203
|
+
const queryParams = new URLSearchParams(window.location.search);
|
|
204
|
+
const queryItemId = queryParams.get(QueryParams.ITEM_ID);
|
|
205
|
+
const queryTenant = queryParams.get(QueryParams.TENANT);
|
|
206
|
+
|
|
207
|
+
if (queryItemId) {
|
|
208
|
+
setSelectedObjectId(queryItemId);
|
|
209
|
+
} else {
|
|
210
|
+
console.error("[DappKit] SmartObjectProvider: No object ID provided");
|
|
211
|
+
setLoading(false);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (queryTenant) {
|
|
215
|
+
setSelectedTenant(queryTenant);
|
|
216
|
+
} else {
|
|
217
|
+
console.error("[DappKit] SmartObjectProvider: No tenant provided");
|
|
218
|
+
}
|
|
219
|
+
}, []);
|
|
220
|
+
|
|
221
|
+
// Fetch and poll for object data
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
if (!selectedObjectId || !isConnected) {
|
|
224
|
+
if (!selectedObjectId) {
|
|
225
|
+
setLoading(false);
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Initial fetch
|
|
231
|
+
fetchObjectData(selectedObjectId, selectedTenant, true);
|
|
232
|
+
|
|
233
|
+
// Set up polling
|
|
234
|
+
pollingRef.current = setInterval(() => {
|
|
235
|
+
fetchObjectData(selectedObjectId, selectedTenant, false);
|
|
236
|
+
}, POLLING_INTERVAL);
|
|
237
|
+
|
|
238
|
+
console.log(
|
|
239
|
+
"[DappKit] SmartObjectProvider: Started polling for object:",
|
|
240
|
+
selectedObjectId,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
return () => {
|
|
244
|
+
if (pollingRef.current) {
|
|
245
|
+
clearInterval(pollingRef.current);
|
|
246
|
+
pollingRef.current = null;
|
|
247
|
+
console.log("[DappKit] SmartObjectProvider: Stopped polling");
|
|
248
|
+
}
|
|
249
|
+
lastDataHashRef.current = null;
|
|
250
|
+
};
|
|
251
|
+
}, [selectedObjectId, isConnected, fetchObjectData]);
|
|
252
|
+
|
|
253
|
+
const handleSetSelectedObjectId = useCallback((id: string) => {
|
|
254
|
+
console.log("[DappKit] SmartObjectProvider: Setting new object ID:", id);
|
|
255
|
+
lastDataHashRef.current = null;
|
|
256
|
+
setSelectedObjectId(id);
|
|
257
|
+
}, []);
|
|
258
|
+
|
|
259
|
+
const handleRefetch = useCallback(async () => {
|
|
260
|
+
if (selectedObjectId) {
|
|
261
|
+
await fetchObjectData(selectedObjectId, selectedTenant, true);
|
|
262
|
+
}
|
|
263
|
+
}, [selectedObjectId, selectedTenant, fetchObjectData]);
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<SmartObjectContext.Provider
|
|
267
|
+
value={{
|
|
268
|
+
assembly,
|
|
269
|
+
character,
|
|
270
|
+
selectedObjectId,
|
|
271
|
+
loading,
|
|
272
|
+
error,
|
|
273
|
+
setSelectedObjectId: handleSetSelectedObjectId,
|
|
274
|
+
refetch: handleRefetch,
|
|
275
|
+
}}
|
|
276
|
+
>
|
|
277
|
+
{children}
|
|
278
|
+
</SmartObjectContext.Provider>
|
|
279
|
+
);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
export default SmartObjectProvider;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ReactNode, useRef, useEffect, createContext } from "react";
|
|
2
|
+
import {
|
|
3
|
+
useCurrentAccount,
|
|
4
|
+
useWallets,
|
|
5
|
+
useDAppKit,
|
|
6
|
+
} from "@mysten/dapp-kit-react";
|
|
7
|
+
import type { WalletAccount } from "@mysten/wallet-standard";
|
|
8
|
+
import { STORAGE_KEYS } from "../utils/constants";
|
|
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
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @category Providers */
|
|
21
|
+
export const VaultContext = createContext<VaultContextType>({
|
|
22
|
+
currentAccount: null,
|
|
23
|
+
walletAddress: undefined,
|
|
24
|
+
hasEveVault: false,
|
|
25
|
+
isConnected: false,
|
|
26
|
+
handleConnect: () => {},
|
|
27
|
+
handleDisconnect: () => {},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* VaultProvider component provides a context for managing Sui wallet connections.
|
|
32
|
+
* It uses @mysten/dapp-kit-react hooks for wallet management.
|
|
33
|
+
*/
|
|
34
|
+
// Module-level flag to prevent auto-connect from running multiple times
|
|
35
|
+
// (persists across component remounts caused by wallet state changes)
|
|
36
|
+
let globalAutoConnectAttempted = false;
|
|
37
|
+
|
|
38
|
+
/** @category Providers */
|
|
39
|
+
const VaultProvider = ({ children }: { children: ReactNode }) => {
|
|
40
|
+
// Sui dapp-kit hooks
|
|
41
|
+
const currentAccount = useCurrentAccount();
|
|
42
|
+
const dAppKit = useDAppKit();
|
|
43
|
+
const { connectWallet, disconnectWallet } = dAppKit;
|
|
44
|
+
const wallets = useWallets();
|
|
45
|
+
|
|
46
|
+
// Find Eve Vault wallet if available
|
|
47
|
+
const eveVaultWallet = wallets.find((wallet) =>
|
|
48
|
+
wallet.name.includes("Eve Vault"),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Track if auto-connect has been attempted to prevent infinite loops
|
|
52
|
+
const hasAttemptedAutoConnect = useRef(false);
|
|
53
|
+
|
|
54
|
+
const handleConnect = () => {
|
|
55
|
+
const walletToConnect = eveVaultWallet || wallets[0];
|
|
56
|
+
|
|
57
|
+
if (!walletToConnect) {
|
|
58
|
+
console.warn("No wallet available to connect");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
connectWallet({ wallet: walletToConnect });
|
|
64
|
+
console.log("[DappKit] Connected to wallet:", walletToConnect.name);
|
|
65
|
+
localStorage.setItem(STORAGE_KEYS.CONNECTED, "true");
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error("[DappKit] Failed to connect wallet:", error);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleDisconnect = () => {
|
|
72
|
+
disconnectWallet();
|
|
73
|
+
localStorage.removeItem(STORAGE_KEYS.CONNECTED);
|
|
74
|
+
console.log("[DappKit] Wallet disconnected");
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Auto-reconnect if user was previously connected (only once)
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
// Use both local ref AND global flag for maximum protection against re-render loops
|
|
80
|
+
if (hasAttemptedAutoConnect.current || globalAutoConnectAttempted) return;
|
|
81
|
+
|
|
82
|
+
const isPreviouslyConnected =
|
|
83
|
+
localStorage.getItem(STORAGE_KEYS.CONNECTED) === "true";
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
typeof window !== "undefined" &&
|
|
87
|
+
isPreviouslyConnected &&
|
|
88
|
+
eveVaultWallet
|
|
89
|
+
) {
|
|
90
|
+
hasAttemptedAutoConnect.current = true;
|
|
91
|
+
globalAutoConnectAttempted = true;
|
|
92
|
+
handleConnect();
|
|
93
|
+
}
|
|
94
|
+
}, [eveVaultWallet, handleConnect]);
|
|
95
|
+
|
|
96
|
+
const isConnected = !!currentAccount;
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<VaultContext.Provider
|
|
100
|
+
value={{
|
|
101
|
+
walletAddress: currentAccount?.address,
|
|
102
|
+
currentAccount,
|
|
103
|
+
hasEveVault: !!eveVaultWallet,
|
|
104
|
+
isConnected,
|
|
105
|
+
handleConnect,
|
|
106
|
+
handleDisconnect,
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
</VaultContext.Provider>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default VaultProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { default as EveFrontierProvider } from "./EveFrontierProvider";
|
|
2
|
+
export {
|
|
3
|
+
default as VaultProvider,
|
|
4
|
+
VaultContext,
|
|
5
|
+
type VaultContextType,
|
|
6
|
+
} from "./VaultProvider";
|
|
7
|
+
export {
|
|
8
|
+
default as SmartObjectProvider,
|
|
9
|
+
SmartObjectContext,
|
|
10
|
+
type SmartObjectContextType,
|
|
11
|
+
} from "./SmartObjectProvider";
|
|
12
|
+
export {
|
|
13
|
+
default as NotificationProvider,
|
|
14
|
+
NotificationContext,
|
|
15
|
+
type NotificationContextType,
|
|
16
|
+
type NotificationState,
|
|
17
|
+
} from "./NotificationProvider";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowImportingTsExtensions": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"jsx": "react-jsx",
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["./**/*.ts", "./**/*.tsx", "./vite-env.d.ts"],
|
|
20
|
+
"exclude": ["node_modules"]
|
|
21
|
+
}
|
|
22
|
+
|
package/typedoc.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://typedoc.org/schema.json",
|
|
3
|
+
"entryPoints": [
|
|
4
|
+
"./index.ts"
|
|
5
|
+
],
|
|
6
|
+
"entryPointStrategy": "expand",
|
|
7
|
+
"out": "./docs/api",
|
|
8
|
+
"name": "@evefrontier/dapp-kit",
|
|
9
|
+
"readme": "./README.md",
|
|
10
|
+
"includeVersion": true,
|
|
11
|
+
"excludePrivate": true,
|
|
12
|
+
"excludeProtected": true,
|
|
13
|
+
"excludeInternal": true,
|
|
14
|
+
"excludeExternals": true,
|
|
15
|
+
"categoryOrder": [
|
|
16
|
+
"Providers",
|
|
17
|
+
"Hooks",
|
|
18
|
+
"GraphQL",
|
|
19
|
+
"Types",
|
|
20
|
+
"Utilities",
|
|
21
|
+
"Wallet",
|
|
22
|
+
"Config",
|
|
23
|
+
"*"
|
|
24
|
+
],
|
|
25
|
+
"navigation": {
|
|
26
|
+
"includeCategories": true,
|
|
27
|
+
"includeGroups": true
|
|
28
|
+
},
|
|
29
|
+
"sort": [
|
|
30
|
+
"source-order"
|
|
31
|
+
],
|
|
32
|
+
"visibilityFilters": {
|
|
33
|
+
"protected": false,
|
|
34
|
+
"private": false,
|
|
35
|
+
"inherited": true,
|
|
36
|
+
"external": false
|
|
37
|
+
}
|
|
38
|
+
}
|
package/types/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SponsoredTransactionArgs,
|
|
3
|
+
SponsoredTransactionOutput,
|
|
4
|
+
} from "../wallet";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Available sponsored transaction actions
|
|
8
|
+
*
|
|
9
|
+
* @category Types
|
|
10
|
+
*/
|
|
11
|
+
export enum SponsoredTransactionActions {
|
|
12
|
+
BRING_ONLINE = "online",
|
|
13
|
+
BRING_OFFLINE = "offline",
|
|
14
|
+
EDIT_UNIT = "edit-unit",
|
|
15
|
+
LINK_SMART_GATE = "link-smart-gate",
|
|
16
|
+
UNLINK_SMART_GATE = "unlink-smart-gate",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @category Types */
|
|
20
|
+
export type SendSponsoredTransactionFn = (
|
|
21
|
+
input: SponsoredTransactionArgs,
|
|
22
|
+
options?: {
|
|
23
|
+
onSuccess?: (data: SponsoredTransactionOutput) => void;
|
|
24
|
+
onError?: (error: Error) => void;
|
|
25
|
+
},
|
|
26
|
+
) => Promise<SponsoredTransactionOutput>;
|
package/types/types.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DetailedAssemblyResponse,
|
|
3
|
+
StorageModule,
|
|
4
|
+
TurretModule,
|
|
5
|
+
GateModule,
|
|
6
|
+
RefineryModule,
|
|
7
|
+
ManufacturingModule,
|
|
8
|
+
NetworkNodeModule,
|
|
9
|
+
} from "./worldApiReturnTypes";
|
|
10
|
+
|
|
11
|
+
// =========================================
|
|
12
|
+
// Query Parameters
|
|
13
|
+
// =========================================
|
|
14
|
+
|
|
15
|
+
/** @category Types */
|
|
16
|
+
export enum QueryParams {
|
|
17
|
+
ITEM_ID = "itemId",
|
|
18
|
+
TENANT = "tenant",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// =========================================
|
|
22
|
+
// Assembly State and Actions
|
|
23
|
+
// =========================================
|
|
24
|
+
|
|
25
|
+
/** @category Types */
|
|
26
|
+
export enum State {
|
|
27
|
+
NULL = "NULL",
|
|
28
|
+
UNANCHORED = "UNANCHORED",
|
|
29
|
+
ANCHORED = "anchored", // Anchored + offline
|
|
30
|
+
ONLINE = "online", // Anchored + online
|
|
31
|
+
DESTROYED = "destroyed",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @category Types */
|
|
35
|
+
export enum ActionTypes {
|
|
36
|
+
UNANCHOR = "Unanchor",
|
|
37
|
+
ANCHOR = "Anchor",
|
|
38
|
+
BRING_ONLINE = "Online unit",
|
|
39
|
+
BRING_OFFLINE = "Offline unit",
|
|
40
|
+
DESTROY = "Destroy",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// =========================================
|
|
44
|
+
// UI Related Types
|
|
45
|
+
// =========================================
|
|
46
|
+
|
|
47
|
+
/** @category Types */
|
|
48
|
+
export enum Severity {
|
|
49
|
+
Error = "error",
|
|
50
|
+
Warning = "warning",
|
|
51
|
+
Info = "info",
|
|
52
|
+
Success = "success",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @category Types */
|
|
56
|
+
export interface Notify {
|
|
57
|
+
type: Severity;
|
|
58
|
+
message: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
namespace?: string;
|
|
61
|
+
namespaceLabel?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// =========================================
|
|
65
|
+
// Assembly Types
|
|
66
|
+
// =========================================
|
|
67
|
+
|
|
68
|
+
/** @category Types */
|
|
69
|
+
export enum Assemblies {
|
|
70
|
+
SmartStorageUnit = "SmartStorageUnit",
|
|
71
|
+
SmartTurret = "SmartTurret",
|
|
72
|
+
SmartGate = "SmartGate",
|
|
73
|
+
NetworkNode = "NetworkNode",
|
|
74
|
+
Manufacturing = "Manufacturing",
|
|
75
|
+
Refinery = "Refinery",
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** @category Types */
|
|
79
|
+
export interface AssemblyProperties<T extends Assemblies>
|
|
80
|
+
extends DetailedAssemblyResponse {
|
|
81
|
+
type: T;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @category Types */
|
|
85
|
+
export type AssemblyType<T extends Assemblies> = {
|
|
86
|
+
[K in T]: K extends Assemblies.SmartStorageUnit
|
|
87
|
+
? AssemblyProperties<K> & { storage: StorageModule }
|
|
88
|
+
: K extends Assemblies.SmartTurret
|
|
89
|
+
? AssemblyProperties<K> & { turret: TurretModule }
|
|
90
|
+
: K extends Assemblies.SmartGate
|
|
91
|
+
? AssemblyProperties<K> & { gate: GateModule }
|
|
92
|
+
: K extends Assemblies.NetworkNode
|
|
93
|
+
? AssemblyProperties<K> & { networkNode: NetworkNodeModule }
|
|
94
|
+
: K extends Assemblies.Refinery
|
|
95
|
+
? AssemblyProperties<K> & { refinery: RefineryModule }
|
|
96
|
+
: K extends Assemblies.Manufacturing
|
|
97
|
+
? AssemblyProperties<K> & { manufacturing: ManufacturingModule }
|
|
98
|
+
: never;
|
|
99
|
+
}[T];
|
|
100
|
+
|
|
101
|
+
// =========================================
|
|
102
|
+
// Character Related Types
|
|
103
|
+
// =========================================
|
|
104
|
+
|
|
105
|
+
/** @category Types */
|
|
106
|
+
export interface DetailedSmartCharacterResponse {
|
|
107
|
+
address: string;
|
|
108
|
+
name: string;
|
|
109
|
+
id: string;
|
|
110
|
+
tribeId: number;
|
|
111
|
+
smartAssemblies: Assemblies[];
|
|
112
|
+
portrait: string;
|
|
113
|
+
}
|