@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
package/utils/utils.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { SuiChain } from "@mysten/wallet-standard";
|
|
3
|
+
import {
|
|
4
|
+
Assemblies,
|
|
5
|
+
DetailedAssemblyResponse,
|
|
6
|
+
SmartAssemblyResponse,
|
|
7
|
+
AssemblyType,
|
|
8
|
+
} from "../types";
|
|
9
|
+
|
|
10
|
+
import { ONE_M3 } from "./constants";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Abbreviate a Sui address or hex string for display.
|
|
14
|
+
*
|
|
15
|
+
* Shortens long addresses to show only the beginning and end characters
|
|
16
|
+
* with ellipsis in the middle.
|
|
17
|
+
*
|
|
18
|
+
* @category Utilities
|
|
19
|
+
* @param string - The address or hex string to abbreviate
|
|
20
|
+
* @param precision - Number of characters to show on each end (default: 5)
|
|
21
|
+
* @param expanded - If true, returns the full string without abbreviation
|
|
22
|
+
* @returns The abbreviated string (e.g., "0x123...abc")
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* abbreviateAddress("0x1234567890abcdef1234567890abcdef"); // "0x123...cdef"
|
|
27
|
+
* abbreviateAddress("0x1234567890abcdef", 3); // "0x1...def"
|
|
28
|
+
* abbreviateAddress("0x1234567890abcdef", 5, true); // Full address
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const abbreviateAddress = (
|
|
32
|
+
string?: `0x${string}` | string,
|
|
33
|
+
precision = 5,
|
|
34
|
+
expanded = false,
|
|
35
|
+
): string => {
|
|
36
|
+
if (!string) return "";
|
|
37
|
+
if (expanded) return string;
|
|
38
|
+
if (string.length <= precision * 2) return string;
|
|
39
|
+
return `${string.slice(0, precision)}...${string.slice(-precision)}`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Check if an account is the owner of a smart assembly.
|
|
44
|
+
*
|
|
45
|
+
* Compares the assembly's owner address with the provided account address
|
|
46
|
+
* to determine ownership.
|
|
47
|
+
*
|
|
48
|
+
* @category Utilities
|
|
49
|
+
* @param assembly - The assembly object to check ownership of
|
|
50
|
+
* @param account - The account address to check against
|
|
51
|
+
* @returns True if the account owns the assembly, false otherwise
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const { assembly } = useSmartObject();
|
|
56
|
+
* const { currentAccount } = useConnection();
|
|
57
|
+
*
|
|
58
|
+
* if (isOwner(assembly, currentAccount?.address)) {
|
|
59
|
+
* // Show owner-only actions
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export const isOwner = (
|
|
64
|
+
assembly: DetailedAssemblyResponse | SmartAssemblyResponse | null,
|
|
65
|
+
account?: `0x${string}` | string,
|
|
66
|
+
): boolean => {
|
|
67
|
+
if (!assembly?.character?.address || account == "0x") return false;
|
|
68
|
+
return assembly.character.address === (account ?? "");
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Generate a Suiscan transaction URL for a given transaction hash.
|
|
73
|
+
*
|
|
74
|
+
* @category Utilities
|
|
75
|
+
* @param suiChain - The Sui chain identifier (e.g., "sui:testnet", "sui:mainnet")
|
|
76
|
+
* @param txHash - The transaction digest hash
|
|
77
|
+
* @returns Full Suiscan URL to view the transaction
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const url = getTxUrl("sui:testnet", "ABC123...");
|
|
82
|
+
* // Returns: "https://suiscan.xyz/testnet/tx/ABC123..."
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export const getTxUrl = (suiChain: SuiChain, txHash: string): string => {
|
|
86
|
+
const network = suiChain.split(":")[1];
|
|
87
|
+
|
|
88
|
+
return `https://suiscan.xyz/${network}/tx/${txHash}`;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const parseURL = (string: string): string => {
|
|
92
|
+
if (string.includes("://")) {
|
|
93
|
+
// Remove 'http' or 'https'
|
|
94
|
+
return string.split("://")[1];
|
|
95
|
+
} else {
|
|
96
|
+
return string;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const clickToCopy = (string: string) => {
|
|
101
|
+
return navigator.clipboard.writeText(string);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const getCommonItems = (array1: any[], array2: any[]) => {
|
|
105
|
+
const commonItems: any[] = [];
|
|
106
|
+
const set: Set<any> = new Set([]);
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < array1.length; i++) {
|
|
109
|
+
const value = array1[i];
|
|
110
|
+
if (!set.has(value)) set.add(value);
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < array2.length; i++) {
|
|
113
|
+
const value = array2[i];
|
|
114
|
+
if (set.has(value)) commonItems.push(value);
|
|
115
|
+
}
|
|
116
|
+
return commonItems;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const removeTrailingZeros = (number: string) => {
|
|
120
|
+
return number.replace(/(\.\d*?[1-9])0+$|\.0*$/, "$1");
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const getEnv = (env: string, fallback: string): string => {
|
|
124
|
+
if (!env) return fallback;
|
|
125
|
+
return env;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Calculates the volume in M3
|
|
129
|
+
* @param quantity - The unit quantity of the item
|
|
130
|
+
* @param volume - Volume per unit in wei (10^18)
|
|
131
|
+
* @returns volume in m3 */
|
|
132
|
+
export const getVolumeM3 = (quantity: bigint, volume: bigint): number => {
|
|
133
|
+
const totalVolume = Number(quantity) * Number(volume);
|
|
134
|
+
return totalVolume;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Format a raw volume value to cubic meters (m³).
|
|
139
|
+
*
|
|
140
|
+
* Converts from the on-chain representation (wei-like, 10^18) to m³.
|
|
141
|
+
*
|
|
142
|
+
* @category Utilities
|
|
143
|
+
* @param quantity - The raw volume value as string or bigint
|
|
144
|
+
* @returns Volume in cubic meters
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const m3 = formatM3(BigInt("1000000000000000000")); // 1.0 m³
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export const formatM3 = (quantity: string | bigint): number => {
|
|
152
|
+
return Number(quantity) / ONE_M3;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get the dApp URL for an assembly, ensuring it has a protocol prefix.
|
|
157
|
+
*
|
|
158
|
+
* @category Utilities
|
|
159
|
+
* @param assembly - The assembly object
|
|
160
|
+
* @returns The full dApp URL with https:// prefix if needed
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const { assembly } = useSmartObject();
|
|
165
|
+
* const dappUrl = getDappUrl(assembly);
|
|
166
|
+
* if (dappUrl) {
|
|
167
|
+
* window.open(dappUrl, '_blank');
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export const getDappUrl = (assembly: AssemblyType<Assemblies>): string => {
|
|
172
|
+
if (!assembly?.dappURL) return "";
|
|
173
|
+
|
|
174
|
+
const pattern = /^((http|https|ftp):\/\/)/;
|
|
175
|
+
|
|
176
|
+
let url = assembly.dappURL;
|
|
177
|
+
if (!pattern.test(url)) {
|
|
178
|
+
url = "https://" + url;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return url;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Check if two addresses match.
|
|
186
|
+
*
|
|
187
|
+
* @category Utilities
|
|
188
|
+
* @param address1 - First address to compare
|
|
189
|
+
* @param address2 - Second address to compare
|
|
190
|
+
* @returns True if addresses match, false otherwise
|
|
191
|
+
*/
|
|
192
|
+
export const findOwnerByAddress = (
|
|
193
|
+
address1: string | undefined,
|
|
194
|
+
address2: string | undefined,
|
|
195
|
+
): boolean => {
|
|
196
|
+
if (!address2 || !address1 || address1 == "" || address2 == "") return false;
|
|
197
|
+
return address1 === address2;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Type guard to check if an assembly is of a specific type.
|
|
202
|
+
*
|
|
203
|
+
* Use this to narrow the type of an assembly for type-safe property access.
|
|
204
|
+
*
|
|
205
|
+
* @category Utilities
|
|
206
|
+
* @param assembly - The assembly to check
|
|
207
|
+
* @param assemblyType - The expected assembly type
|
|
208
|
+
* @returns True if assembly matches the specified type
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const { assembly } = useSmartObject();
|
|
213
|
+
*
|
|
214
|
+
* if (assertAssemblyType(assembly, Assemblies.SmartStorageUnit)) {
|
|
215
|
+
* // TypeScript knows assembly is SmartStorageUnit here
|
|
216
|
+
* console.log(assembly.storage.mainInventory);
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export const assertAssemblyType = (
|
|
221
|
+
assembly: AssemblyType<Assemblies> | null,
|
|
222
|
+
assemblyType: Assemblies,
|
|
223
|
+
): assembly is AssemblyType<Assemblies> => {
|
|
224
|
+
if (typeof assembly?.type === "string") {
|
|
225
|
+
return assembly.type === assemblyType;
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Format a duration in seconds to a human-readable string.
|
|
232
|
+
*
|
|
233
|
+
* Displays the duration in days, hours, minutes, and seconds as appropriate.
|
|
234
|
+
*
|
|
235
|
+
* @category Utilities
|
|
236
|
+
* @param seconds - Duration in seconds
|
|
237
|
+
* @returns Formatted duration string (e.g., "02d 05h 30m 15s")
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* formatDuration(3665); // "01h 01m 05s"
|
|
242
|
+
* formatDuration(90061); // "01d 01h 01m 01s"
|
|
243
|
+
* formatDuration(45); // "45s"
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export const formatDuration = (seconds: number): string => {
|
|
247
|
+
if (seconds === 0) return "0m 0s";
|
|
248
|
+
|
|
249
|
+
const days = Math.floor(seconds / (24 * 3600));
|
|
250
|
+
seconds %= 24 * 3600;
|
|
251
|
+
const hours = Math.floor(seconds / 3600);
|
|
252
|
+
seconds %= 3600;
|
|
253
|
+
const minutes = Math.floor(seconds / 60);
|
|
254
|
+
const remainingSeconds = seconds % 60;
|
|
255
|
+
|
|
256
|
+
const formattedDays = String(days).padStart(2, "0");
|
|
257
|
+
const formattedHours = String(hours).padStart(2, "0");
|
|
258
|
+
const formattedMinutes = String(minutes).padStart(2, "0");
|
|
259
|
+
const formattedSeconds = String(remainingSeconds).padStart(2, "0");
|
|
260
|
+
|
|
261
|
+
if (days > 0) {
|
|
262
|
+
return `${formattedDays}d ${formattedHours}h ${formattedMinutes}m ${formattedSeconds}s`;
|
|
263
|
+
} else if (hours > 0) {
|
|
264
|
+
return `${formattedHours}h ${formattedMinutes}m ${formattedSeconds}s`;
|
|
265
|
+
} else if (minutes > 0) {
|
|
266
|
+
return `${formattedMinutes}m ${formattedSeconds}s`;
|
|
267
|
+
} else {
|
|
268
|
+
return `${formattedSeconds}s`;
|
|
269
|
+
}
|
|
270
|
+
};
|
package/vite-env.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
interface ImportMetaEnv {
|
|
4
|
+
/** Sui GraphQL endpoint URL (required) */
|
|
5
|
+
readonly VITE_SUI_GRAPHQL_ENDPOINT: string;
|
|
6
|
+
/** EVE World package ID on Sui (required) */
|
|
7
|
+
readonly VITE_EVE_WORLD_PACKAGE_ID: string;
|
|
8
|
+
/** Optional smart assembly item ID override */
|
|
9
|
+
readonly VITE_ITEM_ID?: string;
|
|
10
|
+
/** Tenant identifier (required when VITE_ITEM_ID is set) */
|
|
11
|
+
readonly VITE_EVE_WORLD_TENANT?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ImportMeta {
|
|
15
|
+
readonly env: ImportMetaEnv;
|
|
16
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVE Frontier Wallet Standard Feature Extensions
|
|
3
|
+
*
|
|
4
|
+
* Custom wallet features for EVE Frontier dApps that extend the
|
|
5
|
+
* standard Sui wallet capabilities.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
Assemblies,
|
|
10
|
+
AssemblyType,
|
|
11
|
+
SponsoredTransactionActions,
|
|
12
|
+
} from "../types";
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Feature Identifiers
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Feature identifier for sponsored transactions.
|
|
20
|
+
* Wallets implementing this feature can request gas sponsorship from
|
|
21
|
+
* the EVE Frontier sponsored-transaction backend service.
|
|
22
|
+
*
|
|
23
|
+
* @category Wallet
|
|
24
|
+
*/
|
|
25
|
+
export const EVEFRONTIER_SPONSORED_TRANSACTION =
|
|
26
|
+
"evefrontier:sponsoredTransaction" as const;
|
|
27
|
+
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Sponsored Transaction Types
|
|
30
|
+
// ============================================================================
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Map assembly types to API strings
|
|
34
|
+
*/
|
|
35
|
+
const ASSEMBLY_TYPE_API_STRING: Record<Assemblies, string> = {
|
|
36
|
+
[Assemblies.SmartStorageUnit]: "storage-units",
|
|
37
|
+
[Assemblies.SmartTurret]: "turrets",
|
|
38
|
+
[Assemblies.SmartGate]: "gates",
|
|
39
|
+
[Assemblies.NetworkNode]: "network-nodes",
|
|
40
|
+
[Assemblies.Manufacturing]: "manufacturing",
|
|
41
|
+
[Assemblies.Refinery]: "refineries",
|
|
42
|
+
} as const;
|
|
43
|
+
|
|
44
|
+
/** API slug for assembly type in sponsored transaction payloads (e.g. "storage-units"). */
|
|
45
|
+
export type SponsoredTransactionAssemblyType =
|
|
46
|
+
(typeof ASSEMBLY_TYPE_API_STRING)[Assemblies];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Maps an assembly type enum to the API string expected by the sponsored transaction backend.
|
|
50
|
+
*
|
|
51
|
+
* @category Wallet
|
|
52
|
+
*/
|
|
53
|
+
export function getAssemblyTypeApiString(
|
|
54
|
+
type: Assemblies,
|
|
55
|
+
): SponsoredTransactionAssemblyType {
|
|
56
|
+
return ASSEMBLY_TYPE_API_STRING[type];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Input for a sponsored transaction request
|
|
61
|
+
* Takes the transformed item_id and assembly type values of the assembly object
|
|
62
|
+
* Normalization from assembly object to this flat shape is done in the hook by design;
|
|
63
|
+
* callers may pass either the full assembly or pre-flattened values.
|
|
64
|
+
* @category Wallet
|
|
65
|
+
*/
|
|
66
|
+
export interface SponsoredTransactionInput {
|
|
67
|
+
/** The transaction to be sponsored and executed */
|
|
68
|
+
txAction: SponsoredTransactionActions;
|
|
69
|
+
/** Assembly ID */
|
|
70
|
+
assembly: AssemblyType<Assemblies>["item_id"];
|
|
71
|
+
/** The assembly type to be sponsored and executed */
|
|
72
|
+
assemblyType: SponsoredTransactionAssemblyType;
|
|
73
|
+
/** The Sui chain to execute on (e.g., "sui:testnet", "sui:mainnet") */
|
|
74
|
+
chain: `sui:${string}`;
|
|
75
|
+
/** Optional destination for gate linking */
|
|
76
|
+
destination?: AssemblyType<Assemblies>["item_id"];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Sponsored tx args with assembly object; id and assemblyType are derived. */
|
|
80
|
+
export type SponsoredTransactionArgs = Omit<
|
|
81
|
+
SponsoredTransactionInput,
|
|
82
|
+
"assembly" | "assemblyType" | "account"
|
|
83
|
+
> & {
|
|
84
|
+
assembly: AssemblyType<Assemblies>;
|
|
85
|
+
account?: string;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Output from a successful sponsored transaction
|
|
90
|
+
*
|
|
91
|
+
* @category Wallet
|
|
92
|
+
*/
|
|
93
|
+
export interface SponsoredTransactionOutput {
|
|
94
|
+
/** The transaction digest */
|
|
95
|
+
digest: string;
|
|
96
|
+
/** The transaction effects (BCS encoded) */
|
|
97
|
+
effects?: string;
|
|
98
|
+
/** Raw effects bytes (if available) */
|
|
99
|
+
rawEffects?: number[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The sponsored transaction method signature
|
|
104
|
+
*
|
|
105
|
+
* @category Wallet
|
|
106
|
+
*/
|
|
107
|
+
export type SponsoredTransactionMethod = (
|
|
108
|
+
input: SponsoredTransactionInput,
|
|
109
|
+
) => Promise<SponsoredTransactionOutput>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Feature interface for sponsored transactions.
|
|
113
|
+
* Wallets that support this feature should implement this interface
|
|
114
|
+
* in their `features` object.
|
|
115
|
+
*
|
|
116
|
+
* @category Wallet
|
|
117
|
+
*/
|
|
118
|
+
export interface EveFrontierSponsoredTransactionFeature {
|
|
119
|
+
readonly [EVEFRONTIER_SPONSORED_TRANSACTION]: {
|
|
120
|
+
/** Feature version for compatibility checking */
|
|
121
|
+
readonly version: "1.0.0";
|
|
122
|
+
/** Execute a gas-sponsored transaction */
|
|
123
|
+
signSponsoredTransaction: SponsoredTransactionMethod;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ============================================================================
|
|
128
|
+
// Type Guards
|
|
129
|
+
// ============================================================================
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Type guard to check if an object has the sponsored transaction feature
|
|
133
|
+
* (object form with implementation).
|
|
134
|
+
*
|
|
135
|
+
* @category Wallet
|
|
136
|
+
*/
|
|
137
|
+
export function hasSponsoredTransactionFeature(
|
|
138
|
+
features: Record<string, unknown>,
|
|
139
|
+
): features is Record<string, unknown> &
|
|
140
|
+
EveFrontierSponsoredTransactionFeature {
|
|
141
|
+
const featureValue = features[EVEFRONTIER_SPONSORED_TRANSACTION];
|
|
142
|
+
return (
|
|
143
|
+
EVEFRONTIER_SPONSORED_TRANSACTION in features &&
|
|
144
|
+
typeof featureValue === "object" &&
|
|
145
|
+
featureValue !== null &&
|
|
146
|
+
"signSponsoredTransaction" in (featureValue as object)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Check if a wallet supports the sponsored transaction feature.
|
|
152
|
+
* Supports both legacy object-shaped features and v2 array-shaped features
|
|
153
|
+
* (list of feature names).
|
|
154
|
+
*
|
|
155
|
+
* @category Wallet
|
|
156
|
+
*/
|
|
157
|
+
export function supportsSponsoredTransaction(features: unknown): boolean {
|
|
158
|
+
if (Array.isArray(features)) {
|
|
159
|
+
return (features as string[]).includes(EVEFRONTIER_SPONSORED_TRANSACTION);
|
|
160
|
+
}
|
|
161
|
+
if (typeof features === "object" && features !== null) {
|
|
162
|
+
return hasSponsoredTransactionFeature(features as Record<string, unknown>);
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
}
|
package/wallet/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVE Frontier Wallet Standard Extensions
|
|
3
|
+
*
|
|
4
|
+
* Provides custom wallet sponsored transaction features.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Feature definitions and types
|
|
8
|
+
export {
|
|
9
|
+
EVEFRONTIER_SPONSORED_TRANSACTION,
|
|
10
|
+
getAssemblyTypeApiString,
|
|
11
|
+
hasSponsoredTransactionFeature,
|
|
12
|
+
supportsSponsoredTransaction,
|
|
13
|
+
} from "./features";
|
|
14
|
+
export type {
|
|
15
|
+
EveFrontierSponsoredTransactionFeature,
|
|
16
|
+
SponsoredTransactionArgs,
|
|
17
|
+
SponsoredTransactionAssemblyType,
|
|
18
|
+
SponsoredTransactionInput,
|
|
19
|
+
SponsoredTransactionMethod,
|
|
20
|
+
SponsoredTransactionOutput,
|
|
21
|
+
} from "./features";
|
|
22
|
+
|
|
23
|
+
// Utility functions
|
|
24
|
+
export {
|
|
25
|
+
walletSupportsSponsoredTransaction,
|
|
26
|
+
getSponsoredTransactionFeature,
|
|
27
|
+
getSponsoredTransactionMethod,
|
|
28
|
+
} from "./utils";
|
package/wallet/utils.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Wallet } from "@mysten/wallet-standard";
|
|
2
|
+
import {
|
|
3
|
+
EVEFRONTIER_SPONSORED_TRANSACTION,
|
|
4
|
+
hasSponsoredTransactionFeature,
|
|
5
|
+
supportsSponsoredTransaction,
|
|
6
|
+
type EveFrontierSponsoredTransactionFeature,
|
|
7
|
+
type SponsoredTransactionMethod,
|
|
8
|
+
} from "./features";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Check if a wallet supports the EVE Frontier sponsored transaction feature.
|
|
12
|
+
*
|
|
13
|
+
* Use this to filter available wallets to only those that can execute
|
|
14
|
+
* sponsored (gasless) transactions. Currently, only EVE Vault implements
|
|
15
|
+
* this feature.
|
|
16
|
+
*
|
|
17
|
+
* @category Wallet
|
|
18
|
+
* @param wallet - The wallet object from wallet-standard
|
|
19
|
+
* @returns True if the wallet implements the `evefrontier:sponsoredTransaction` feature
|
|
20
|
+
*
|
|
21
|
+
* @example Filter supported wallets
|
|
22
|
+
* ```tsx
|
|
23
|
+
* import { useWallets } from "@mysten/dapp-kit-react";
|
|
24
|
+
* import { walletSupportsSponsoredTransaction } from "@evefrontier/dapp-kit";
|
|
25
|
+
*
|
|
26
|
+
* const wallets = useWallets();
|
|
27
|
+
* const supportedWallets = wallets.filter(walletSupportsSponsoredTransaction);
|
|
28
|
+
*
|
|
29
|
+
* console.log(`${supportedWallets.length} wallets support sponsored transactions`);
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Check single wallet
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const { currentWallet } = useCurrentWallet();
|
|
35
|
+
*
|
|
36
|
+
* if (currentWallet && walletSupportsSponsoredTransaction(currentWallet)) {
|
|
37
|
+
* // Wallet supports gasless transactions
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function walletSupportsSponsoredTransaction(wallet: Wallet): boolean {
|
|
42
|
+
return supportsSponsoredTransaction(wallet.features);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get the sponsored transaction method from a wallet if supported.
|
|
47
|
+
*
|
|
48
|
+
* Returns the raw `signSponsoredTransaction` method from the wallet's features.
|
|
49
|
+
* For most use cases, prefer using the {@link useSponsoredTransaction} hook instead,
|
|
50
|
+
* which provides React Query integration and automatic error handling.
|
|
51
|
+
*
|
|
52
|
+
* @category Wallet
|
|
53
|
+
* @param wallet - The wallet object from wallet-standard
|
|
54
|
+
* @returns The sponsored transaction method, or undefined if not supported
|
|
55
|
+
*
|
|
56
|
+
* @example Direct wallet feature access
|
|
57
|
+
* ```tsx
|
|
58
|
+
* const { currentWallet } = useCurrentWallet();
|
|
59
|
+
*
|
|
60
|
+
* if (currentWallet) {
|
|
61
|
+
* const sponsoredTx = getSponsoredTransactionFeature(currentWallet);
|
|
62
|
+
* if (sponsoredTx) {
|
|
63
|
+
* const result = await sponsoredTx({
|
|
64
|
+
* txAction: "online",
|
|
65
|
+
* chain: "sui:testnet",
|
|
66
|
+
* assembly: "0x123..."
|
|
67
|
+
* });
|
|
68
|
+
* console.log("Transaction digest:", result.digest);
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @see {@link useSponsoredTransaction} for the recommended React hook approach
|
|
74
|
+
*/
|
|
75
|
+
export function getSponsoredTransactionFeature(
|
|
76
|
+
wallet: Wallet,
|
|
77
|
+
): SponsoredTransactionMethod | undefined {
|
|
78
|
+
if (
|
|
79
|
+
!hasSponsoredTransactionFeature(wallet.features as Record<string, unknown>)
|
|
80
|
+
) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const feature = (wallet.features as Record<string, unknown>)[
|
|
85
|
+
EVEFRONTIER_SPONSORED_TRANSACTION
|
|
86
|
+
] as EveFrontierSponsoredTransactionFeature[typeof EVEFRONTIER_SPONSORED_TRANSACTION];
|
|
87
|
+
|
|
88
|
+
return feature.signSponsoredTransaction;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get the sponsored transaction method from a wallet, supporting both
|
|
93
|
+
* object-shaped features (legacy) and array-shaped features (v2).
|
|
94
|
+
* When features is an array, tries the wallet object for a top-level
|
|
95
|
+
* feature implementation (e.g. wallet['evefrontier:sponsoredTransaction']).
|
|
96
|
+
*/
|
|
97
|
+
export function getSponsoredTransactionMethod(
|
|
98
|
+
wallet: Wallet | { features: unknown; name?: string; version?: string },
|
|
99
|
+
): SponsoredTransactionMethod | undefined {
|
|
100
|
+
const fromFeatures = getSponsoredTransactionFeature(wallet as Wallet);
|
|
101
|
+
if (fromFeatures) return fromFeatures;
|
|
102
|
+
|
|
103
|
+
if (!supportsSponsoredTransaction(wallet.features)) return undefined;
|
|
104
|
+
|
|
105
|
+
const w = wallet as Record<string, unknown>;
|
|
106
|
+
const feature = w[EVEFRONTIER_SPONSORED_TRANSACTION];
|
|
107
|
+
if (
|
|
108
|
+
feature !== null &&
|
|
109
|
+
typeof feature === "object" &&
|
|
110
|
+
typeof (feature as { signSponsoredTransaction?: unknown })
|
|
111
|
+
.signSponsoredTransaction === "function"
|
|
112
|
+
) {
|
|
113
|
+
return (feature as { signSponsoredTransaction: SponsoredTransactionMethod })
|
|
114
|
+
.signSponsoredTransaction;
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|