@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
|
@@ -1,442 +0,0 @@
|
|
|
1
|
-
import { getWallets } from "@mysten/wallet-standard";
|
|
2
|
-
import {
|
|
3
|
-
useCurrentAccount,
|
|
4
|
-
useWallets,
|
|
5
|
-
useDAppKit,
|
|
6
|
-
} from "@mysten/dapp-kit-react";
|
|
7
|
-
import {
|
|
8
|
-
useMutation,
|
|
9
|
-
UseMutationResult,
|
|
10
|
-
type UseMutationOptions,
|
|
11
|
-
} from "@tanstack/react-query";
|
|
12
|
-
import {
|
|
13
|
-
getAssemblyTypeApiString,
|
|
14
|
-
supportsSponsoredTransaction,
|
|
15
|
-
getSponsoredTransactionMethod,
|
|
16
|
-
type SponsoredTransactionInput,
|
|
17
|
-
type SponsoredTransactionOutput,
|
|
18
|
-
SponsoredTransactionArgs,
|
|
19
|
-
} from "../wallet";
|
|
20
|
-
import { Assemblies, QueryParams, SponsoredTransactionActions } from "../types";
|
|
21
|
-
import { createLogger, TenantId } from "../utils";
|
|
22
|
-
|
|
23
|
-
const log = createLogger();
|
|
24
|
-
|
|
25
|
-
/** Wallet-like shape from dApp Kit (UiWallet or connection store). */
|
|
26
|
-
type ResolvableWallet = {
|
|
27
|
-
features: unknown;
|
|
28
|
-
name?: string;
|
|
29
|
-
version?: string;
|
|
30
|
-
[key: string]: unknown;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// ============================================================================
|
|
34
|
-
// Error Types
|
|
35
|
-
// ============================================================================
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Error thrown when the connected wallet doesn't support EVE Frontier sponsored transactions.
|
|
39
|
-
*
|
|
40
|
-
* This occurs when the wallet doesn't implement the `evefrontier:sponsoredTransaction` feature.
|
|
41
|
-
* Currently, only EVE Vault wallet supports this feature.
|
|
42
|
-
*
|
|
43
|
-
* @category Errors
|
|
44
|
-
*/
|
|
45
|
-
export class WalletSponsoredTransactionNotSupportedError extends Error {
|
|
46
|
-
constructor(walletName?: string) {
|
|
47
|
-
super(
|
|
48
|
-
walletName
|
|
49
|
-
? `Wallet "${walletName}" does not support sponsored transactions`
|
|
50
|
-
: "Connected wallet does not support sponsored transactions",
|
|
51
|
-
);
|
|
52
|
-
this.name = "WalletSponsoredTransactionNotSupportedError";
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Error thrown when attempting a sponsored transaction without a connected wallet.
|
|
58
|
-
*
|
|
59
|
-
* @category Errors
|
|
60
|
-
*/
|
|
61
|
-
export class WalletNotConnectedError extends Error {
|
|
62
|
-
constructor() {
|
|
63
|
-
super("No wallet connected");
|
|
64
|
-
this.name = "WalletNotConnectedError";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Error thrown when no account is selected in the connected wallet.
|
|
70
|
-
*
|
|
71
|
-
* @category Errors
|
|
72
|
-
*/
|
|
73
|
-
export class WalletNoAccountSelectedError extends Error {
|
|
74
|
-
constructor() {
|
|
75
|
-
super("No account selected in wallet");
|
|
76
|
-
this.name = "WalletNoAccountSelectedError";
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Error thrown when assembly ID cannot be resolved or is invalid.
|
|
82
|
-
* Assembly ID must come from the assembly object (item_id) or the URL query param (itemId), and must be a valid non-negative integer.
|
|
83
|
-
*
|
|
84
|
-
* @category Errors
|
|
85
|
-
*/
|
|
86
|
-
export class AssemblyIdRequiredError extends Error {
|
|
87
|
-
constructor(reason?: string) {
|
|
88
|
-
super(
|
|
89
|
-
reason ??
|
|
90
|
-
"Assembly ID is required: pass an assembly object with item_id or set the itemId query param to a valid non-negative integer",
|
|
91
|
-
);
|
|
92
|
-
this.name = "AssemblyIdRequiredError";
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ============================================================================
|
|
97
|
-
// Assembly ID resolution
|
|
98
|
-
// ============================================================================
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Resolves assembly ID to a non-negative integer from the assembly object or query param.
|
|
102
|
-
* Fails fast with {@link AssemblyIdRequiredError} if neither source provides a valid id.
|
|
103
|
-
*/
|
|
104
|
-
function resolveAssemblyId(
|
|
105
|
-
assemblyItemId: number | undefined,
|
|
106
|
-
queryItemId: string | null,
|
|
107
|
-
): number {
|
|
108
|
-
const fromAssembly =
|
|
109
|
-
typeof assemblyItemId === "number" &&
|
|
110
|
-
Number.isInteger(assemblyItemId) &&
|
|
111
|
-
assemblyItemId >= 0
|
|
112
|
-
? assemblyItemId
|
|
113
|
-
: undefined;
|
|
114
|
-
|
|
115
|
-
if (fromAssembly !== undefined) {
|
|
116
|
-
return fromAssembly;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (queryItemId != null && queryItemId.trim() !== "") {
|
|
120
|
-
const parsed = parseInt(queryItemId.trim(), 10);
|
|
121
|
-
if (Number.isNaN(parsed) || parsed < 0) {
|
|
122
|
-
throw new AssemblyIdRequiredError(
|
|
123
|
-
`Query param itemId must be a non-negative integer; got "${queryItemId}"`,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return parsed;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
throw new AssemblyIdRequiredError();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// ============================================================================
|
|
133
|
-
// Retry helpers (502 Bad Gateway)
|
|
134
|
-
// ============================================================================
|
|
135
|
-
|
|
136
|
-
const DEFAULT_MAX_RETRIES = 2;
|
|
137
|
-
const DEFAULT_RETRY_DELAY_MS = 1500;
|
|
138
|
-
|
|
139
|
-
function delay(ms: number): Promise<void> {
|
|
140
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Returns true if the error indicates a 502 (or similar transient server error)
|
|
145
|
-
* where retrying the same payload is safe.
|
|
146
|
-
*/
|
|
147
|
-
function isRetryableSponsorError(error: unknown): boolean {
|
|
148
|
-
if (error instanceof Error) {
|
|
149
|
-
const msg = error.message.toLowerCase();
|
|
150
|
-
if (msg.includes("502") || msg.includes("bad gateway")) return true;
|
|
151
|
-
}
|
|
152
|
-
const withResponse = error as { response?: { status?: number } };
|
|
153
|
-
if (withResponse?.response?.status === 502) return true;
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// ============================================================================
|
|
158
|
-
// Hook Types
|
|
159
|
-
// ============================================================================
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Error union type for {@link useSponsoredTransaction} mutation failures.
|
|
163
|
-
*
|
|
164
|
-
* @category Hooks - Sponsored Transaction
|
|
165
|
-
*/
|
|
166
|
-
export type UseSponsoredTransactionError =
|
|
167
|
-
| WalletSponsoredTransactionNotSupportedError
|
|
168
|
-
| WalletNotConnectedError
|
|
169
|
-
| WalletNoAccountSelectedError
|
|
170
|
-
| AssemblyIdRequiredError
|
|
171
|
-
| Error;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Arguments passed to {@link useSponsoredTransaction} mutate/mutateAsync.
|
|
175
|
-
* With assembly object (id and type derived).
|
|
176
|
-
*
|
|
177
|
-
* @category Hooks - Sponsored Transaction
|
|
178
|
-
*/
|
|
179
|
-
export type UseSponsoredTransactionArgs = SponsoredTransactionArgs;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* React Query mutation options for {@link useSponsoredTransaction}.
|
|
183
|
-
*
|
|
184
|
-
* @category Hooks - Sponsored Transaction
|
|
185
|
-
*/
|
|
186
|
-
export type UseSponsoredTransactionMutationOptions = Omit<
|
|
187
|
-
UseMutationOptions<
|
|
188
|
-
SponsoredTransactionOutput,
|
|
189
|
-
UseSponsoredTransactionError,
|
|
190
|
-
UseSponsoredTransactionArgs
|
|
191
|
-
>,
|
|
192
|
-
"mutationFn"
|
|
193
|
-
>;
|
|
194
|
-
|
|
195
|
-
// ============================================================================
|
|
196
|
-
// Hook Implementation
|
|
197
|
-
// ============================================================================
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Hook for executing gas-sponsored transactions via EVE Frontier.
|
|
201
|
-
*
|
|
202
|
-
* This mutation hook enables dApps to send transactions where gas fees are paid
|
|
203
|
-
* by the EVE Frontier backend service, eliminating the need for users to have SUI
|
|
204
|
-
* tokens for gas. The wallet must support the `evefrontier:sponsoredTransaction` feature
|
|
205
|
-
* (currently only EVE Vault).
|
|
206
|
-
*
|
|
207
|
-
* Transient server errors (e.g. 502 Bad Gateway) are retried automatically with the same
|
|
208
|
-
* payload a limited number of times with a delay between attempts.
|
|
209
|
-
*
|
|
210
|
-
* The hook automatically uses the currently connected wallet and account (unless overridden)
|
|
211
|
-
* and handles wallet feature detection and validation.
|
|
212
|
-
*
|
|
213
|
-
* **Input** (passed to `mutate` / `mutateAsync`):
|
|
214
|
-
* - `txAction` (required) – The sponsored action to run (e.g. BRING_ONLINE, BRING_OFFLINE).
|
|
215
|
-
* - `chain` (required) – Sui chain id, e.g. `"sui:testnet"` or `"sui:mainnet"`.
|
|
216
|
-
* - `assembly` (required) – Full assembly object (`AssemblyType<Assemblies>`). Must include `type` and `item_id` (number). If `item_id` is missing or invalid, the hook falls back to the URL query param `itemId` (parsed as a non-negative integer). Fails with {@link AssemblyIdRequiredError} if neither source provides a valid id.
|
|
217
|
-
* - `tenant` (optional) – Tenant ID. When omitted, the hook resolves it from the URL query param (e.g. `tenant`) with fallback to `TenantId.UTOPIA`. Pass explicitly to override.
|
|
218
|
-
* - `account` (optional) – Signer address. If omitted, the currently connected wallet account is used.
|
|
219
|
-
*
|
|
220
|
-
* **Output** (on success, in `data` or resolved from `mutateAsync`):
|
|
221
|
-
* - `digest` (required) – Transaction digest.
|
|
222
|
-
* - `effects` (optional) – Transaction effects, BCS encoded.
|
|
223
|
-
* - `rawEffects` (optional) – Raw effects bytes.
|
|
224
|
-
*
|
|
225
|
-
* @category Hooks - Sponsored Transaction
|
|
226
|
-
* @param options - React Query mutation options (optional)
|
|
227
|
-
* @returns React Query mutation result with:
|
|
228
|
-
* - `mutate(args, options?)` - Trigger transaction (fire-and-forget)
|
|
229
|
-
* - `mutateAsync(args)` - Trigger transaction (returns Promise<SponsoredTransactionOutput>)
|
|
230
|
-
* - `isPending` - True while the transaction is in progress
|
|
231
|
-
* - `isError` - True if the last mutation failed
|
|
232
|
-
* - `error` - Error from the last failed mutation
|
|
233
|
-
* - `data` - Last successful result (`SponsoredTransactionOutput`)
|
|
234
|
-
*
|
|
235
|
-
* @throws {WalletNotConnectedError} If no wallet is connected
|
|
236
|
-
* @throws {WalletNoAccountSelectedError} If no account is selected
|
|
237
|
-
* @throws {WalletSponsoredTransactionNotSupportedError} If wallet doesn't support sponsored transactions
|
|
238
|
-
* @throws {AssemblyIdRequiredError} If assembly ID is missing or invalid (neither assembly.item_id nor itemId query param is a valid non-negative integer)
|
|
239
|
-
*
|
|
240
|
-
* @example Basic bring online transaction
|
|
241
|
-
* ```tsx
|
|
242
|
-
* import { useSponsoredTransaction, SponsoredTransactionActions, useSmartObject } from "@evefrontier/dapp-kit";
|
|
243
|
-
*
|
|
244
|
-
* const BringOnlineButton = () => {
|
|
245
|
-
* const { assembly } = useSmartObject();
|
|
246
|
-
* const { mutateAsync: sendTx, isPending } = useSponsoredTransaction();
|
|
247
|
-
*
|
|
248
|
-
* const handleBringOnline = async () => {
|
|
249
|
-
* if (!assembly) return;
|
|
250
|
-
* try {
|
|
251
|
-
* const result = await sendTx({
|
|
252
|
-
* txAction: SponsoredTransactionActions.BRING_ONLINE,
|
|
253
|
-
* assembly,
|
|
254
|
-
* chain: "sui:testnet",
|
|
255
|
-
* });
|
|
256
|
-
* console.log("Transaction digest:", result.digest);
|
|
257
|
-
* } catch (error) {
|
|
258
|
-
* console.error("Transaction failed:", error);
|
|
259
|
-
* }
|
|
260
|
-
* };
|
|
261
|
-
*
|
|
262
|
-
* return (
|
|
263
|
-
* <button onClick={handleBringOnline} disabled={isPending || !assembly}>
|
|
264
|
-
* {isPending ? "Processing..." : "Bring Online"}
|
|
265
|
-
* </button>
|
|
266
|
-
* );
|
|
267
|
-
* };
|
|
268
|
-
* ```
|
|
269
|
-
*
|
|
270
|
-
* @example With callbacks
|
|
271
|
-
* ```tsx
|
|
272
|
-
* const { assembly } = useSmartObject();
|
|
273
|
-
* const { mutate: sendTx } = useSponsoredTransaction();
|
|
274
|
-
*
|
|
275
|
-
* sendTx(
|
|
276
|
-
* {
|
|
277
|
-
* txAction: SponsoredTransactionActions.BRING_ONLINE,
|
|
278
|
-
* assembly,
|
|
279
|
-
* chain: "sui:testnet",
|
|
280
|
-
* },
|
|
281
|
-
* {
|
|
282
|
-
* onSuccess: (result) => {
|
|
283
|
-
* notify({ type: Severity.Success, txHash: result.digest });
|
|
284
|
-
* },
|
|
285
|
-
* onError: (error) => {
|
|
286
|
-
* notify({ type: Severity.Error, message: error.message });
|
|
287
|
-
* },
|
|
288
|
-
* }
|
|
289
|
-
* );
|
|
290
|
-
* ```
|
|
291
|
-
*
|
|
292
|
-
* @example With assembly and optional account
|
|
293
|
-
* ```tsx
|
|
294
|
-
* const result = await sendTx({
|
|
295
|
-
* txAction: SponsoredTransactionActions.BRING_ONLINE,
|
|
296
|
-
* assembly, // full AssemblyType from useSmartObject() or similar
|
|
297
|
-
* chain: "sui:testnet",
|
|
298
|
-
* account: "0x...", // optional; defaults to connected wallet account
|
|
299
|
-
* });
|
|
300
|
-
* ```
|
|
301
|
-
*
|
|
302
|
-
* @see {@link SponsoredTransactionActions} for available transaction actions
|
|
303
|
-
* @see {@link SponsoredTransactionInput} for full input type
|
|
304
|
-
* @see {@link SponsoredTransactionOutput} for full output type
|
|
305
|
-
*/
|
|
306
|
-
export function useSponsoredTransaction({
|
|
307
|
-
mutationKey,
|
|
308
|
-
...mutationOptions
|
|
309
|
-
}: UseSponsoredTransactionMutationOptions = {}): UseMutationResult<
|
|
310
|
-
SponsoredTransactionOutput,
|
|
311
|
-
UseSponsoredTransactionError,
|
|
312
|
-
UseSponsoredTransactionArgs
|
|
313
|
-
> {
|
|
314
|
-
const dAppKit = useDAppKit();
|
|
315
|
-
const wallets = useWallets();
|
|
316
|
-
const currentAccount = useCurrentAccount();
|
|
317
|
-
|
|
318
|
-
const queryParams = new URLSearchParams(window.location.search);
|
|
319
|
-
const queryItemId = queryParams.get(QueryParams.ITEM_ID);
|
|
320
|
-
const queryTenant = queryParams.get(QueryParams.TENANT);
|
|
321
|
-
|
|
322
|
-
return useMutation({
|
|
323
|
-
mutationKey: [
|
|
324
|
-
"evefrontier",
|
|
325
|
-
"sponsored-transaction",
|
|
326
|
-
...(mutationKey ?? []),
|
|
327
|
-
],
|
|
328
|
-
mutationFn: async (args): Promise<SponsoredTransactionOutput> => {
|
|
329
|
-
// Resolve wallet at call time
|
|
330
|
-
const connection =
|
|
331
|
-
typeof dAppKit.stores?.$connection?.get === "function"
|
|
332
|
-
? (dAppKit.stores.$connection.get() as { wallet?: ResolvableWallet })
|
|
333
|
-
: null;
|
|
334
|
-
const walletFromStore = connection?.wallet;
|
|
335
|
-
const wallet = walletFromStore ?? null;
|
|
336
|
-
|
|
337
|
-
if (!wallet) {
|
|
338
|
-
throw new WalletNotConnectedError();
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const signerAccount = args.account ?? currentAccount?.address;
|
|
342
|
-
if (!signerAccount) {
|
|
343
|
-
throw new WalletNoAccountSelectedError();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (!supportsSponsoredTransaction(wallet.features)) {
|
|
347
|
-
throw new WalletSponsoredTransactionNotSupportedError(
|
|
348
|
-
(wallet as ResolvableWallet).name,
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Resolve method: prefer raw Wallet Standard wallets (object-shaped features), then store/current/list
|
|
353
|
-
const walletName = (wallet as ResolvableWallet).name;
|
|
354
|
-
const walletVersion = (wallet as ResolvableWallet).version;
|
|
355
|
-
const rawWallets =
|
|
356
|
-
typeof getWallets === "function" ? getWallets().get() : [];
|
|
357
|
-
const rawWallet = rawWallets.find(
|
|
358
|
-
(w) =>
|
|
359
|
-
w.name === walletName &&
|
|
360
|
-
(walletVersion == null || w.version === walletVersion),
|
|
361
|
-
);
|
|
362
|
-
let signSponsoredTransaction =
|
|
363
|
-
(rawWallet != null
|
|
364
|
-
? getSponsoredTransactionMethod(
|
|
365
|
-
rawWallet as Parameters<typeof getSponsoredTransactionMethod>[0],
|
|
366
|
-
)
|
|
367
|
-
: undefined) ??
|
|
368
|
-
(walletFromStore != null
|
|
369
|
-
? getSponsoredTransactionMethod(
|
|
370
|
-
walletFromStore as Parameters<
|
|
371
|
-
typeof getSponsoredTransactionMethod
|
|
372
|
-
>[0],
|
|
373
|
-
)
|
|
374
|
-
: undefined) ??
|
|
375
|
-
getSponsoredTransactionMethod(
|
|
376
|
-
wallet as Parameters<typeof getSponsoredTransactionMethod>[0],
|
|
377
|
-
);
|
|
378
|
-
if (!signSponsoredTransaction) {
|
|
379
|
-
const walletFromList = wallets.find(
|
|
380
|
-
(w) =>
|
|
381
|
-
w.name === (wallet as ResolvableWallet).name &&
|
|
382
|
-
((wallet as ResolvableWallet).version == null ||
|
|
383
|
-
w.version === (wallet as ResolvableWallet).version),
|
|
384
|
-
);
|
|
385
|
-
signSponsoredTransaction =
|
|
386
|
-
walletFromList != null
|
|
387
|
-
? getSponsoredTransactionMethod(
|
|
388
|
-
walletFromList as Parameters<
|
|
389
|
-
typeof getSponsoredTransactionMethod
|
|
390
|
-
>[0],
|
|
391
|
-
)
|
|
392
|
-
: undefined;
|
|
393
|
-
}
|
|
394
|
-
if (!signSponsoredTransaction) {
|
|
395
|
-
throw new WalletSponsoredTransactionNotSupportedError(
|
|
396
|
-
(wallet as ResolvableWallet).name,
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
const tenant = (args.tenant ?? queryTenant ?? TenantId.UTOPIA).trim();
|
|
401
|
-
if (!tenant) {
|
|
402
|
-
throw new Error(
|
|
403
|
-
"Tenant could not be resolved; pass tenant or set the tenant query param",
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const assemblyId = resolveAssemblyId(args.assembly.item_id, queryItemId);
|
|
408
|
-
|
|
409
|
-
// If the txAction is UPDATE_METADATA, it goes through the standard assembly type
|
|
410
|
-
const assemblyType = getAssemblyTypeApiString(
|
|
411
|
-
args.txAction === SponsoredTransactionActions.UPDATE_METADATA
|
|
412
|
-
? Assemblies.Assembly
|
|
413
|
-
: args.assembly.type,
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
const payload: SponsoredTransactionInput = {
|
|
417
|
-
txAction: args.txAction,
|
|
418
|
-
assembly: assemblyId,
|
|
419
|
-
assemblyType: assemblyType,
|
|
420
|
-
metadata: args.metadata,
|
|
421
|
-
tenant,
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
log.info("Sponsored Transaction Payload:", payload);
|
|
425
|
-
|
|
426
|
-
let lastError: unknown;
|
|
427
|
-
const maxAttempts = DEFAULT_MAX_RETRIES + 1;
|
|
428
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
429
|
-
try {
|
|
430
|
-
return await signSponsoredTransaction(payload);
|
|
431
|
-
} catch (e) {
|
|
432
|
-
lastError = e;
|
|
433
|
-
const canRetry = attempt < maxAttempts && isRetryableSponsorError(e);
|
|
434
|
-
if (!canRetry) throw e;
|
|
435
|
-
await delay(DEFAULT_RETRY_DELAY_MS);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
throw lastError;
|
|
439
|
-
},
|
|
440
|
-
...mutationOptions,
|
|
441
|
-
});
|
|
442
|
-
}
|
package/index.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Main provider
|
|
2
|
-
export { EveFrontierProvider } from "./providers";
|
|
3
|
-
|
|
4
|
-
// Hooks
|
|
5
|
-
export {
|
|
6
|
-
useConnection,
|
|
7
|
-
useSmartObject,
|
|
8
|
-
useNotification,
|
|
9
|
-
useSponsoredTransaction,
|
|
10
|
-
} from "./hooks";
|
|
11
|
-
|
|
12
|
-
// Hook error types and sponsored transaction types
|
|
13
|
-
export {
|
|
14
|
-
WalletSponsoredTransactionNotSupportedError,
|
|
15
|
-
WalletNotConnectedError,
|
|
16
|
-
WalletNoAccountSelectedError,
|
|
17
|
-
} from "./hooks";
|
|
18
|
-
export type {
|
|
19
|
-
UseSponsoredTransactionError,
|
|
20
|
-
UseSponsoredTransactionArgs,
|
|
21
|
-
UseSponsoredTransactionMutationOptions,
|
|
22
|
-
} from "./hooks";
|
|
23
|
-
|
|
24
|
-
// Providers (for advanced usage)
|
|
25
|
-
export {
|
|
26
|
-
VaultProvider,
|
|
27
|
-
VaultContext,
|
|
28
|
-
SmartObjectProvider,
|
|
29
|
-
SmartObjectContext,
|
|
30
|
-
NotificationProvider,
|
|
31
|
-
NotificationContext,
|
|
32
|
-
} from "./providers";
|
|
33
|
-
|
|
34
|
-
// =========================================
|
|
35
|
-
// Types (re-exported from ./types)
|
|
36
|
-
// =========================================
|
|
37
|
-
export * from "./types";
|
|
38
|
-
|
|
39
|
-
// =========================================
|
|
40
|
-
// Utils (re-exported from ./utils)
|
|
41
|
-
// =========================================
|
|
42
|
-
export * from "./utils";
|
|
43
|
-
|
|
44
|
-
// =========================================
|
|
45
|
-
// GraphQL - Query execution & helper functions
|
|
46
|
-
// =========================================
|
|
47
|
-
export * from "./graphql";
|
|
48
|
-
|
|
49
|
-
// =========================================
|
|
50
|
-
// Config
|
|
51
|
-
// =========================================
|
|
52
|
-
export { dAppKit } from "./config/dapp-kit";
|
|
53
|
-
export {
|
|
54
|
-
getEnergyConfig,
|
|
55
|
-
getFuelEfficiencyConfig,
|
|
56
|
-
getFuelEfficiencyForType,
|
|
57
|
-
getEnergyUsageForType,
|
|
58
|
-
} from "./utils/config";
|
|
59
|
-
|
|
60
|
-
// =========================================
|
|
61
|
-
// Constants & Configuration
|
|
62
|
-
// =========================================
|
|
63
|
-
export {
|
|
64
|
-
getSuiGraphqlEndpoint,
|
|
65
|
-
getEveWorldPackageId,
|
|
66
|
-
getCharacterOwnerCapType,
|
|
67
|
-
getObjectRegistryType,
|
|
68
|
-
POLLING_INTERVAL,
|
|
69
|
-
STORAGE_KEYS,
|
|
70
|
-
} from "./utils/constants";
|
|
71
|
-
|
|
72
|
-
// =========================================
|
|
73
|
-
// Wallet Standard Extensions
|
|
74
|
-
// =========================================
|
|
75
|
-
export {
|
|
76
|
-
getAssemblyTypeApiString,
|
|
77
|
-
hasSponsoredTransactionFeature,
|
|
78
|
-
walletSupportsSponsoredTransaction,
|
|
79
|
-
getSponsoredTransactionFeature,
|
|
80
|
-
} from "./wallet";
|
|
81
|
-
|
|
82
|
-
export type {
|
|
83
|
-
EveFrontierSponsoredTransactionFeature,
|
|
84
|
-
SponsoredTransactionArgs,
|
|
85
|
-
SponsoredTransactionInput,
|
|
86
|
-
SponsoredTransactionOutput,
|
|
87
|
-
SponsoredTransactionMethod,
|
|
88
|
-
} from "./wallet";
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
-
import { DAppKitProvider } from "@mysten/dapp-kit-react";
|
|
4
|
-
import { dAppKit } from "../config/dapp-kit";
|
|
5
|
-
|
|
6
|
-
import NotificationProvider from "./NotificationProvider";
|
|
7
|
-
import SmartObjectProvider from "./SmartObjectProvider";
|
|
8
|
-
import VaultProvider from "./VaultProvider";
|
|
9
|
-
/**
|
|
10
|
-
* EveFrontierProvider wraps the application with all necessary providers
|
|
11
|
-
* for the EVE Frontier dApp kit.
|
|
12
|
-
*
|
|
13
|
-
* Provider hierarchy:
|
|
14
|
-
* 1. QueryClientProvider - React Query for async state management
|
|
15
|
-
* 2. DAppKitProvider - Sui blockchain client
|
|
16
|
-
* 3. VaultProvider - Eve-specific wallet configuration (from @evefrontier/dapp-kit)
|
|
17
|
-
* 4. SmartObjectProvider - Smart object data via GraphQL
|
|
18
|
-
* 5. NotificationProvider - User notifications
|
|
19
|
-
* @category Providers
|
|
20
|
-
*/
|
|
21
|
-
const EveFrontierProvider = ({
|
|
22
|
-
children,
|
|
23
|
-
queryClient,
|
|
24
|
-
}: {
|
|
25
|
-
children: ReactNode;
|
|
26
|
-
queryClient: QueryClient;
|
|
27
|
-
}) => {
|
|
28
|
-
return (
|
|
29
|
-
<QueryClientProvider client={queryClient}>
|
|
30
|
-
<DAppKitProvider dAppKit={dAppKit}>
|
|
31
|
-
<VaultProvider>
|
|
32
|
-
<SmartObjectProvider>
|
|
33
|
-
<NotificationProvider>{children}</NotificationProvider>
|
|
34
|
-
</SmartObjectProvider>
|
|
35
|
-
</VaultProvider>
|
|
36
|
-
</DAppKitProvider>
|
|
37
|
-
</QueryClientProvider>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default EveFrontierProvider;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { ReactNode, createContext, useCallback, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import { Severity } from "../types";
|
|
4
|
-
import { NotificationContextType, NotificationState } from "../types";
|
|
5
|
-
|
|
6
|
-
/** @category Providers */
|
|
7
|
-
export const NotificationContext = createContext<NotificationContextType>({
|
|
8
|
-
notify: () => {},
|
|
9
|
-
notification: {
|
|
10
|
-
message: "",
|
|
11
|
-
txHash: "",
|
|
12
|
-
onSuccess: () => {},
|
|
13
|
-
severity: Severity.Success,
|
|
14
|
-
handleClose: () => {},
|
|
15
|
-
isOpen: false,
|
|
16
|
-
},
|
|
17
|
-
handleClose: () => {},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* NotificationProvider manages notifications for transactions and messages.
|
|
22
|
-
*
|
|
23
|
-
* @category Providers
|
|
24
|
-
*/
|
|
25
|
-
const NotificationProvider = ({ children }: { children: ReactNode }) => {
|
|
26
|
-
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
27
|
-
const [message, setMessage] = useState<string>("");
|
|
28
|
-
const [severity, setSeverity] = useState<Severity>(Severity.Info);
|
|
29
|
-
const [txHash, setTxHash] = useState<string>("");
|
|
30
|
-
const [onSuccess, setOnSuccess] = useState<NotificationState["onSuccess"]>(
|
|
31
|
-
() => () => {},
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const handleClose = useCallback(() => {
|
|
35
|
-
setIsOpen(false);
|
|
36
|
-
if (severity === Severity.Success) {
|
|
37
|
-
onSuccess();
|
|
38
|
-
}
|
|
39
|
-
setOnSuccess(() => () => {});
|
|
40
|
-
}, [onSuccess, severity]);
|
|
41
|
-
|
|
42
|
-
const notify = useCallback(
|
|
43
|
-
({
|
|
44
|
-
type,
|
|
45
|
-
message,
|
|
46
|
-
txHash,
|
|
47
|
-
onSuccess,
|
|
48
|
-
}: {
|
|
49
|
-
type: Severity;
|
|
50
|
-
message?: string;
|
|
51
|
-
txHash?: string;
|
|
52
|
-
onSuccess?: () => void;
|
|
53
|
-
}) => {
|
|
54
|
-
setSeverity(type);
|
|
55
|
-
setIsOpen(true);
|
|
56
|
-
setOnSuccess(() => onSuccess ?? (() => {}));
|
|
57
|
-
|
|
58
|
-
// If success with txHash, show success message with transaction hash
|
|
59
|
-
if (type === Severity.Success && txHash) {
|
|
60
|
-
setMessage(
|
|
61
|
-
`Transaction was successful. ${message ?? ""} Transaction hash: ${txHash}`,
|
|
62
|
-
);
|
|
63
|
-
setTxHash(txHash);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Otherwise, show the passed message or a default based on severity
|
|
68
|
-
if (message) {
|
|
69
|
-
setMessage(message);
|
|
70
|
-
} else {
|
|
71
|
-
switch (type) {
|
|
72
|
-
case Severity.Success:
|
|
73
|
-
setMessage("Operation completed successfully.");
|
|
74
|
-
break;
|
|
75
|
-
case Severity.Error:
|
|
76
|
-
setMessage("An error occurred.");
|
|
77
|
-
break;
|
|
78
|
-
case Severity.Warning:
|
|
79
|
-
setMessage("Warning.");
|
|
80
|
-
break;
|
|
81
|
-
case Severity.Info:
|
|
82
|
-
default:
|
|
83
|
-
setMessage("Processing...");
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
setTxHash(txHash ?? "");
|
|
88
|
-
},
|
|
89
|
-
[],
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const notification: NotificationState = {
|
|
93
|
-
message,
|
|
94
|
-
txHash,
|
|
95
|
-
onSuccess,
|
|
96
|
-
severity,
|
|
97
|
-
handleClose,
|
|
98
|
-
isOpen,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<NotificationContext.Provider value={{ notify, handleClose, notification }}>
|
|
103
|
-
{children}
|
|
104
|
-
</NotificationContext.Provider>
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export default NotificationProvider;
|