@evefrontier/dapp-kit 0.1.8 → 0.2.0-alpha.1
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 +28 -25
- package/dist/config/dapp-kit.d.ts +4 -0
- package/dist/config/dapp-kit.d.ts.map +1 -0
- package/dist/config/dapp-kit.js +14 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +1 -0
- package/dist/graphql/client.d.ts +277 -0
- package/dist/graphql/client.d.ts.map +1 -0
- package/dist/graphql/client.js +346 -0
- package/dist/graphql/index.d.ts +4 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +16 -0
- package/dist/graphql/queries.d.ts +103 -0
- package/dist/graphql/queries.d.ts.map +1 -0
- package/{graphql/queries.ts → dist/graphql/queries.js} +113 -223
- package/dist/graphql/types.d.ts +396 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +4 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useCharacterDirectory.d.ts +16 -0
- package/dist/hooks/useCharacterDirectory.d.ts.map +1 -0
- package/dist/hooks/useCharacterDirectory.js +23 -0
- package/dist/hooks/useCharacterSearch.d.ts +24 -0
- package/dist/hooks/useCharacterSearch.d.ts.map +1 -0
- package/dist/hooks/useCharacterSearch.js +24 -0
- package/dist/hooks/useConnection.d.ts +51 -0
- package/dist/hooks/useConnection.d.ts.map +1 -0
- package/{hooks/useConnection.ts → dist/hooks/useConnection.js} +8 -10
- package/dist/hooks/useEntityRole.d.ts +26 -0
- package/dist/hooks/useEntityRole.d.ts.map +1 -0
- package/dist/hooks/useEntityRole.js +91 -0
- package/dist/hooks/useNotification.d.ts +72 -0
- package/dist/hooks/useNotification.d.ts.map +1 -0
- package/{hooks/useNotification.ts → dist/hooks/useNotification.js} +8 -12
- package/dist/hooks/useSmartObject.d.ts +44 -0
- package/dist/hooks/useSmartObject.d.ts.map +1 -0
- package/dist/hooks/useSmartObject.js +50 -0
- package/dist/hooks/useSponsoredTransaction.d.ts +147 -0
- package/dist/hooks/useSponsoredTransaction.d.ts.map +1 -0
- package/dist/hooks/useSponsoredTransaction.js +240 -0
- package/dist/hooks/useTypeNames.d.ts +11 -0
- package/dist/hooks/useTypeNames.d.ts.map +1 -0
- package/dist/hooks/useTypeNames.js +24 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/providers/EveFrontierProvider.d.ts +23 -0
- package/dist/providers/EveFrontierProvider.d.ts.map +1 -0
- package/dist/providers/EveFrontierProvider.js +23 -0
- package/dist/providers/NotificationProvider.d.ts +14 -0
- package/dist/providers/NotificationProvider.d.ts.map +1 -0
- package/dist/providers/NotificationProvider.js +66 -0
- package/dist/providers/SmartObjectProvider.d.ts +31 -0
- package/dist/providers/SmartObjectProvider.d.ts.map +1 -0
- package/dist/providers/SmartObjectProvider.js +80 -0
- package/dist/providers/VaultProvider.d.ts +10 -0
- package/dist/providers/VaultProvider.d.ts.map +1 -0
- package/dist/providers/VaultProvider.js +79 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/smartObject/useEntityData.d.ts +29 -0
- package/dist/providers/smartObject/useEntityData.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntityData.js +135 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts +14 -0
- package/dist/providers/smartObject/useEntitySubscription.d.ts.map +1 -0
- package/dist/providers/smartObject/useEntitySubscription.js +58 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts +11 -0
- package/dist/providers/smartObject/useObjectSelection.d.ts.map +1 -0
- package/dist/providers/smartObject/useObjectSelection.js +27 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts +18 -0
- package/dist/providers/smartObject/usePollingBackstop.d.ts.map +1 -0
- package/dist/providers/smartObject/usePollingBackstop.js +38 -0
- package/dist/types/character.d.ts +21 -0
- package/dist/types/character.d.ts.map +1 -0
- package/dist/types/character.js +1 -0
- package/dist/types/contexts.d.ts +61 -0
- package/dist/types/contexts.d.ts.map +1 -0
- package/dist/types/contexts.js +6 -0
- package/dist/types/entity.d.ts +245 -0
- package/dist/types/entity.d.ts.map +1 -0
- package/dist/types/entity.js +6 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/sponsoredTransaction.d.ts +26 -0
- package/dist/types/sponsoredTransaction.d.ts.map +1 -0
- package/dist/types/sponsoredTransaction.js +10 -0
- package/dist/types/types.d.ts +110 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +41 -0
- package/dist/types/worldApiReturnTypes.d.ts +68 -0
- package/dist/types/worldApiReturnTypes.d.ts.map +1 -0
- package/dist/types/worldApiReturnTypes.js +1 -0
- package/{utils/burnRate.ts → dist/utils/burnRate.d.ts} +4 -29
- package/dist/utils/burnRate.d.ts.map +1 -0
- package/dist/utils/burnRate.js +25 -0
- package/dist/utils/characters.d.ts +26 -0
- package/dist/utils/characters.d.ts.map +1 -0
- package/dist/utils/characters.js +84 -0
- package/dist/utils/constants.d.ts +153 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +190 -0
- package/dist/utils/datahub.d.ts +40 -0
- package/dist/utils/datahub.d.ts.map +1 -0
- package/{utils/datahub.ts → dist/utils/datahub.js} +32 -25
- package/dist/utils/entity.d.ts +58 -0
- package/dist/utils/entity.d.ts.map +1 -0
- package/dist/utils/entity.js +386 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +128 -0
- package/dist/utils/events/entityEvents.d.ts +44 -0
- package/dist/utils/events/entityEvents.d.ts.map +1 -0
- package/dist/utils/events/entityEvents.js +95 -0
- package/dist/utils/events/entitySubscription.d.ts +30 -0
- package/dist/utils/events/entitySubscription.d.ts.map +1 -0
- package/dist/utils/events/entitySubscription.js +84 -0
- package/dist/utils/events/graphqlEventStream.d.ts +90 -0
- package/dist/utils/events/graphqlEventStream.d.ts.map +1 -0
- package/dist/utils/events/graphqlEventStream.js +198 -0
- package/dist/utils/events/refetchScheduler.d.ts +30 -0
- package/dist/utils/events/refetchScheduler.d.ts.map +1 -0
- package/dist/utils/events/refetchScheduler.js +57 -0
- package/dist/utils/events/sseClient.d.ts +42 -0
- package/dist/utils/events/sseClient.d.ts.map +1 -0
- package/dist/utils/events/sseClient.js +97 -0
- package/dist/utils/fuel.d.ts +231 -0
- package/dist/utils/fuel.d.ts.map +1 -0
- package/dist/utils/fuel.js +652 -0
- package/dist/utils/grid.d.ts +115 -0
- package/dist/utils/grid.d.ts.map +1 -0
- package/dist/utils/grid.js +115 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/inventory.d.ts +3 -0
- package/dist/utils/inventory.d.ts.map +1 -0
- package/dist/utils/inventory.js +12 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +228 -0
- package/dist/utils/mapping.d.ts +30 -0
- package/dist/utils/mapping.d.ts.map +1 -0
- package/dist/utils/mapping.js +73 -0
- package/dist/utils/mvr/worldTypes.d.ts +35 -0
- package/dist/utils/mvr/worldTypes.d.ts.map +1 -0
- package/dist/utils/mvr/worldTypes.js +54 -0
- package/dist/utils/role.d.ts +116 -0
- package/dist/utils/role.d.ts.map +1 -0
- package/dist/utils/role.js +120 -0
- package/dist/utils/smartObject.d.ts +24 -0
- package/dist/utils/smartObject.d.ts.map +1 -0
- package/dist/utils/smartObject.js +24 -0
- package/dist/utils/utils.d.ts +133 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +213 -0
- package/dist/wallet/features.d.ts +28 -0
- package/dist/wallet/features.d.ts.map +1 -0
- package/dist/wallet/features.js +22 -0
- package/dist/wallet/index.d.ts +9 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/index.js +9 -0
- package/dist/wallet/utils.d.ts +71 -0
- package/dist/wallet/utils.d.ts.map +1 -0
- package/dist/wallet/utils.js +79 -0
- package/package.json +69 -35
- package/config/dapp-kit.ts +0 -20
- package/config/index.ts +0 -1
- package/graphql/client.ts +0 -578
- package/graphql/index.ts +0 -39
- package/graphql/types.ts +0 -468
- package/hooks/index.ts +0 -15
- package/hooks/useSmartObject.ts +0 -66
- package/hooks/useSponsoredTransaction.ts +0 -442
- package/index.ts +0 -88
- package/providers/EveFrontierProvider.tsx +0 -41
- package/providers/NotificationProvider.tsx +0 -108
- package/providers/SmartObjectProvider.tsx +0 -296
- package/providers/VaultProvider.tsx +0 -108
- package/providers/index.ts +0 -10
- package/types/contexts.ts +0 -67
- package/types/global.d.ts +0 -7
- package/types/index.ts +0 -4
- package/types/sponsoredTransaction.ts +0 -70
- package/types/types.ts +0 -198
- package/types/worldApiReturnTypes.ts +0 -144
- package/utils/__tests__/burnRate.test.ts +0 -121
- package/utils/__tests__/character.test.ts +0 -112
- package/utils/__tests__/characterOwnedObjects.test.ts +0 -225
- package/utils/__tests__/config.test.ts +0 -424
- package/utils/__tests__/datahub.test.ts +0 -58
- package/utils/__tests__/logger.test.ts +0 -145
- package/utils/__tests__/mapping.test.ts +0 -439
- package/utils/__tests__/utils.test.ts +0 -299
- package/utils/character.ts +0 -46
- package/utils/characterOwnedObjects.ts +0 -53
- package/utils/config.ts +0 -151
- package/utils/constants.ts +0 -254
- package/utils/errors.ts +0 -171
- package/utils/index.ts +0 -47
- package/utils/logger.ts +0 -300
- package/utils/mapping.ts +0 -118
- package/utils/transforms.ts +0 -263
- package/utils/utils.ts +0 -270
- package/wallet/features.ts +0 -136
- package/wallet/index.ts +0 -26
- package/wallet/utils.ts +0 -117
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { findCharactersByWallet, getEntityRole, needsCharacterDirectory, } from '../utils/role.js';
|
|
3
|
+
import { useCharacterDirectory } from './useCharacterDirectory.js';
|
|
4
|
+
import { useConnection } from './useConnection.js';
|
|
5
|
+
import { useSmartObject } from './useSmartObject.js';
|
|
6
|
+
/**
|
|
7
|
+
* Hook for the connected wallet's role on the selected entity: `shell`,
|
|
8
|
+
* `controller` or `visitor`. See {@link getEntityRole}.
|
|
9
|
+
*
|
|
10
|
+
* Without `options.characterId`, the wallet's character is looked up in the
|
|
11
|
+
* character directory, which is only fetched when it can change the answer: a
|
|
12
|
+
* wallet is connected, it is not the shell's, and the entity has controllers
|
|
13
|
+
* or its cap is parked on a character. Until it loads, the role reads
|
|
14
|
+
* `visitor` with `isLoading` true.
|
|
15
|
+
*
|
|
16
|
+
* @category Hooks - Access
|
|
17
|
+
* @param options.characterId - The wallet's character id, when the caller knows it
|
|
18
|
+
* @returns
|
|
19
|
+
* - `role` - The wallet's role
|
|
20
|
+
* - `characterId` - The wallet's character id, when known
|
|
21
|
+
* - `isLoading` - True while the directory is loading for this answer
|
|
22
|
+
*/
|
|
23
|
+
export function useEntityRole(options = {}) {
|
|
24
|
+
const { entity, entityOwner } = useSmartObject();
|
|
25
|
+
const { currentAccount } = useConnection();
|
|
26
|
+
const walletAddress = currentAccount?.address ?? null;
|
|
27
|
+
const controllers = entity?.controllers ?? null;
|
|
28
|
+
const knownCharacterId = options.characterId ?? null;
|
|
29
|
+
const needsDirectory = needsCharacterDirectory({
|
|
30
|
+
walletAddress,
|
|
31
|
+
entityOwner,
|
|
32
|
+
controllers,
|
|
33
|
+
knownCharacterId,
|
|
34
|
+
});
|
|
35
|
+
const directory = useCharacterDirectory({ enabled: needsDirectory });
|
|
36
|
+
return useMemo(() => {
|
|
37
|
+
const isLoading = needsDirectory && directory.isLoading;
|
|
38
|
+
if (knownCharacterId) {
|
|
39
|
+
return {
|
|
40
|
+
role: getEntityRole({
|
|
41
|
+
walletAddress,
|
|
42
|
+
entityOwner,
|
|
43
|
+
controllers,
|
|
44
|
+
characterId: knownCharacterId,
|
|
45
|
+
}),
|
|
46
|
+
characterId: knownCharacterId,
|
|
47
|
+
isLoading,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const candidates = needsDirectory
|
|
51
|
+
? findCharactersByWallet(directory.data ?? [], walletAddress)
|
|
52
|
+
: [];
|
|
53
|
+
if (candidates.length === 0) {
|
|
54
|
+
return {
|
|
55
|
+
role: getEntityRole({
|
|
56
|
+
walletAddress,
|
|
57
|
+
entityOwner,
|
|
58
|
+
controllers,
|
|
59
|
+
characterId: null,
|
|
60
|
+
}),
|
|
61
|
+
characterId: null,
|
|
62
|
+
isLoading,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// A wallet can be bound to multiple characters. Resolve the
|
|
66
|
+
// highest-privilege role across all of them (shell > controller > visitor).
|
|
67
|
+
const ROLE_ORDER = ['shell', 'controller', 'visitor'];
|
|
68
|
+
let bestIdx = ROLE_ORDER.length - 1;
|
|
69
|
+
let bestCharacterId = null;
|
|
70
|
+
for (const { characterId } of candidates) {
|
|
71
|
+
const idx = ROLE_ORDER.indexOf(getEntityRole({ walletAddress, entityOwner, controllers, characterId }));
|
|
72
|
+
if (idx < bestIdx) {
|
|
73
|
+
bestIdx = idx;
|
|
74
|
+
bestCharacterId = characterId;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
role: ROLE_ORDER[bestIdx] ?? 'visitor',
|
|
79
|
+
characterId: bestCharacterId,
|
|
80
|
+
isLoading,
|
|
81
|
+
};
|
|
82
|
+
}, [
|
|
83
|
+
knownCharacterId,
|
|
84
|
+
needsDirectory,
|
|
85
|
+
directory.data,
|
|
86
|
+
directory.isLoading,
|
|
87
|
+
walletAddress,
|
|
88
|
+
entityOwner,
|
|
89
|
+
controllers,
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { NotificationContextType } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for displaying user notifications in EVE Frontier dApps.
|
|
4
|
+
*
|
|
5
|
+
* Provides a simple notification system for displaying success, error, warning,
|
|
6
|
+
* and info messages to users. Commonly used after transaction completions
|
|
7
|
+
* or to display important status updates.
|
|
8
|
+
*
|
|
9
|
+
* @category Hooks - Notification
|
|
10
|
+
* @returns Object containing notification state and methods:
|
|
11
|
+
* - `notify` - Function to trigger a notification
|
|
12
|
+
* - `notification` - Current notification state object with:
|
|
13
|
+
* - `isOpen` - Whether notification is visible
|
|
14
|
+
* - `message` - The notification message
|
|
15
|
+
* - `severity` - The notification type (success, error, warning, info)
|
|
16
|
+
* - `txHash` - Optional transaction hash for linking
|
|
17
|
+
* - `handleClose` - Function to close the notification
|
|
18
|
+
* @throws {Error} If used outside of `EveFrontierProvider`
|
|
19
|
+
*
|
|
20
|
+
* @example Basic notification
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import { useNotification, Severity } from '@evefrontier/dapp-kit';
|
|
23
|
+
*
|
|
24
|
+
* const MyComponent = () => {
|
|
25
|
+
* const { notify } = useNotification();
|
|
26
|
+
*
|
|
27
|
+
* const showSuccess = () => {
|
|
28
|
+
* notify({ type: Severity.Success, message: 'Operation completed!' });
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* return <button onClick={showSuccess}>Complete</button>;
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Transaction notification with hash
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const { notify } = useNotification();
|
|
38
|
+
*
|
|
39
|
+
* const handleTransaction = async () => {
|
|
40
|
+
* try {
|
|
41
|
+
* const result = await sendTransaction();
|
|
42
|
+
* notify({
|
|
43
|
+
* type: Severity.Success,
|
|
44
|
+
* message: 'Transaction successful!',
|
|
45
|
+
* txHash: result.digest
|
|
46
|
+
* });
|
|
47
|
+
* } catch (error) {
|
|
48
|
+
* notify({
|
|
49
|
+
* type: Severity.Error,
|
|
50
|
+
* message: 'Transaction failed'
|
|
51
|
+
* });
|
|
52
|
+
* }
|
|
53
|
+
* };
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Displaying notification UI
|
|
57
|
+
* ```tsx
|
|
58
|
+
* const { notification } = useNotification();
|
|
59
|
+
*
|
|
60
|
+
* return (
|
|
61
|
+
* <>
|
|
62
|
+
* {notification.isOpen && (
|
|
63
|
+
* <Alert severity={notification.severity} onClose={notification.handleClose}>
|
|
64
|
+
* {notification.message}
|
|
65
|
+
* </Alert>
|
|
66
|
+
* )}
|
|
67
|
+
* </>
|
|
68
|
+
* );
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function useNotification(): NotificationContextType;
|
|
72
|
+
//# sourceMappingURL=useNotification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNotification.d.ts","sourceRoot":"","sources":["../../hooks/useNotification.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,wBAAgB,eAAe,IAAI,uBAAuB,CAQzD"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { useContext } from
|
|
2
|
-
import { NotificationContext } from
|
|
3
|
-
import { NotificationContextType } from "../types";
|
|
4
|
-
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { NotificationContext } from '../providers/NotificationProvider.js';
|
|
5
3
|
/**
|
|
6
4
|
* Hook for displaying user notifications in EVE Frontier dApps.
|
|
7
5
|
*
|
|
@@ -71,12 +69,10 @@ import { NotificationContextType } from "../types";
|
|
|
71
69
|
* );
|
|
72
70
|
* ```
|
|
73
71
|
*/
|
|
74
|
-
export function useNotification()
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
return context;
|
|
72
|
+
export function useNotification() {
|
|
73
|
+
const context = useContext(NotificationContext);
|
|
74
|
+
if (!context) {
|
|
75
|
+
throw new Error('useNotification must be used within an EveFrontierProvider');
|
|
76
|
+
}
|
|
77
|
+
return context;
|
|
82
78
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { SmartObjectContextType } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for accessing the selected world entity from the Sui GraphQL Indexer.
|
|
4
|
+
*
|
|
5
|
+
* Provides reactive access to the selected entity (its components, layout,
|
|
6
|
+
* power grid, inventories and actions) with polling for updates. The entity is
|
|
7
|
+
* determined from URL query parameters (`?itemId=` and `?tenant=`, derived
|
|
8
|
+
* through the core ObjectRegistry) or from the `VITE_OBJECT_ID` environment
|
|
9
|
+
* variable as a Sui object ID.
|
|
10
|
+
*
|
|
11
|
+
* @category Hooks - Smart Object
|
|
12
|
+
* @returns Object containing entity state and methods:
|
|
13
|
+
* - `entity` - The parsed entity (or null if not loaded)
|
|
14
|
+
* - `entityOwner` - Who holds the entity's AccessCap, and their Character (or null)
|
|
15
|
+
* - `loading` - Boolean indicating if data is being fetched
|
|
16
|
+
* - `error` - Error message string (or null)
|
|
17
|
+
* - `refetch` - Function to manually refresh entity data with retries
|
|
18
|
+
* - `assembly` / `assemblyOwner` - Deprecated, always null
|
|
19
|
+
* @throws {Error} If used outside of `EveFrontierProvider`
|
|
20
|
+
*
|
|
21
|
+
* @example Basic usage
|
|
22
|
+
* ```tsx
|
|
23
|
+
* import { useSmartObject } from '@evefrontier/dapp-kit';
|
|
24
|
+
*
|
|
25
|
+
* const EntityInfo = () => {
|
|
26
|
+
* const { entity, entityOwner, loading, error, refetch } = useSmartObject();
|
|
27
|
+
*
|
|
28
|
+
* if (loading) return <div>Loading...</div>;
|
|
29
|
+
* if (error) return <div>Error: {error}</div>;
|
|
30
|
+
* if (!entity) return <div>No entity found</div>;
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <div>
|
|
34
|
+
* <h1>{entity.metadata?.name ?? entity.key.id}</h1>
|
|
35
|
+
* <p>Power: {entity.powerGrid?.on ? 'on' : 'off'}</p>
|
|
36
|
+
* <p>Owner: {entityOwner?.character?.metadata?.name ?? entityOwner?.walletAddress}</p>
|
|
37
|
+
* <button onClick={refetch}>Refresh</button>
|
|
38
|
+
* </div>
|
|
39
|
+
* );
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function useSmartObject(): SmartObjectContextType;
|
|
44
|
+
//# sourceMappingURL=useSmartObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSmartObject.d.ts","sourceRoot":"","sources":["../../hooks/useSmartObject.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,cAAc,IAAI,sBAAsB,CAMvD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { SmartObjectContext } from '../providers/SmartObjectProvider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for accessing the selected world entity from the Sui GraphQL Indexer.
|
|
5
|
+
*
|
|
6
|
+
* Provides reactive access to the selected entity (its components, layout,
|
|
7
|
+
* power grid, inventories and actions) with polling for updates. The entity is
|
|
8
|
+
* determined from URL query parameters (`?itemId=` and `?tenant=`, derived
|
|
9
|
+
* through the core ObjectRegistry) or from the `VITE_OBJECT_ID` environment
|
|
10
|
+
* variable as a Sui object ID.
|
|
11
|
+
*
|
|
12
|
+
* @category Hooks - Smart Object
|
|
13
|
+
* @returns Object containing entity state and methods:
|
|
14
|
+
* - `entity` - The parsed entity (or null if not loaded)
|
|
15
|
+
* - `entityOwner` - Who holds the entity's AccessCap, and their Character (or null)
|
|
16
|
+
* - `loading` - Boolean indicating if data is being fetched
|
|
17
|
+
* - `error` - Error message string (or null)
|
|
18
|
+
* - `refetch` - Function to manually refresh entity data with retries
|
|
19
|
+
* - `assembly` / `assemblyOwner` - Deprecated, always null
|
|
20
|
+
* @throws {Error} If used outside of `EveFrontierProvider`
|
|
21
|
+
*
|
|
22
|
+
* @example Basic usage
|
|
23
|
+
* ```tsx
|
|
24
|
+
* import { useSmartObject } from '@evefrontier/dapp-kit';
|
|
25
|
+
*
|
|
26
|
+
* const EntityInfo = () => {
|
|
27
|
+
* const { entity, entityOwner, loading, error, refetch } = useSmartObject();
|
|
28
|
+
*
|
|
29
|
+
* if (loading) return <div>Loading...</div>;
|
|
30
|
+
* if (error) return <div>Error: {error}</div>;
|
|
31
|
+
* if (!entity) return <div>No entity found</div>;
|
|
32
|
+
*
|
|
33
|
+
* return (
|
|
34
|
+
* <div>
|
|
35
|
+
* <h1>{entity.metadata?.name ?? entity.key.id}</h1>
|
|
36
|
+
* <p>Power: {entity.powerGrid?.on ? 'on' : 'off'}</p>
|
|
37
|
+
* <p>Owner: {entityOwner?.character?.metadata?.name ?? entityOwner?.walletAddress}</p>
|
|
38
|
+
* <button onClick={refetch}>Refresh</button>
|
|
39
|
+
* </div>
|
|
40
|
+
* );
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function useSmartObject() {
|
|
45
|
+
const context = useContext(SmartObjectContext);
|
|
46
|
+
if (!context) {
|
|
47
|
+
throw new Error('useSmartObject must be used within an EveFrontierProvider');
|
|
48
|
+
}
|
|
49
|
+
return context;
|
|
50
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { type UseMutationOptions, type UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import { type SponsoredTransactionArgs, type SponsoredTransactionOutput } from '../wallet/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when the connected wallet doesn't support EVE Frontier sponsored transactions.
|
|
5
|
+
*
|
|
6
|
+
* This occurs when the wallet doesn't implement the `evefrontier:sponsoredTransaction` feature.
|
|
7
|
+
* Currently, only EVE Vault wallet supports this feature.
|
|
8
|
+
*
|
|
9
|
+
* @category Errors
|
|
10
|
+
*/
|
|
11
|
+
export declare class WalletSponsoredTransactionNotSupportedError extends Error {
|
|
12
|
+
constructor(walletName?: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when attempting a sponsored transaction without a connected wallet.
|
|
16
|
+
*
|
|
17
|
+
* @category Errors
|
|
18
|
+
*/
|
|
19
|
+
export declare class WalletNotConnectedError extends Error {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown when no account is selected in the connected wallet.
|
|
24
|
+
*
|
|
25
|
+
* @category Errors
|
|
26
|
+
*/
|
|
27
|
+
export declare class WalletNoAccountSelectedError extends Error {
|
|
28
|
+
constructor();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Error union type for {@link useSponsoredTransaction} mutation failures.
|
|
32
|
+
*
|
|
33
|
+
* @category Hooks - Sponsored Transaction
|
|
34
|
+
*/
|
|
35
|
+
export type UseSponsoredTransactionError = WalletSponsoredTransactionNotSupportedError | WalletNotConnectedError | WalletNoAccountSelectedError | Error;
|
|
36
|
+
/**
|
|
37
|
+
* Arguments passed to {@link useSponsoredTransaction} mutate/mutateAsync.
|
|
38
|
+
* With assembly object (id and type derived).
|
|
39
|
+
*
|
|
40
|
+
* @category Hooks - Sponsored Transaction
|
|
41
|
+
*/
|
|
42
|
+
export type UseSponsoredTransactionArgs = SponsoredTransactionArgs;
|
|
43
|
+
/**
|
|
44
|
+
* React Query mutation options for {@link useSponsoredTransaction}.
|
|
45
|
+
*
|
|
46
|
+
* @category Hooks - Sponsored Transaction
|
|
47
|
+
*/
|
|
48
|
+
export type UseSponsoredTransactionMutationOptions = Omit<UseMutationOptions<SponsoredTransactionOutput, UseSponsoredTransactionError, UseSponsoredTransactionArgs>, 'mutationFn'>;
|
|
49
|
+
/**
|
|
50
|
+
* Hook for executing gas-sponsored transactions via EVE Frontier.
|
|
51
|
+
*
|
|
52
|
+
* This mutation hook enables dApps to send transactions where gas fees are paid
|
|
53
|
+
* by the EVE Frontier backend service, eliminating the need for users to have SUI
|
|
54
|
+
* tokens for gas. The wallet must support the `evefrontier:sponsoredTransaction` feature
|
|
55
|
+
* (currently only EVE Vault).
|
|
56
|
+
*
|
|
57
|
+
* Transient server errors (e.g. 502 Bad Gateway) are retried automatically with the same
|
|
58
|
+
* payload a limited number of times with a delay between attempts.
|
|
59
|
+
*
|
|
60
|
+
* The hook automatically uses the currently connected wallet and account (unless overridden)
|
|
61
|
+
* and handles wallet feature detection and validation.
|
|
62
|
+
*
|
|
63
|
+
* **Input** (passed to `mutate` / `mutateAsync`):
|
|
64
|
+
* - `txAction` (required) – The sponsored action to run (`UPDATE_METADATA` or `SET_POWER_GRID`).
|
|
65
|
+
* - `entityId` (required) – In-game entity id (`EntityKey.id`), uint64 decimal string.
|
|
66
|
+
* - `metadata` (required for `UPDATE_METADATA`) – `{ name, description, url }`. All three are required; send `''` to clear one.
|
|
67
|
+
* - `on` (required for `SET_POWER_GRID`) – `true` to switch the power grid on, `false` to switch it off.
|
|
68
|
+
* - `tenant` (optional) – Not sent in the wire payload; reserved for future use.
|
|
69
|
+
* - `account` (optional) – Signer address. If omitted, the currently connected wallet account is used.
|
|
70
|
+
*
|
|
71
|
+
* **Output** (on success, in `data` or resolved from `mutateAsync`):
|
|
72
|
+
* - `digest` (required) – Transaction digest.
|
|
73
|
+
* - `executionStatus` (required) – On-chain execution status reported by the gateway (e.g. `"success"`).
|
|
74
|
+
* - `executionErrorMessage` (optional) – Error message when the on-chain execution failed; absent on success.
|
|
75
|
+
*
|
|
76
|
+
* @category Hooks - Sponsored Transaction
|
|
77
|
+
* @param options - React Query mutation options (optional)
|
|
78
|
+
* @returns React Query mutation result with:
|
|
79
|
+
* - `mutate(args, options?)` - Trigger transaction (fire-and-forget)
|
|
80
|
+
* - `mutateAsync(args)` - Trigger transaction (returns Promise<SponsoredTransactionOutput>)
|
|
81
|
+
* - `isPending` - True while the transaction is in progress
|
|
82
|
+
* - `isError` - True if the last mutation failed
|
|
83
|
+
* - `error` - Error from the last failed mutation
|
|
84
|
+
* - `data` - Last successful result (`SponsoredTransactionOutput`)
|
|
85
|
+
*
|
|
86
|
+
* @throws {WalletNotConnectedError} If no wallet is connected
|
|
87
|
+
* @throws {WalletNoAccountSelectedError} If no account is selected
|
|
88
|
+
* @throws {WalletSponsoredTransactionNotSupportedError} If wallet doesn't support sponsored transactions
|
|
89
|
+
*
|
|
90
|
+
* @example Set power grid on
|
|
91
|
+
* ```tsx
|
|
92
|
+
* import { useSponsoredTransaction, SponsoredTransactionActions, useSmartObject } from "@evefrontier/dapp-kit";
|
|
93
|
+
*
|
|
94
|
+
* const BringOnlineButton = () => {
|
|
95
|
+
* const { entity } = useSmartObject();
|
|
96
|
+
* const { mutateAsync: sendTx, isPending } = useSponsoredTransaction();
|
|
97
|
+
*
|
|
98
|
+
* const handleBringOnline = async () => {
|
|
99
|
+
* if (!entity) return;
|
|
100
|
+
* try {
|
|
101
|
+
* const result = await sendTx({
|
|
102
|
+
* txAction: SponsoredTransactionActions.SET_POWER_GRID,
|
|
103
|
+
* entityId: entity.key.id,
|
|
104
|
+
* on: true,
|
|
105
|
+
* });
|
|
106
|
+
* console.log("Transaction digest:", result.digest);
|
|
107
|
+
* } catch (error) {
|
|
108
|
+
* console.error("Transaction failed:", error);
|
|
109
|
+
* }
|
|
110
|
+
* };
|
|
111
|
+
*
|
|
112
|
+
* return (
|
|
113
|
+
* <button onClick={handleBringOnline} disabled={isPending || !entity}>
|
|
114
|
+
* {isPending ? "Processing..." : "Bring Online"}
|
|
115
|
+
* </button>
|
|
116
|
+
* );
|
|
117
|
+
* };
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example Update metadata with callbacks
|
|
121
|
+
* ```tsx
|
|
122
|
+
* const { entity } = useSmartObject();
|
|
123
|
+
* const { mutate: sendTx } = useSponsoredTransaction();
|
|
124
|
+
*
|
|
125
|
+
* sendTx(
|
|
126
|
+
* {
|
|
127
|
+
* txAction: SponsoredTransactionActions.UPDATE_METADATA,
|
|
128
|
+
* entityId: entity.key.id,
|
|
129
|
+
* metadata: { name: "My Station", description: "Forward post", url: "" },
|
|
130
|
+
* },
|
|
131
|
+
* {
|
|
132
|
+
* onSuccess: (result) => {
|
|
133
|
+
* notify({ type: Severity.Success, txHash: result.digest });
|
|
134
|
+
* },
|
|
135
|
+
* onError: (error) => {
|
|
136
|
+
* notify({ type: Severity.Error, message: error.message });
|
|
137
|
+
* },
|
|
138
|
+
* }
|
|
139
|
+
* );
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @see {@link SponsoredTransactionActions} for available transaction actions
|
|
143
|
+
* @see {@link SponsoredTransactionInput} for full input type
|
|
144
|
+
* @see {@link SponsoredTransactionOutput} for full output type
|
|
145
|
+
*/
|
|
146
|
+
export declare function useSponsoredTransaction({ mutationKey, ...mutationOptions }?: UseSponsoredTransactionMutationOptions): UseMutationResult<SponsoredTransactionOutput, UseSponsoredTransactionError, UseSponsoredTransactionArgs>;
|
|
147
|
+
//# sourceMappingURL=useSponsoredTransaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSponsoredTransaction.d.ts","sourceRoot":"","sources":["../../hooks/useSponsoredTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEvB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAEL,KAAK,wBAAwB,EAE7B,KAAK,0BAA0B,EAEhC,MAAM,WAAW,CAAA;AAgBlB;;;;;;;GAOG;AACH,qBAAa,2CAA4C,SAAQ,KAAK;IACpE,YAAY,UAAU,CAAC,EAAE,MAAM,EAO9B;CACF;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,cAGC;CACF;AAED;;;;GAIG;AACH,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,cAGC;CACF;AA+BD;;;;GAIG;AACH,MAAM,MAAM,4BAA4B,GACpC,2CAA2C,GAC3C,uBAAuB,GACvB,4BAA4B,GAC5B,KAAK,CAAA;AAET;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG,wBAAwB,CAAA;AAElE;;;;GAIG;AACH,MAAM,MAAM,sCAAsC,GAAG,IAAI,CACvD,kBAAkB,CAChB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,CAC5B,EACD,YAAY,CACb,CAAA;AAgFD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgGG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,WAAW,EACX,GAAG,eAAe,EACnB,GAAE,sCAA2C,GAAG,iBAAiB,CAChE,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,CAC5B,CA2BA"}
|