@fractalshq/sync 0.1.0 → 0.1.2
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 +43 -11
- package/dist/chunk-4VKCXC52.mjs +129 -0
- package/dist/chunk-4ZYNBLY5.mjs +129 -0
- package/dist/chunk-DUDWBTA2.mjs +0 -0
- package/dist/chunk-FBL2T6BA.mjs +249 -0
- package/dist/chunk-ZIWHYEXE.mjs +498 -0
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +19 -649
- package/dist/index.mjs +7 -42
- package/dist/v1/core/index.d.mts +28 -0
- package/dist/v1/core/index.d.ts +28 -0
- package/dist/v1/core/index.js +320 -0
- package/dist/v1/core/index.mjs +51 -0
- package/dist/v1/index.d.mts +3 -0
- package/dist/v1/index.d.ts +3 -0
- package/dist/v1/index.js +816 -0
- package/dist/v1/index.mjs +63 -0
- package/dist/v1/react/index.d.mts +111 -0
- package/dist/v1/react/index.d.ts +111 -0
- package/dist/v1/react/index.js +552 -0
- package/dist/v1/react/index.mjs +330 -0
- package/dist/v1/server/index.d.mts +67 -0
- package/dist/v1/server/index.d.ts +67 -0
- package/dist/v1/server/index.js +540 -0
- package/dist/v1/server/index.mjs +15 -0
- package/dist/v1/widgets/index.d.mts +2 -0
- package/dist/v1/widgets/index.d.ts +2 -0
- package/dist/v1/widgets/index.js +18 -0
- package/dist/v1/widgets/index.mjs +0 -0
- package/dist/v2/core/index.d.mts +5 -21
- package/dist/v2/core/index.d.ts +5 -21
- package/dist/v2/core/index.js +9 -35
- package/dist/v2/core/index.mjs +3 -7
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.d.ts +1 -1
- package/dist/v2/index.js +9 -35
- package/dist/v2/index.mjs +4 -7
- package/dist/v2/react/index.d.mts +5 -27
- package/dist/v2/react/index.d.ts +5 -27
- package/dist/v2/react/index.js +26 -108
- package/dist/v2/react/index.mjs +20 -76
- package/package.json +52 -21
package/dist/v2/core/index.d.ts
CHANGED
|
@@ -23,17 +23,6 @@ interface ClaimTransactionResponse {
|
|
|
23
23
|
instructions: ClaimTransactionInstruction[];
|
|
24
24
|
transaction?: string;
|
|
25
25
|
}
|
|
26
|
-
interface CommitClaimRequest {
|
|
27
|
-
distributionId: string;
|
|
28
|
-
signedTransactionBase64: string;
|
|
29
|
-
claimantPubkey: string;
|
|
30
|
-
}
|
|
31
|
-
interface CommitClaimResponse {
|
|
32
|
-
success: boolean;
|
|
33
|
-
distributorId: string;
|
|
34
|
-
txSignature: string;
|
|
35
|
-
alreadyTracked?: boolean;
|
|
36
|
-
}
|
|
37
26
|
interface ClaimableDistribution {
|
|
38
27
|
distributorId: string;
|
|
39
28
|
distributorName?: string;
|
|
@@ -46,9 +35,10 @@ interface ClaimableDistribution {
|
|
|
46
35
|
solFee?: string;
|
|
47
36
|
};
|
|
48
37
|
}
|
|
49
|
-
interface
|
|
50
|
-
wallet: string;
|
|
38
|
+
interface ClaimsResponse {
|
|
51
39
|
claimable: ClaimableDistribution[];
|
|
40
|
+
claimed: ClaimHistoryItem[];
|
|
41
|
+
nextCursor: string | null;
|
|
52
42
|
}
|
|
53
43
|
interface ClaimHistoryItem {
|
|
54
44
|
distributorId: string;
|
|
@@ -64,10 +54,6 @@ interface ClaimHistoryItem {
|
|
|
64
54
|
solFeeLamports?: string | null;
|
|
65
55
|
solFeeUsd?: string | null;
|
|
66
56
|
}
|
|
67
|
-
interface ClaimHistoryResponse {
|
|
68
|
-
items: ClaimHistoryItem[];
|
|
69
|
-
nextCursor: string | null;
|
|
70
|
-
}
|
|
71
57
|
|
|
72
58
|
type Fetcher = typeof fetch;
|
|
73
59
|
declare const DEFAULT_BASE_PATH: string;
|
|
@@ -96,8 +82,6 @@ declare function isRelativeUrl(path: string): boolean;
|
|
|
96
82
|
type BuildClaimTransactionRequest = ClaimTransactionRequest;
|
|
97
83
|
type BuildClaimTransactionResponse = ClaimTransactionResponse;
|
|
98
84
|
declare function buildClaimTransaction(input: BuildClaimTransactionRequest, options?: SyncRequestOptions): Promise<BuildClaimTransactionResponse>;
|
|
99
|
-
declare function
|
|
100
|
-
declare function listClaimable(options?: SyncRequestOptions): Promise<ClaimableResponse>;
|
|
101
|
-
declare function listClaimHistory(options?: SyncRequestOptions): Promise<ClaimHistoryResponse>;
|
|
85
|
+
declare function listClaims(wallet: string, options?: SyncRequestOptions): Promise<ClaimsResponse>;
|
|
102
86
|
|
|
103
|
-
export { type BuildClaimTransactionRequest, type BuildClaimTransactionResponse, type ClaimHistoryItem, type
|
|
87
|
+
export { type BuildClaimTransactionRequest, type BuildClaimTransactionResponse, type ClaimHistoryItem, type ClaimTransactionInstruction, type ClaimTransactionRequest, type ClaimTransactionResponse, type ClaimableDistribution, type ClaimsResponse, DEFAULT_BASE_PATH, type Fetcher, SyncReactError, type SyncRequestConfig, type SyncRequestOptions, buildClaimTransaction, buildUrl, isAbsoluteUrl, isRelativeUrl, listClaims, requestJSON, resolveFetcher, resolveRequestConfig, sanitizeBasePath };
|
package/dist/v2/core/index.js
CHANGED
|
@@ -50,11 +50,9 @@ __export(core_exports, {
|
|
|
50
50
|
SyncReactError: () => SyncReactError,
|
|
51
51
|
buildClaimTransaction: () => buildClaimTransaction,
|
|
52
52
|
buildUrl: () => buildUrl,
|
|
53
|
-
commitClaim: () => commitClaim,
|
|
54
53
|
isAbsoluteUrl: () => isAbsoluteUrl,
|
|
55
54
|
isRelativeUrl: () => isRelativeUrl,
|
|
56
|
-
|
|
57
|
-
listClaimable: () => listClaimable,
|
|
55
|
+
listClaims: () => listClaims,
|
|
58
56
|
requestJSON: () => requestJSON,
|
|
59
57
|
resolveFetcher: () => resolveFetcher,
|
|
60
58
|
resolveRequestConfig: () => resolveRequestConfig,
|
|
@@ -63,7 +61,7 @@ __export(core_exports, {
|
|
|
63
61
|
module.exports = __toCommonJS(core_exports);
|
|
64
62
|
|
|
65
63
|
// src/v2/core/http.ts
|
|
66
|
-
var FALLBACK_BASE_PATH = "/api/v2";
|
|
64
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
67
65
|
var _a, _b;
|
|
68
66
|
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
69
67
|
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
@@ -86,7 +84,7 @@ async function requestJSON(config, path, init) {
|
|
|
86
84
|
var _a2;
|
|
87
85
|
const url = buildUrl(config.basePath, path);
|
|
88
86
|
const requestInit = prepareInit(init);
|
|
89
|
-
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 :
|
|
87
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : "omit";
|
|
90
88
|
const response = await config.fetcher(url, requestInit);
|
|
91
89
|
const payload = await parseResponseBody(response);
|
|
92
90
|
if (!response.ok) {
|
|
@@ -164,35 +162,13 @@ async function buildClaimTransaction(input, options) {
|
|
|
164
162
|
}
|
|
165
163
|
);
|
|
166
164
|
}
|
|
167
|
-
async function
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
throw new SyncReactError(400, "distribution_id_required");
|
|
171
|
-
}
|
|
172
|
-
if (!(input == null ? void 0 : input.signedTransactionBase64)) {
|
|
173
|
-
throw new SyncReactError(400, "signed_transaction_required");
|
|
174
|
-
}
|
|
175
|
-
if (!(input == null ? void 0 : input.claimantPubkey)) {
|
|
176
|
-
throw new SyncReactError(400, "claimant_pubkey_required");
|
|
165
|
+
async function listClaims(wallet, options) {
|
|
166
|
+
if (!wallet) {
|
|
167
|
+
throw new SyncReactError(400, "wallet_required");
|
|
177
168
|
}
|
|
178
169
|
const config = resolveRequestConfig(options);
|
|
179
|
-
const
|
|
180
|
-
return requestJSON(
|
|
181
|
-
config,
|
|
182
|
-
`/claims/${encodeURIComponent(distributionId)}/commit`,
|
|
183
|
-
{
|
|
184
|
-
method: "POST",
|
|
185
|
-
body: JSON.stringify(body)
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
async function listClaimable(options) {
|
|
190
|
-
const config = resolveRequestConfig(options);
|
|
191
|
-
return requestJSON(config, "/claims/me", { method: "GET" });
|
|
192
|
-
}
|
|
193
|
-
async function listClaimHistory(options) {
|
|
194
|
-
const config = resolveRequestConfig(options);
|
|
195
|
-
return requestJSON(config, "/claims/history", { method: "GET" });
|
|
170
|
+
const qs = new URLSearchParams({ wallet }).toString();
|
|
171
|
+
return requestJSON(config, `/claims?${qs}`, { method: "GET" });
|
|
196
172
|
}
|
|
197
173
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
174
|
0 && (module.exports = {
|
|
@@ -200,11 +176,9 @@ async function listClaimHistory(options) {
|
|
|
200
176
|
SyncReactError,
|
|
201
177
|
buildClaimTransaction,
|
|
202
178
|
buildUrl,
|
|
203
|
-
commitClaim,
|
|
204
179
|
isAbsoluteUrl,
|
|
205
180
|
isRelativeUrl,
|
|
206
|
-
|
|
207
|
-
listClaimable,
|
|
181
|
+
listClaims,
|
|
208
182
|
requestJSON,
|
|
209
183
|
resolveFetcher,
|
|
210
184
|
resolveRequestConfig,
|
package/dist/v2/core/index.mjs
CHANGED
|
@@ -3,27 +3,23 @@ import {
|
|
|
3
3
|
SyncReactError,
|
|
4
4
|
buildClaimTransaction,
|
|
5
5
|
buildUrl,
|
|
6
|
-
commitClaim,
|
|
7
6
|
isAbsoluteUrl,
|
|
8
7
|
isRelativeUrl,
|
|
9
|
-
|
|
10
|
-
listClaimable,
|
|
8
|
+
listClaims,
|
|
11
9
|
requestJSON,
|
|
12
10
|
resolveFetcher,
|
|
13
11
|
resolveRequestConfig,
|
|
14
12
|
sanitizeBasePath
|
|
15
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-4VKCXC52.mjs";
|
|
16
14
|
import "../../chunk-FWCSY2DS.mjs";
|
|
17
15
|
export {
|
|
18
16
|
DEFAULT_BASE_PATH,
|
|
19
17
|
SyncReactError,
|
|
20
18
|
buildClaimTransaction,
|
|
21
19
|
buildUrl,
|
|
22
|
-
commitClaim,
|
|
23
20
|
isAbsoluteUrl,
|
|
24
21
|
isRelativeUrl,
|
|
25
|
-
|
|
26
|
-
listClaimable,
|
|
22
|
+
listClaims,
|
|
27
23
|
requestJSON,
|
|
28
24
|
resolveFetcher,
|
|
29
25
|
resolveRequestConfig,
|
package/dist/v2/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { BuildClaimTransactionRequest, BuildClaimTransactionResponse, ClaimHistoryItem,
|
|
1
|
+
export { BuildClaimTransactionRequest, BuildClaimTransactionResponse, ClaimHistoryItem, ClaimTransactionInstruction, ClaimTransactionRequest, ClaimTransactionResponse, ClaimableDistribution, ClaimsResponse, DEFAULT_BASE_PATH, Fetcher, SyncReactError, SyncRequestConfig, SyncRequestOptions, buildClaimTransaction, buildUrl, isAbsoluteUrl, isRelativeUrl, listClaims, requestJSON, resolveFetcher, resolveRequestConfig, sanitizeBasePath } from './core/index.mjs';
|
package/dist/v2/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { BuildClaimTransactionRequest, BuildClaimTransactionResponse, ClaimHistoryItem,
|
|
1
|
+
export { BuildClaimTransactionRequest, BuildClaimTransactionResponse, ClaimHistoryItem, ClaimTransactionInstruction, ClaimTransactionRequest, ClaimTransactionResponse, ClaimableDistribution, ClaimsResponse, DEFAULT_BASE_PATH, Fetcher, SyncReactError, SyncRequestConfig, SyncRequestOptions, buildClaimTransaction, buildUrl, isAbsoluteUrl, isRelativeUrl, listClaims, requestJSON, resolveFetcher, resolveRequestConfig, sanitizeBasePath } from './core/index.js';
|
package/dist/v2/index.js
CHANGED
|
@@ -50,11 +50,9 @@ __export(v2_exports, {
|
|
|
50
50
|
SyncReactError: () => SyncReactError,
|
|
51
51
|
buildClaimTransaction: () => buildClaimTransaction,
|
|
52
52
|
buildUrl: () => buildUrl,
|
|
53
|
-
commitClaim: () => commitClaim,
|
|
54
53
|
isAbsoluteUrl: () => isAbsoluteUrl,
|
|
55
54
|
isRelativeUrl: () => isRelativeUrl,
|
|
56
|
-
|
|
57
|
-
listClaimable: () => listClaimable,
|
|
55
|
+
listClaims: () => listClaims,
|
|
58
56
|
requestJSON: () => requestJSON,
|
|
59
57
|
resolveFetcher: () => resolveFetcher,
|
|
60
58
|
resolveRequestConfig: () => resolveRequestConfig,
|
|
@@ -63,7 +61,7 @@ __export(v2_exports, {
|
|
|
63
61
|
module.exports = __toCommonJS(v2_exports);
|
|
64
62
|
|
|
65
63
|
// src/v2/core/http.ts
|
|
66
|
-
var FALLBACK_BASE_PATH = "/api/v2";
|
|
64
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
67
65
|
var _a, _b;
|
|
68
66
|
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
69
67
|
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
@@ -86,7 +84,7 @@ async function requestJSON(config, path, init) {
|
|
|
86
84
|
var _a2;
|
|
87
85
|
const url = buildUrl(config.basePath, path);
|
|
88
86
|
const requestInit = prepareInit(init);
|
|
89
|
-
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 :
|
|
87
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : "omit";
|
|
90
88
|
const response = await config.fetcher(url, requestInit);
|
|
91
89
|
const payload = await parseResponseBody(response);
|
|
92
90
|
if (!response.ok) {
|
|
@@ -164,35 +162,13 @@ async function buildClaimTransaction(input, options) {
|
|
|
164
162
|
}
|
|
165
163
|
);
|
|
166
164
|
}
|
|
167
|
-
async function
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
throw new SyncReactError(400, "distribution_id_required");
|
|
171
|
-
}
|
|
172
|
-
if (!(input == null ? void 0 : input.signedTransactionBase64)) {
|
|
173
|
-
throw new SyncReactError(400, "signed_transaction_required");
|
|
174
|
-
}
|
|
175
|
-
if (!(input == null ? void 0 : input.claimantPubkey)) {
|
|
176
|
-
throw new SyncReactError(400, "claimant_pubkey_required");
|
|
165
|
+
async function listClaims(wallet, options) {
|
|
166
|
+
if (!wallet) {
|
|
167
|
+
throw new SyncReactError(400, "wallet_required");
|
|
177
168
|
}
|
|
178
169
|
const config = resolveRequestConfig(options);
|
|
179
|
-
const
|
|
180
|
-
return requestJSON(
|
|
181
|
-
config,
|
|
182
|
-
`/claims/${encodeURIComponent(distributionId)}/commit`,
|
|
183
|
-
{
|
|
184
|
-
method: "POST",
|
|
185
|
-
body: JSON.stringify(body)
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
async function listClaimable(options) {
|
|
190
|
-
const config = resolveRequestConfig(options);
|
|
191
|
-
return requestJSON(config, "/claims/me", { method: "GET" });
|
|
192
|
-
}
|
|
193
|
-
async function listClaimHistory(options) {
|
|
194
|
-
const config = resolveRequestConfig(options);
|
|
195
|
-
return requestJSON(config, "/claims/history", { method: "GET" });
|
|
170
|
+
const qs = new URLSearchParams({ wallet }).toString();
|
|
171
|
+
return requestJSON(config, `/claims?${qs}`, { method: "GET" });
|
|
196
172
|
}
|
|
197
173
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
174
|
0 && (module.exports = {
|
|
@@ -200,11 +176,9 @@ async function listClaimHistory(options) {
|
|
|
200
176
|
SyncReactError,
|
|
201
177
|
buildClaimTransaction,
|
|
202
178
|
buildUrl,
|
|
203
|
-
commitClaim,
|
|
204
179
|
isAbsoluteUrl,
|
|
205
180
|
isRelativeUrl,
|
|
206
|
-
|
|
207
|
-
listClaimable,
|
|
181
|
+
listClaims,
|
|
208
182
|
requestJSON,
|
|
209
183
|
resolveFetcher,
|
|
210
184
|
resolveRequestConfig,
|
package/dist/v2/index.mjs
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
+
import "../chunk-DUDWBTA2.mjs";
|
|
1
2
|
import {
|
|
2
3
|
DEFAULT_BASE_PATH,
|
|
3
4
|
SyncReactError,
|
|
4
5
|
buildClaimTransaction,
|
|
5
6
|
buildUrl,
|
|
6
|
-
commitClaim,
|
|
7
7
|
isAbsoluteUrl,
|
|
8
8
|
isRelativeUrl,
|
|
9
|
-
|
|
10
|
-
listClaimable,
|
|
9
|
+
listClaims,
|
|
11
10
|
requestJSON,
|
|
12
11
|
resolveFetcher,
|
|
13
12
|
resolveRequestConfig,
|
|
14
13
|
sanitizeBasePath
|
|
15
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-4VKCXC52.mjs";
|
|
16
15
|
import "../chunk-FWCSY2DS.mjs";
|
|
17
16
|
export {
|
|
18
17
|
DEFAULT_BASE_PATH,
|
|
19
18
|
SyncReactError,
|
|
20
19
|
buildClaimTransaction,
|
|
21
20
|
buildUrl,
|
|
22
|
-
commitClaim,
|
|
23
21
|
isAbsoluteUrl,
|
|
24
22
|
isRelativeUrl,
|
|
25
|
-
|
|
26
|
-
listClaimable,
|
|
23
|
+
listClaims,
|
|
27
24
|
requestJSON,
|
|
28
25
|
resolveFetcher,
|
|
29
26
|
resolveRequestConfig,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
4
|
-
import { Fetcher,
|
|
4
|
+
import { Fetcher, ClaimsResponse, SyncReactError, BuildClaimTransactionRequest, BuildClaimTransactionResponse } from '../core/index.mjs';
|
|
5
5
|
|
|
6
6
|
interface SyncContextValue {
|
|
7
7
|
basePath: string;
|
|
@@ -21,30 +21,8 @@ interface SyncClient {
|
|
|
21
21
|
}
|
|
22
22
|
declare function useSyncClient(): SyncClient;
|
|
23
23
|
type QueryOptions<T> = Omit<UseQueryOptions<T, SyncReactError, T>, "queryKey" | "queryFn">;
|
|
24
|
-
declare function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
declare function useClaimTransaction(distributionId: string | null | undefined, options?: UseMutationOptions<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>): UseMutationResult<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>;
|
|
28
|
-
type ClaimCommitInput = Omit<CommitClaimRequest, "distributionId">;
|
|
29
|
-
declare function useCommitClaim(distributionId: string | null | undefined, options?: UseMutationOptions<CommitClaimResponse, SyncReactError, ClaimCommitInput>): UseMutationResult<CommitClaimResponse, SyncReactError, ClaimCommitInput>;
|
|
30
|
-
interface ClaimFlowState {
|
|
31
|
-
latestPayload: BuildClaimTransactionResponse | null;
|
|
32
|
-
building: boolean;
|
|
33
|
-
claiming: boolean;
|
|
34
|
-
error: SyncReactError | null;
|
|
35
|
-
}
|
|
36
|
-
type ClaimFlowSigner = (payload: BuildClaimTransactionResponse) => Promise<ClaimCommitInput> | ClaimCommitInput;
|
|
37
|
-
interface ClaimFlowClaimResult {
|
|
38
|
-
payload: BuildClaimTransactionResponse;
|
|
39
|
-
commit: CommitClaimResponse;
|
|
40
|
-
signerInput: ClaimCommitInput;
|
|
41
|
-
}
|
|
42
|
-
interface ClaimFlowResult {
|
|
43
|
-
state: ClaimFlowState;
|
|
44
|
-
build: (input?: ClaimTransactionInput) => Promise<BuildClaimTransactionResponse>;
|
|
45
|
-
claim: (signer: ClaimFlowSigner, input?: ClaimTransactionInput) => Promise<ClaimFlowClaimResult>;
|
|
46
|
-
reset: () => void;
|
|
47
|
-
}
|
|
48
|
-
declare function useClaimFlow(distributionId: string | null | undefined): ClaimFlowResult;
|
|
24
|
+
declare function useClaims<TResponse = ClaimsResponse>(wallet?: string | null, options?: QueryOptions<TResponse>): UseQueryResult<TResponse, SyncReactError>;
|
|
25
|
+
type ClaimTransactionInput = BuildClaimTransactionRequest;
|
|
26
|
+
declare function useClaimTransaction(options?: UseMutationOptions<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>): UseMutationResult<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>;
|
|
49
27
|
|
|
50
|
-
export { type
|
|
28
|
+
export { type ClaimTransactionInput, type SyncClient, SyncProvider, type SyncProviderProps, useClaimTransaction, useClaims, useSyncClient };
|
package/dist/v2/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
4
|
-
import { Fetcher,
|
|
4
|
+
import { Fetcher, ClaimsResponse, SyncReactError, BuildClaimTransactionRequest, BuildClaimTransactionResponse } from '../core/index.js';
|
|
5
5
|
|
|
6
6
|
interface SyncContextValue {
|
|
7
7
|
basePath: string;
|
|
@@ -21,30 +21,8 @@ interface SyncClient {
|
|
|
21
21
|
}
|
|
22
22
|
declare function useSyncClient(): SyncClient;
|
|
23
23
|
type QueryOptions<T> = Omit<UseQueryOptions<T, SyncReactError, T>, "queryKey" | "queryFn">;
|
|
24
|
-
declare function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
declare function useClaimTransaction(distributionId: string | null | undefined, options?: UseMutationOptions<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>): UseMutationResult<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>;
|
|
28
|
-
type ClaimCommitInput = Omit<CommitClaimRequest, "distributionId">;
|
|
29
|
-
declare function useCommitClaim(distributionId: string | null | undefined, options?: UseMutationOptions<CommitClaimResponse, SyncReactError, ClaimCommitInput>): UseMutationResult<CommitClaimResponse, SyncReactError, ClaimCommitInput>;
|
|
30
|
-
interface ClaimFlowState {
|
|
31
|
-
latestPayload: BuildClaimTransactionResponse | null;
|
|
32
|
-
building: boolean;
|
|
33
|
-
claiming: boolean;
|
|
34
|
-
error: SyncReactError | null;
|
|
35
|
-
}
|
|
36
|
-
type ClaimFlowSigner = (payload: BuildClaimTransactionResponse) => Promise<ClaimCommitInput> | ClaimCommitInput;
|
|
37
|
-
interface ClaimFlowClaimResult {
|
|
38
|
-
payload: BuildClaimTransactionResponse;
|
|
39
|
-
commit: CommitClaimResponse;
|
|
40
|
-
signerInput: ClaimCommitInput;
|
|
41
|
-
}
|
|
42
|
-
interface ClaimFlowResult {
|
|
43
|
-
state: ClaimFlowState;
|
|
44
|
-
build: (input?: ClaimTransactionInput) => Promise<BuildClaimTransactionResponse>;
|
|
45
|
-
claim: (signer: ClaimFlowSigner, input?: ClaimTransactionInput) => Promise<ClaimFlowClaimResult>;
|
|
46
|
-
reset: () => void;
|
|
47
|
-
}
|
|
48
|
-
declare function useClaimFlow(distributionId: string | null | undefined): ClaimFlowResult;
|
|
24
|
+
declare function useClaims<TResponse = ClaimsResponse>(wallet?: string | null, options?: QueryOptions<TResponse>): UseQueryResult<TResponse, SyncReactError>;
|
|
25
|
+
type ClaimTransactionInput = BuildClaimTransactionRequest;
|
|
26
|
+
declare function useClaimTransaction(options?: UseMutationOptions<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>): UseMutationResult<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>;
|
|
49
27
|
|
|
50
|
-
export { type
|
|
28
|
+
export { type ClaimTransactionInput, type SyncClient, SyncProvider, type SyncProviderProps, useClaimTransaction, useClaims, useSyncClient };
|
package/dist/v2/react/index.js
CHANGED
|
@@ -50,19 +50,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
50
50
|
var react_exports = {};
|
|
51
51
|
__export(react_exports, {
|
|
52
52
|
SyncProvider: () => SyncProvider,
|
|
53
|
-
useClaimFlow: () => useClaimFlow,
|
|
54
|
-
useClaimHistory: () => useClaimHistory,
|
|
55
53
|
useClaimTransaction: () => useClaimTransaction,
|
|
56
|
-
|
|
57
|
-
useCommitClaim: () => useCommitClaim,
|
|
54
|
+
useClaims: () => useClaims,
|
|
58
55
|
useSyncClient: () => useSyncClient
|
|
59
56
|
});
|
|
60
57
|
module.exports = __toCommonJS(react_exports);
|
|
61
58
|
var import_react = require("react");
|
|
59
|
+
var import_wallet_adapter_react = require("@solana/wallet-adapter-react");
|
|
62
60
|
var import_react_query = require("@tanstack/react-query");
|
|
63
61
|
|
|
64
62
|
// src/v2/core/http.ts
|
|
65
|
-
var FALLBACK_BASE_PATH = "/api/v2";
|
|
63
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
66
64
|
var _a, _b;
|
|
67
65
|
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
68
66
|
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
@@ -85,7 +83,7 @@ async function requestJSON(config, path, init) {
|
|
|
85
83
|
var _a2;
|
|
86
84
|
const url = buildUrl(config.basePath, path);
|
|
87
85
|
const requestInit = prepareInit(init);
|
|
88
|
-
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 :
|
|
86
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : "omit";
|
|
89
87
|
const response = await config.fetcher(url, requestInit);
|
|
90
88
|
const payload = await parseResponseBody(response);
|
|
91
89
|
if (!response.ok) {
|
|
@@ -117,9 +115,6 @@ function buildUrl(basePath, path) {
|
|
|
117
115
|
function isAbsoluteUrl(path) {
|
|
118
116
|
return /^https?:\/\//i.test(path);
|
|
119
117
|
}
|
|
120
|
-
function isRelativeUrl(path) {
|
|
121
|
-
return !isAbsoluteUrl(path);
|
|
122
|
-
}
|
|
123
118
|
function prepareInit(init) {
|
|
124
119
|
const finalInit = __spreadValues({}, init);
|
|
125
120
|
if ((init == null ? void 0 : init.headers) instanceof Headers) {
|
|
@@ -163,35 +158,13 @@ async function buildClaimTransaction(input, options) {
|
|
|
163
158
|
}
|
|
164
159
|
);
|
|
165
160
|
}
|
|
166
|
-
async function
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
throw new SyncReactError(400, "distribution_id_required");
|
|
170
|
-
}
|
|
171
|
-
if (!(input == null ? void 0 : input.signedTransactionBase64)) {
|
|
172
|
-
throw new SyncReactError(400, "signed_transaction_required");
|
|
161
|
+
async function listClaims(wallet, options) {
|
|
162
|
+
if (!wallet) {
|
|
163
|
+
throw new SyncReactError(400, "wallet_required");
|
|
173
164
|
}
|
|
174
|
-
if (!(input == null ? void 0 : input.claimantPubkey)) {
|
|
175
|
-
throw new SyncReactError(400, "claimant_pubkey_required");
|
|
176
|
-
}
|
|
177
|
-
const config = resolveRequestConfig(options);
|
|
178
|
-
const _a2 = input, { distributionId: _unused } = _a2, body = __objRest(_a2, ["distributionId"]);
|
|
179
|
-
return requestJSON(
|
|
180
|
-
config,
|
|
181
|
-
`/claims/${encodeURIComponent(distributionId)}/commit`,
|
|
182
|
-
{
|
|
183
|
-
method: "POST",
|
|
184
|
-
body: JSON.stringify(body)
|
|
185
|
-
}
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
async function listClaimable(options) {
|
|
189
|
-
const config = resolveRequestConfig(options);
|
|
190
|
-
return requestJSON(config, "/claims/me", { method: "GET" });
|
|
191
|
-
}
|
|
192
|
-
async function listClaimHistory(options) {
|
|
193
165
|
const config = resolveRequestConfig(options);
|
|
194
|
-
|
|
166
|
+
const qs = new URLSearchParams({ wallet }).toString();
|
|
167
|
+
return requestJSON(config, `/claims?${qs}`, { method: "GET" });
|
|
195
168
|
}
|
|
196
169
|
|
|
197
170
|
// src/v2/react/index.tsx
|
|
@@ -224,81 +197,29 @@ function useSyncClient() {
|
|
|
224
197
|
};
|
|
225
198
|
}, [requestConfig]);
|
|
226
199
|
}
|
|
227
|
-
function
|
|
200
|
+
function useClaims(wallet, options) {
|
|
201
|
+
var _a2, _b2, _c;
|
|
202
|
+
const walletContext = (0, import_wallet_adapter_react.useWallet)();
|
|
228
203
|
const requestConfig = useSyncRequestConfig();
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
204
|
+
const resolvedWallet = (_b2 = wallet != null ? wallet : (_a2 = walletContext == null ? void 0 : walletContext.publicKey) == null ? void 0 : _a2.toBase58()) != null ? _b2 : null;
|
|
205
|
+
const enabled = Boolean(resolvedWallet) && ((_c = options == null ? void 0 : options.enabled) != null ? _c : true);
|
|
206
|
+
return (0, import_react_query.useQuery)(__spreadProps(__spreadValues({
|
|
207
|
+
queryKey: ["sync", "v2", "claims", resolvedWallet != null ? resolvedWallet : ""],
|
|
208
|
+
queryFn: () => listClaims(resolvedWallet || "", requestConfig)
|
|
209
|
+
}, options), {
|
|
210
|
+
enabled
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
function useClaimTransaction(options) {
|
|
235
214
|
const requestConfig = useSyncRequestConfig();
|
|
236
|
-
return (0, import_react_query.useQuery)(__spreadValues({
|
|
237
|
-
queryKey: ["sync", "v2", "claims", "history"],
|
|
238
|
-
queryFn: () => listClaimHistory(requestConfig)
|
|
239
|
-
}, options));
|
|
240
|
-
}
|
|
241
|
-
function useClaimTransaction(distributionId, options) {
|
|
242
|
-
const requestConfig = useSyncRequestConfig();
|
|
243
|
-
const id = distributionId || null;
|
|
244
|
-
return (0, import_react_query.useMutation)(__spreadValues({
|
|
245
|
-
mutationFn: async (input = {}) => {
|
|
246
|
-
if (!id) throw new SyncReactError(400, "distribution_id_required");
|
|
247
|
-
return buildClaimTransaction(__spreadProps(__spreadValues({}, input), { distributionId: id }), requestConfig);
|
|
248
|
-
}
|
|
249
|
-
}, options));
|
|
250
|
-
}
|
|
251
|
-
function useCommitClaim(distributionId, options) {
|
|
252
|
-
const requestConfig = useSyncRequestConfig();
|
|
253
|
-
const id = distributionId || null;
|
|
254
215
|
return (0, import_react_query.useMutation)(__spreadValues({
|
|
255
216
|
mutationFn: async (input) => {
|
|
256
|
-
if (!
|
|
257
|
-
if (!(input == null ? void 0 : input.
|
|
258
|
-
|
|
259
|
-
return commitClaim(__spreadProps(__spreadValues({}, input), { distributionId: id }), requestConfig);
|
|
217
|
+
if (!(input == null ? void 0 : input.distributionId)) throw new SyncReactError(400, "distribution_id_required");
|
|
218
|
+
if (!(input == null ? void 0 : input.claimant)) throw new SyncReactError(400, "claimant_required");
|
|
219
|
+
return buildClaimTransaction(input, requestConfig);
|
|
260
220
|
}
|
|
261
221
|
}, options));
|
|
262
222
|
}
|
|
263
|
-
function useClaimFlow(distributionId) {
|
|
264
|
-
var _a2, _b2;
|
|
265
|
-
const buildMutation = useClaimTransaction(distributionId);
|
|
266
|
-
const commitMutation = useCommitClaim(distributionId);
|
|
267
|
-
const [latestPayload, setLatestPayload] = (0, import_react.useState)(null);
|
|
268
|
-
const build = (0, import_react.useCallback)(
|
|
269
|
-
async (input) => {
|
|
270
|
-
const payload = await buildMutation.mutateAsync(input != null ? input : {});
|
|
271
|
-
setLatestPayload(payload);
|
|
272
|
-
return payload;
|
|
273
|
-
},
|
|
274
|
-
[buildMutation]
|
|
275
|
-
);
|
|
276
|
-
const claim = (0, import_react.useCallback)(
|
|
277
|
-
async (signer, input) => {
|
|
278
|
-
const payload = await build(input);
|
|
279
|
-
const signerInput = await signer(payload);
|
|
280
|
-
if (!(signerInput == null ? void 0 : signerInput.signedTransactionBase64)) {
|
|
281
|
-
throw new SyncReactError(400, "signed_transaction_required");
|
|
282
|
-
}
|
|
283
|
-
if (!(signerInput == null ? void 0 : signerInput.claimantPubkey)) {
|
|
284
|
-
throw new SyncReactError(400, "claimant_pubkey_required");
|
|
285
|
-
}
|
|
286
|
-
const commit = await commitMutation.mutateAsync(signerInput);
|
|
287
|
-
return { payload, commit, signerInput };
|
|
288
|
-
},
|
|
289
|
-
[build, commitMutation]
|
|
290
|
-
);
|
|
291
|
-
const reset = (0, import_react.useCallback)(() => {
|
|
292
|
-
setLatestPayload(null);
|
|
293
|
-
}, []);
|
|
294
|
-
const state = {
|
|
295
|
-
latestPayload,
|
|
296
|
-
building: buildMutation.isPending,
|
|
297
|
-
claiming: commitMutation.isPending,
|
|
298
|
-
error: (_b2 = (_a2 = buildMutation.error) != null ? _a2 : commitMutation.error) != null ? _b2 : null
|
|
299
|
-
};
|
|
300
|
-
return { state, build, claim, reset };
|
|
301
|
-
}
|
|
302
223
|
function useSyncRequestConfig() {
|
|
303
224
|
const context = (0, import_react.useContext)(SyncContext);
|
|
304
225
|
const basePath = sanitizeBasePath((context == null ? void 0 : context.basePath) || DEFAULT_BASE_PATH);
|
|
@@ -308,10 +229,7 @@ function useSyncRequestConfig() {
|
|
|
308
229
|
// Annotate the CommonJS export names for ESM import in node:
|
|
309
230
|
0 && (module.exports = {
|
|
310
231
|
SyncProvider,
|
|
311
|
-
useClaimFlow,
|
|
312
|
-
useClaimHistory,
|
|
313
232
|
useClaimTransaction,
|
|
314
|
-
|
|
315
|
-
useCommitClaim,
|
|
233
|
+
useClaims,
|
|
316
234
|
useSyncClient
|
|
317
235
|
});
|