@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,240 @@
|
|
|
1
|
+
import { useCurrentAccount, useDAppKit } from '@mysten/dapp-kit-react';
|
|
2
|
+
import { useMutation, } from '@tanstack/react-query';
|
|
3
|
+
import { createLogger } from '../utils/index.js';
|
|
4
|
+
import { getSponsoredTransactionFeature, supportsSponsoredTransaction, } from '../wallet/index.js';
|
|
5
|
+
const log = createLogger();
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Error Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when the connected wallet doesn't support EVE Frontier sponsored transactions.
|
|
11
|
+
*
|
|
12
|
+
* This occurs when the wallet doesn't implement the `evefrontier:sponsoredTransaction` feature.
|
|
13
|
+
* Currently, only EVE Vault wallet supports this feature.
|
|
14
|
+
*
|
|
15
|
+
* @category Errors
|
|
16
|
+
*/
|
|
17
|
+
export class WalletSponsoredTransactionNotSupportedError extends Error {
|
|
18
|
+
constructor(walletName) {
|
|
19
|
+
super(walletName
|
|
20
|
+
? `Wallet "${walletName}" does not support sponsored transactions`
|
|
21
|
+
: 'Connected wallet does not support sponsored transactions');
|
|
22
|
+
this.name = 'WalletSponsoredTransactionNotSupportedError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when attempting a sponsored transaction without a connected wallet.
|
|
27
|
+
*
|
|
28
|
+
* @category Errors
|
|
29
|
+
*/
|
|
30
|
+
export class WalletNotConnectedError extends Error {
|
|
31
|
+
constructor() {
|
|
32
|
+
super('No wallet connected');
|
|
33
|
+
this.name = 'WalletNotConnectedError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Error thrown when no account is selected in the connected wallet.
|
|
38
|
+
*
|
|
39
|
+
* @category Errors
|
|
40
|
+
*/
|
|
41
|
+
export class WalletNoAccountSelectedError extends Error {
|
|
42
|
+
constructor() {
|
|
43
|
+
super('No account selected in wallet');
|
|
44
|
+
this.name = 'WalletNoAccountSelectedError';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Retry helpers (502 Bad Gateway)
|
|
49
|
+
// ============================================================================
|
|
50
|
+
const DEFAULT_MAX_RETRIES = 2;
|
|
51
|
+
const DEFAULT_RETRY_DELAY_MS = 1500;
|
|
52
|
+
function delay(ms) {
|
|
53
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns true if the error indicates a 502 (or similar transient server error)
|
|
57
|
+
* where retrying the same payload is safe.
|
|
58
|
+
*/
|
|
59
|
+
function isRetryableSponsorError(error) {
|
|
60
|
+
if (error instanceof Error) {
|
|
61
|
+
const msg = error.message.toLowerCase();
|
|
62
|
+
if (msg.includes('502') || msg.includes('bad gateway'))
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const withResponse = error;
|
|
66
|
+
if (withResponse?.response?.status === 502)
|
|
67
|
+
return true;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/** Resolves the connected wallet at call time from the dApp Kit connection store. */
|
|
71
|
+
function getConnectedWallet(dAppKit) {
|
|
72
|
+
const connection = typeof dAppKit.stores?.$connection?.get === 'function'
|
|
73
|
+
? dAppKit.stores.$connection.get()
|
|
74
|
+
: null;
|
|
75
|
+
const wallet = connection?.wallet ?? null;
|
|
76
|
+
if (!wallet) {
|
|
77
|
+
throw new WalletNotConnectedError();
|
|
78
|
+
}
|
|
79
|
+
return wallet;
|
|
80
|
+
}
|
|
81
|
+
/** Returns the wallet's sponsored transaction signer, or throws if it has none. */
|
|
82
|
+
function getSponsoredSigner(wallet) {
|
|
83
|
+
if (!supportsSponsoredTransaction(wallet.features)) {
|
|
84
|
+
throw new WalletSponsoredTransactionNotSupportedError(wallet.name);
|
|
85
|
+
}
|
|
86
|
+
const signSponsoredTransaction = getSponsoredTransactionFeature(wallet);
|
|
87
|
+
if (!signSponsoredTransaction) {
|
|
88
|
+
throw new WalletSponsoredTransactionNotSupportedError(wallet.name);
|
|
89
|
+
}
|
|
90
|
+
return signSponsoredTransaction;
|
|
91
|
+
}
|
|
92
|
+
/** Strips hook-only fields (account, tenant) and returns the wire payload. */
|
|
93
|
+
function buildSponsoredPayload(args) {
|
|
94
|
+
const { account: _account, tenant: _tenant, ...payload } = args;
|
|
95
|
+
if (typeof payload.entityId !== 'string' || !/^\d+$/.test(payload.entityId)) {
|
|
96
|
+
throw new Error(`entityId must be a uint64 decimal string; got "${String(payload.entityId)}"`);
|
|
97
|
+
}
|
|
98
|
+
return payload;
|
|
99
|
+
}
|
|
100
|
+
/** Signs and submits the payload, retrying transient (502) gateway errors. */
|
|
101
|
+
async function signWithRetries(signSponsoredTransaction, payload) {
|
|
102
|
+
let lastError;
|
|
103
|
+
const maxAttempts = DEFAULT_MAX_RETRIES + 1;
|
|
104
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
105
|
+
try {
|
|
106
|
+
return await signSponsoredTransaction(payload);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
lastError = e;
|
|
110
|
+
const canRetry = attempt < maxAttempts && isRetryableSponsorError(e);
|
|
111
|
+
if (!canRetry)
|
|
112
|
+
throw e;
|
|
113
|
+
await delay(DEFAULT_RETRY_DELAY_MS);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw lastError;
|
|
117
|
+
}
|
|
118
|
+
// ============================================================================
|
|
119
|
+
// Hook Implementation
|
|
120
|
+
// ============================================================================
|
|
121
|
+
/**
|
|
122
|
+
* Hook for executing gas-sponsored transactions via EVE Frontier.
|
|
123
|
+
*
|
|
124
|
+
* This mutation hook enables dApps to send transactions where gas fees are paid
|
|
125
|
+
* by the EVE Frontier backend service, eliminating the need for users to have SUI
|
|
126
|
+
* tokens for gas. The wallet must support the `evefrontier:sponsoredTransaction` feature
|
|
127
|
+
* (currently only EVE Vault).
|
|
128
|
+
*
|
|
129
|
+
* Transient server errors (e.g. 502 Bad Gateway) are retried automatically with the same
|
|
130
|
+
* payload a limited number of times with a delay between attempts.
|
|
131
|
+
*
|
|
132
|
+
* The hook automatically uses the currently connected wallet and account (unless overridden)
|
|
133
|
+
* and handles wallet feature detection and validation.
|
|
134
|
+
*
|
|
135
|
+
* **Input** (passed to `mutate` / `mutateAsync`):
|
|
136
|
+
* - `txAction` (required) – The sponsored action to run (`UPDATE_METADATA` or `SET_POWER_GRID`).
|
|
137
|
+
* - `entityId` (required) – In-game entity id (`EntityKey.id`), uint64 decimal string.
|
|
138
|
+
* - `metadata` (required for `UPDATE_METADATA`) – `{ name, description, url }`. All three are required; send `''` to clear one.
|
|
139
|
+
* - `on` (required for `SET_POWER_GRID`) – `true` to switch the power grid on, `false` to switch it off.
|
|
140
|
+
* - `tenant` (optional) – Not sent in the wire payload; reserved for future use.
|
|
141
|
+
* - `account` (optional) – Signer address. If omitted, the currently connected wallet account is used.
|
|
142
|
+
*
|
|
143
|
+
* **Output** (on success, in `data` or resolved from `mutateAsync`):
|
|
144
|
+
* - `digest` (required) – Transaction digest.
|
|
145
|
+
* - `executionStatus` (required) – On-chain execution status reported by the gateway (e.g. `"success"`).
|
|
146
|
+
* - `executionErrorMessage` (optional) – Error message when the on-chain execution failed; absent on success.
|
|
147
|
+
*
|
|
148
|
+
* @category Hooks - Sponsored Transaction
|
|
149
|
+
* @param options - React Query mutation options (optional)
|
|
150
|
+
* @returns React Query mutation result with:
|
|
151
|
+
* - `mutate(args, options?)` - Trigger transaction (fire-and-forget)
|
|
152
|
+
* - `mutateAsync(args)` - Trigger transaction (returns Promise<SponsoredTransactionOutput>)
|
|
153
|
+
* - `isPending` - True while the transaction is in progress
|
|
154
|
+
* - `isError` - True if the last mutation failed
|
|
155
|
+
* - `error` - Error from the last failed mutation
|
|
156
|
+
* - `data` - Last successful result (`SponsoredTransactionOutput`)
|
|
157
|
+
*
|
|
158
|
+
* @throws {WalletNotConnectedError} If no wallet is connected
|
|
159
|
+
* @throws {WalletNoAccountSelectedError} If no account is selected
|
|
160
|
+
* @throws {WalletSponsoredTransactionNotSupportedError} If wallet doesn't support sponsored transactions
|
|
161
|
+
*
|
|
162
|
+
* @example Set power grid on
|
|
163
|
+
* ```tsx
|
|
164
|
+
* import { useSponsoredTransaction, SponsoredTransactionActions, useSmartObject } from "@evefrontier/dapp-kit";
|
|
165
|
+
*
|
|
166
|
+
* const BringOnlineButton = () => {
|
|
167
|
+
* const { entity } = useSmartObject();
|
|
168
|
+
* const { mutateAsync: sendTx, isPending } = useSponsoredTransaction();
|
|
169
|
+
*
|
|
170
|
+
* const handleBringOnline = async () => {
|
|
171
|
+
* if (!entity) return;
|
|
172
|
+
* try {
|
|
173
|
+
* const result = await sendTx({
|
|
174
|
+
* txAction: SponsoredTransactionActions.SET_POWER_GRID,
|
|
175
|
+
* entityId: entity.key.id,
|
|
176
|
+
* on: true,
|
|
177
|
+
* });
|
|
178
|
+
* console.log("Transaction digest:", result.digest);
|
|
179
|
+
* } catch (error) {
|
|
180
|
+
* console.error("Transaction failed:", error);
|
|
181
|
+
* }
|
|
182
|
+
* };
|
|
183
|
+
*
|
|
184
|
+
* return (
|
|
185
|
+
* <button onClick={handleBringOnline} disabled={isPending || !entity}>
|
|
186
|
+
* {isPending ? "Processing..." : "Bring Online"}
|
|
187
|
+
* </button>
|
|
188
|
+
* );
|
|
189
|
+
* };
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @example Update metadata with callbacks
|
|
193
|
+
* ```tsx
|
|
194
|
+
* const { entity } = useSmartObject();
|
|
195
|
+
* const { mutate: sendTx } = useSponsoredTransaction();
|
|
196
|
+
*
|
|
197
|
+
* sendTx(
|
|
198
|
+
* {
|
|
199
|
+
* txAction: SponsoredTransactionActions.UPDATE_METADATA,
|
|
200
|
+
* entityId: entity.key.id,
|
|
201
|
+
* metadata: { name: "My Station", description: "Forward post", url: "" },
|
|
202
|
+
* },
|
|
203
|
+
* {
|
|
204
|
+
* onSuccess: (result) => {
|
|
205
|
+
* notify({ type: Severity.Success, txHash: result.digest });
|
|
206
|
+
* },
|
|
207
|
+
* onError: (error) => {
|
|
208
|
+
* notify({ type: Severity.Error, message: error.message });
|
|
209
|
+
* },
|
|
210
|
+
* }
|
|
211
|
+
* );
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @see {@link SponsoredTransactionActions} for available transaction actions
|
|
215
|
+
* @see {@link SponsoredTransactionInput} for full input type
|
|
216
|
+
* @see {@link SponsoredTransactionOutput} for full output type
|
|
217
|
+
*/
|
|
218
|
+
export function useSponsoredTransaction({ mutationKey, ...mutationOptions } = {}) {
|
|
219
|
+
const dAppKit = useDAppKit();
|
|
220
|
+
const currentAccount = useCurrentAccount();
|
|
221
|
+
return useMutation({
|
|
222
|
+
mutationKey: [
|
|
223
|
+
'evefrontier',
|
|
224
|
+
'sponsored-transaction',
|
|
225
|
+
...(mutationKey ?? []),
|
|
226
|
+
],
|
|
227
|
+
mutationFn: async (args) => {
|
|
228
|
+
const wallet = getConnectedWallet(dAppKit);
|
|
229
|
+
const signerAccount = args.account ?? currentAccount?.address;
|
|
230
|
+
if (!signerAccount) {
|
|
231
|
+
throw new WalletNoAccountSelectedError();
|
|
232
|
+
}
|
|
233
|
+
const signSponsoredTransaction = getSponsoredSigner(wallet);
|
|
234
|
+
const payload = buildSponsoredPayload(args);
|
|
235
|
+
log.info('Sponsored Transaction Payload:', payload);
|
|
236
|
+
return signWithRetries(signSponsoredTransaction, payload);
|
|
237
|
+
},
|
|
238
|
+
...mutationOptions,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for display names of on-chain type ids (generic modules, airlocks,
|
|
3
|
+
* airlock items), looked up in Datahub. Each id is fetched once and kept for
|
|
4
|
+
* the session; type names do not change.
|
|
5
|
+
*
|
|
6
|
+
* @category Hooks - Datahub
|
|
7
|
+
* @param typeIds - Type ids as stored on chain (decimal strings)
|
|
8
|
+
* @returns Type id → name, for the ids that have loaded
|
|
9
|
+
*/
|
|
10
|
+
export declare function useTypeNames(typeIds: string[]): Record<string, string>;
|
|
11
|
+
//# sourceMappingURL=useTypeNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTypeNames.d.ts","sourceRoot":"","sources":["../../hooks/useTypeNames.ts"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBtE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useQueries } from '@tanstack/react-query';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { getDatahubGameInfo, resolveTenantFromSearch, typeNamesFrom, } from '../utils/datahub.js';
|
|
4
|
+
/**
|
|
5
|
+
* Hook for display names of on-chain type ids (generic modules, airlocks,
|
|
6
|
+
* airlock items), looked up in Datahub. Each id is fetched once and kept for
|
|
7
|
+
* the session; type names do not change.
|
|
8
|
+
*
|
|
9
|
+
* @category Hooks - Datahub
|
|
10
|
+
* @param typeIds - Type ids as stored on chain (decimal strings)
|
|
11
|
+
* @returns Type id → name, for the ids that have loaded
|
|
12
|
+
*/
|
|
13
|
+
export function useTypeNames(typeIds) {
|
|
14
|
+
const unique = useMemo(() => [...new Set(typeIds)], [typeIds]);
|
|
15
|
+
const tenant = resolveTenantFromSearch(window.location.search);
|
|
16
|
+
const results = useQueries({
|
|
17
|
+
queries: unique.map((typeId) => ({
|
|
18
|
+
queryKey: ['datahubType', tenant, typeId],
|
|
19
|
+
queryFn: () => getDatahubGameInfo(Number(typeId)),
|
|
20
|
+
staleTime: Number.POSITIVE_INFINITY,
|
|
21
|
+
})),
|
|
22
|
+
});
|
|
23
|
+
return useMemo(() => typeNamesFrom(unique, results.map((result) => result.data)), [results, unique]);
|
|
24
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { dAppKit } from './config/dapp-kit.js';
|
|
2
|
+
export * from './graphql/index.js';
|
|
3
|
+
export type { UseSponsoredTransactionArgs, UseSponsoredTransactionError, UseSponsoredTransactionMutationOptions, } from './hooks/index.js';
|
|
4
|
+
export { useCharacterDirectory, useCharacterSearch, useConnection, useEntityRole, useNotification, useSmartObject, useSponsoredTransaction, useTypeNames, WalletNoAccountSelectedError, WalletNotConnectedError, WalletSponsoredTransactionNotSupportedError, } from './hooks/index.js';
|
|
5
|
+
export { EveFrontierProvider, NotificationContext, NotificationProvider, SmartObjectContext, SmartObjectProvider, VaultContext, VaultProvider, } from './providers/index.js';
|
|
6
|
+
export * from './types/index.js';
|
|
7
|
+
export * from './utils/index.js';
|
|
8
|
+
export { getObjectRegistryType, getPollingInterval, getSuiGraphqlEndpoint, getWorldPackageId, getWorldTier, getWorldType, POLLING_INTERVAL, STORAGE_KEYS, } from './utils/constants.js';
|
|
9
|
+
export type { EveFrontierSponsoredTransactionFeature, SponsoredTransactionArgs, SponsoredTransactionInput, SponsoredTransactionMethod, SponsoredTransactionOutput, } from './wallet/index.js';
|
|
10
|
+
export { getSponsoredTransactionFeature, walletSupportsSponsoredTransaction, } from './wallet/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAI3C,cAAc,WAAW,CAAA;AACzB,YAAY,EACV,2BAA2B,EAC3B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,SAAS,CAAA;AAGhB,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,YAAY,EACZ,4BAA4B,EAC5B,uBAAuB,EACvB,2CAA2C,GAC5C,MAAM,SAAS,CAAA;AAChB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAA;AAIpB,cAAc,SAAS,CAAA;AAIvB,cAAc,SAAS,CAAA;AAKvB,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,YAAY,GACb,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,sCAAsC,EACtC,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,UAAU,CAAA;AAIjB,OAAO,EACL,8BAA8B,EAC9B,kCAAkC,GACnC,MAAM,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Main provider
|
|
2
|
+
// =========================================
|
|
3
|
+
// Config
|
|
4
|
+
// =========================================
|
|
5
|
+
export { dAppKit } from './config/dapp-kit.js';
|
|
6
|
+
// =========================================
|
|
7
|
+
// GraphQL - Query execution & helper functions
|
|
8
|
+
// =========================================
|
|
9
|
+
export * from './graphql/index.js';
|
|
10
|
+
// Hooks
|
|
11
|
+
// Hook error types and sponsored transaction types
|
|
12
|
+
export { useCharacterDirectory, useCharacterSearch, useConnection, useEntityRole, useNotification, useSmartObject, useSponsoredTransaction, useTypeNames, WalletNoAccountSelectedError, WalletNotConnectedError, WalletSponsoredTransactionNotSupportedError, } from './hooks/index.js';
|
|
13
|
+
export { EveFrontierProvider, NotificationContext, NotificationProvider, SmartObjectContext, SmartObjectProvider, VaultContext, VaultProvider, } from './providers/index.js';
|
|
14
|
+
// =========================================
|
|
15
|
+
// Types (re-exported from ./types)
|
|
16
|
+
// =========================================
|
|
17
|
+
export * from './types/index.js';
|
|
18
|
+
// =========================================
|
|
19
|
+
// Utils (re-exported from ./utils)
|
|
20
|
+
// =========================================
|
|
21
|
+
export * from './utils/index.js';
|
|
22
|
+
// =========================================
|
|
23
|
+
// Constants & Configuration
|
|
24
|
+
// =========================================
|
|
25
|
+
export { getObjectRegistryType, getPollingInterval, getSuiGraphqlEndpoint, getWorldPackageId, getWorldTier, getWorldType, POLLING_INTERVAL, STORAGE_KEYS, } from './utils/constants.js';
|
|
26
|
+
// =========================================
|
|
27
|
+
// Wallet Standard Extensions
|
|
28
|
+
// =========================================
|
|
29
|
+
export { getSponsoredTransactionFeature, walletSupportsSponsoredTransaction, } from './wallet/index.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { UpdateTransport } from '../utils/constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* EveFrontierProvider wraps the application with all necessary providers
|
|
6
|
+
* for the EVE Frontier dApp kit.
|
|
7
|
+
*
|
|
8
|
+
* Provider hierarchy:
|
|
9
|
+
* 1. QueryClientProvider - React Query for async state management
|
|
10
|
+
* 2. DAppKitProvider - Sui blockchain client
|
|
11
|
+
* 3. VaultProvider - Eve-specific wallet configuration (from @evefrontier/dapp-kit)
|
|
12
|
+
* 4. SmartObjectProvider - Smart object data via GraphQL
|
|
13
|
+
* 5. NotificationProvider - User notifications
|
|
14
|
+
* @category Providers
|
|
15
|
+
*/
|
|
16
|
+
declare const EveFrontierProvider: ({ children, queryClient, updateTransport, }: {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
queryClient: QueryClient;
|
|
19
|
+
/** How the selected entity is kept up to date; see SmartObjectProvider */
|
|
20
|
+
updateTransport?: UpdateTransport;
|
|
21
|
+
}) => import("react").JSX.Element;
|
|
22
|
+
export default EveFrontierProvider;
|
|
23
|
+
//# sourceMappingURL=EveFrontierProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EveFrontierProvider.d.ts","sourceRoot":"","sources":["../../providers/EveFrontierProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAMzD;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,mBAAmB,gDAItB;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,WAAW,EAAE,WAAW,CAAA;IACxB,0EAA0E;IAC1E,eAAe,CAAC,EAAE,eAAe,CAAA;CAClC,gCAcA,CAAA;eAEc,mBAAmB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DAppKitProvider } from '@mysten/dapp-kit-react';
|
|
3
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
+
import { dAppKit } from '../config/dapp-kit.js';
|
|
5
|
+
import NotificationProvider from './NotificationProvider.js';
|
|
6
|
+
import SmartObjectProvider from './SmartObjectProvider.js';
|
|
7
|
+
import VaultProvider from './VaultProvider.js';
|
|
8
|
+
/**
|
|
9
|
+
* EveFrontierProvider wraps the application with all necessary providers
|
|
10
|
+
* for the EVE Frontier dApp kit.
|
|
11
|
+
*
|
|
12
|
+
* Provider hierarchy:
|
|
13
|
+
* 1. QueryClientProvider - React Query for async state management
|
|
14
|
+
* 2. DAppKitProvider - Sui blockchain client
|
|
15
|
+
* 3. VaultProvider - Eve-specific wallet configuration (from @evefrontier/dapp-kit)
|
|
16
|
+
* 4. SmartObjectProvider - Smart object data via GraphQL
|
|
17
|
+
* 5. NotificationProvider - User notifications
|
|
18
|
+
* @category Providers
|
|
19
|
+
*/
|
|
20
|
+
const EveFrontierProvider = ({ children, queryClient, updateTransport, }) => {
|
|
21
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(DAppKitProvider, { dAppKit: dAppKit, children: _jsx(VaultProvider, { children: _jsx(SmartObjectProvider, { ...(updateTransport !== undefined ? { updateTransport } : {}), children: _jsx(NotificationProvider, { children: children }) }) }) }) }));
|
|
22
|
+
};
|
|
23
|
+
export default EveFrontierProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type NotificationContextType } from '../types/index.js';
|
|
3
|
+
/** @category Providers */
|
|
4
|
+
export declare const NotificationContext: import("react").Context<NotificationContextType>;
|
|
5
|
+
/**
|
|
6
|
+
* NotificationProvider manages notifications for transactions and messages.
|
|
7
|
+
*
|
|
8
|
+
* @category Providers
|
|
9
|
+
*/
|
|
10
|
+
declare const NotificationProvider: ({ children }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}) => import("react").JSX.Element;
|
|
13
|
+
export default NotificationProvider;
|
|
14
|
+
//# sourceMappingURL=NotificationProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationProvider.d.ts","sourceRoot":"","sources":["../../providers/NotificationProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,EACL,KAAK,uBAAuB,EAG7B,MAAM,UAAU,CAAA;AAEjB,0BAA0B;AAC1B,eAAO,MAAM,mBAAmB,kDAW9B,CAAA;AAUF;;;;GAIG;AACH,QAAA,MAAM,oBAAoB,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,gCA+DlE,CAAA;eAEc,oBAAoB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useState } from 'react';
|
|
3
|
+
import { Severity, } from '../types/index.js';
|
|
4
|
+
/** @category Providers */
|
|
5
|
+
export const NotificationContext = createContext({
|
|
6
|
+
notify: () => { },
|
|
7
|
+
notification: {
|
|
8
|
+
message: '',
|
|
9
|
+
txHash: '',
|
|
10
|
+
onSuccess: () => { },
|
|
11
|
+
severity: Severity.Success,
|
|
12
|
+
handleClose: () => { },
|
|
13
|
+
isOpen: false,
|
|
14
|
+
},
|
|
15
|
+
handleClose: () => { },
|
|
16
|
+
});
|
|
17
|
+
/** Message shown when notify() is called without one. */
|
|
18
|
+
const DEFAULT_MESSAGES = {
|
|
19
|
+
[Severity.Success]: 'Operation completed successfully.',
|
|
20
|
+
[Severity.Error]: 'An error occurred.',
|
|
21
|
+
[Severity.Warning]: 'Warning.',
|
|
22
|
+
[Severity.Info]: 'Processing...',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* NotificationProvider manages notifications for transactions and messages.
|
|
26
|
+
*
|
|
27
|
+
* @category Providers
|
|
28
|
+
*/
|
|
29
|
+
const NotificationProvider = ({ children }) => {
|
|
30
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
31
|
+
const [message, setMessage] = useState('');
|
|
32
|
+
const [severity, setSeverity] = useState(Severity.Info);
|
|
33
|
+
const [txHash, setTxHash] = useState('');
|
|
34
|
+
const [onSuccess, setOnSuccess] = useState(() => () => { });
|
|
35
|
+
const handleClose = useCallback(() => {
|
|
36
|
+
setIsOpen(false);
|
|
37
|
+
if (severity === Severity.Success) {
|
|
38
|
+
onSuccess();
|
|
39
|
+
}
|
|
40
|
+
setOnSuccess(() => () => { });
|
|
41
|
+
}, [onSuccess, severity]);
|
|
42
|
+
const notify = useCallback(({ type, message, txHash, onSuccess, }) => {
|
|
43
|
+
setSeverity(type);
|
|
44
|
+
setIsOpen(true);
|
|
45
|
+
setOnSuccess(() => onSuccess ?? (() => { }));
|
|
46
|
+
// If success with txHash, show success message with transaction hash
|
|
47
|
+
if (type === Severity.Success && txHash) {
|
|
48
|
+
setMessage(`Transaction was successful. ${message ?? ''} Transaction hash: ${txHash}`);
|
|
49
|
+
setTxHash(txHash);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Otherwise, show the passed message or a default based on severity
|
|
53
|
+
setMessage(message || (DEFAULT_MESSAGES[type] ?? 'Processing...'));
|
|
54
|
+
setTxHash(txHash ?? '');
|
|
55
|
+
}, []);
|
|
56
|
+
const notification = {
|
|
57
|
+
message,
|
|
58
|
+
txHash,
|
|
59
|
+
onSuccess,
|
|
60
|
+
severity,
|
|
61
|
+
handleClose,
|
|
62
|
+
isOpen,
|
|
63
|
+
};
|
|
64
|
+
return (_jsx(NotificationContext.Provider, { value: { notify, handleClose, notification }, children: children }));
|
|
65
|
+
};
|
|
66
|
+
export default NotificationProvider;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { SmartObjectContextType } from '../types/index.js';
|
|
3
|
+
import { type UpdateTransport } from '../utils/constants.js';
|
|
4
|
+
export type { FetchObjectDataInput } from '../utils/smartObject.js';
|
|
5
|
+
/** @category Providers */
|
|
6
|
+
export declare const SmartObjectContext: import("react").Context<SmartObjectContextType>;
|
|
7
|
+
/**
|
|
8
|
+
* SmartObjectProvider component provides context for the selected world entity.
|
|
9
|
+
* It uses GraphQL queries to fetch the entity on the Sui blockchain and keeps
|
|
10
|
+
* it up to date by `updateTransport`:
|
|
11
|
+
* - `subscription` (the default): refetches when the GraphQL subscription
|
|
12
|
+
* delivers one of the entity's inventory or power events, with slow polling
|
|
13
|
+
* as a backstop; if the subscription fails, it polls as with `polling`.
|
|
14
|
+
* - `polling`: polls every POLLING_INTERVAL.
|
|
15
|
+
*
|
|
16
|
+
* The entity loads whether or not a wallet is connected; reads are public.
|
|
17
|
+
*
|
|
18
|
+
* The provider fetches both the entity and its owner (entityOwner):
|
|
19
|
+
* 1. Fetches the entity with its components and action maps
|
|
20
|
+
* 2. Reads the holder of the entity's AccessCap
|
|
21
|
+
* 3. When the cap is parked on a Character, fetches that Character entity
|
|
22
|
+
*
|
|
23
|
+
* @category Providers
|
|
24
|
+
*/
|
|
25
|
+
declare const SmartObjectProvider: ({ children, updateTransport, }: {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
/** How the entity is kept up to date; `subscription` by default */
|
|
28
|
+
updateTransport?: UpdateTransport;
|
|
29
|
+
}) => import("react").JSX.Element;
|
|
30
|
+
export default SmartObjectProvider;
|
|
31
|
+
//# sourceMappingURL=SmartObjectProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SmartObjectProvider.d.ts","sourceRoot":"","sources":["../../providers/SmartObjectProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAA;AAM3B,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAEhE,0BAA0B;AAC1B,eAAO,MAAM,kBAAkB,iDAQ7B,CAAA;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,mBAAmB,mCAGtB;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,mEAAmE;IACnE,eAAe,CAAC,EAAE,eAAe,CAAA;CAClC,gCA4DA,CAAA;eAEc,mBAAmB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback } from 'react';
|
|
3
|
+
import { backstopInterval, DEFAULT_TENANT, DEFAULT_UPDATE_TRANSPORT, } from '../utils/constants.js';
|
|
4
|
+
import { useEntityData } from './smartObject/useEntityData.js';
|
|
5
|
+
import { useEntitySubscription } from './smartObject/useEntitySubscription.js';
|
|
6
|
+
import { useObjectSelection } from './smartObject/useObjectSelection.js';
|
|
7
|
+
import { usePollingBackstop } from './smartObject/usePollingBackstop.js';
|
|
8
|
+
/** @category Providers */
|
|
9
|
+
export const SmartObjectContext = createContext({
|
|
10
|
+
tenant: DEFAULT_TENANT,
|
|
11
|
+
entity: null,
|
|
12
|
+
entityOwner: null,
|
|
13
|
+
assemblyOwner: null,
|
|
14
|
+
loading: true,
|
|
15
|
+
error: null,
|
|
16
|
+
refetch: async () => { },
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* SmartObjectProvider component provides context for the selected world entity.
|
|
20
|
+
* It uses GraphQL queries to fetch the entity on the Sui blockchain and keeps
|
|
21
|
+
* it up to date by `updateTransport`:
|
|
22
|
+
* - `subscription` (the default): refetches when the GraphQL subscription
|
|
23
|
+
* delivers one of the entity's inventory or power events, with slow polling
|
|
24
|
+
* as a backstop; if the subscription fails, it polls as with `polling`.
|
|
25
|
+
* - `polling`: polls every POLLING_INTERVAL.
|
|
26
|
+
*
|
|
27
|
+
* The entity loads whether or not a wallet is connected; reads are public.
|
|
28
|
+
*
|
|
29
|
+
* The provider fetches both the entity and its owner (entityOwner):
|
|
30
|
+
* 1. Fetches the entity with its components and action maps
|
|
31
|
+
* 2. Reads the holder of the entity's AccessCap
|
|
32
|
+
* 3. When the cap is parked on a Character, fetches that Character entity
|
|
33
|
+
*
|
|
34
|
+
* @category Providers
|
|
35
|
+
*/
|
|
36
|
+
const SmartObjectProvider = ({ children, updateTransport = DEFAULT_UPDATE_TRANSPORT, }) => {
|
|
37
|
+
const { selection, input } = useObjectSelection();
|
|
38
|
+
const { entity, entityOwner, loading, setLoading, error, fetchObjectData, resetTracking, } = useEntityData();
|
|
39
|
+
// After an event: skip only the version check (the event means it changed)
|
|
40
|
+
// and otherwise refetch as a poll does, so a running fetch is not cut short,
|
|
41
|
+
// a lagging indexer does not clear the entity, and loading is not shown
|
|
42
|
+
const refetchOnEvent = useCallback(async () => {
|
|
43
|
+
if (input)
|
|
44
|
+
await fetchObjectData(input, false, { skipVersionCheck: true });
|
|
45
|
+
}, [input, fetchObjectData]);
|
|
46
|
+
const subscriptionStatus = useEntitySubscription({
|
|
47
|
+
transport: updateTransport,
|
|
48
|
+
entityId: entity?.id ?? null,
|
|
49
|
+
tenant: selection?.tenant,
|
|
50
|
+
refetch: refetchOnEvent,
|
|
51
|
+
});
|
|
52
|
+
usePollingBackstop({
|
|
53
|
+
input,
|
|
54
|
+
fetchObjectData,
|
|
55
|
+
setLoading,
|
|
56
|
+
resetTracking,
|
|
57
|
+
intervalMs: backstopInterval(updateTransport, subscriptionStatus),
|
|
58
|
+
});
|
|
59
|
+
// Refetch with retries after a mutation (e.g. metadata save)
|
|
60
|
+
// so the indexer can catch up.
|
|
61
|
+
const refetch = useCallback(async () => {
|
|
62
|
+
if (!input)
|
|
63
|
+
return;
|
|
64
|
+
await fetchObjectData(input, true);
|
|
65
|
+
await new Promise((resolve) => {
|
|
66
|
+
setTimeout(resolve, 1500);
|
|
67
|
+
});
|
|
68
|
+
await fetchObjectData(input, true);
|
|
69
|
+
}, [input, fetchObjectData]);
|
|
70
|
+
return (_jsx(SmartObjectContext.Provider, { value: {
|
|
71
|
+
tenant: selection?.tenant ?? '',
|
|
72
|
+
entity,
|
|
73
|
+
entityOwner,
|
|
74
|
+
assemblyOwner: null,
|
|
75
|
+
loading,
|
|
76
|
+
error,
|
|
77
|
+
refetch,
|
|
78
|
+
}, children: children }));
|
|
79
|
+
};
|
|
80
|
+
export default SmartObjectProvider;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { type VaultContextType } from '../types/index.js';
|
|
3
|
+
/** @category Providers */
|
|
4
|
+
export declare const VaultContext: import("react").Context<VaultContextType>;
|
|
5
|
+
/** @category Providers */
|
|
6
|
+
declare const VaultProvider: ({ children }: {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}) => import("react").JSX.Element;
|
|
9
|
+
export default VaultProvider;
|
|
10
|
+
//# sourceMappingURL=VaultProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VaultProvider.d.ts","sourceRoot":"","sources":["../../providers/VaultProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAKlE,0BAA0B;AAC1B,eAAO,MAAM,YAAY,2CAOvB,CAAA;AAUF,0BAA0B;AAC1B,QAAA,MAAM,aAAa,iBAAkB;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,gCA2E3D,CAAA;eAEc,aAAa"}
|