@fractalshq/sync 0.0.3 → 0.0.4
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/dist/react/index.d.mts +20 -1
- package/dist/react/index.d.ts +20 -1
- package/dist/react/index.js +38 -0
- package/dist/react/index.mjs +38 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -36,5 +36,24 @@ type ClaimTransactionInput = Partial<Omit<BuildClaimTransactionRequest, "distrib
|
|
|
36
36
|
declare function useClaimTransaction(distributionId: string | null | undefined, options?: UseMutationOptions<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>): UseMutationResult<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>;
|
|
37
37
|
type ClaimCommitInput = Omit<CommitClaimRequest, "distributionId">;
|
|
38
38
|
declare function useCommitClaim(distributionId: string | null | undefined, options?: UseMutationOptions<CommitClaimResponse, SyncReactError, ClaimCommitInput>): UseMutationResult<CommitClaimResponse, SyncReactError, ClaimCommitInput>;
|
|
39
|
+
interface ClaimFlowState {
|
|
40
|
+
latestPayload: BuildClaimTransactionResponse | null;
|
|
41
|
+
building: boolean;
|
|
42
|
+
claiming: boolean;
|
|
43
|
+
error: SyncReactError | null;
|
|
44
|
+
}
|
|
45
|
+
type ClaimFlowSigner = (payload: BuildClaimTransactionResponse) => Promise<ClaimCommitInput> | ClaimCommitInput;
|
|
46
|
+
interface ClaimFlowClaimResult {
|
|
47
|
+
payload: BuildClaimTransactionResponse;
|
|
48
|
+
commit: CommitClaimResponse;
|
|
49
|
+
signerInput: ClaimCommitInput;
|
|
50
|
+
}
|
|
51
|
+
interface ClaimFlowResult {
|
|
52
|
+
state: ClaimFlowState;
|
|
53
|
+
build: (input?: ClaimTransactionInput) => Promise<BuildClaimTransactionResponse>;
|
|
54
|
+
claim: (signer: ClaimFlowSigner, input?: ClaimTransactionInput) => Promise<ClaimFlowClaimResult>;
|
|
55
|
+
reset: () => void;
|
|
56
|
+
}
|
|
57
|
+
declare function useClaimFlow(distributionId: string | null | undefined): ClaimFlowResult;
|
|
39
58
|
|
|
40
|
-
export { type ClaimCommitInput, type ClaimTransactionInput, type SyncClient, SyncProvider, type SyncProviderProps, SyncReactError, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useDistribution, useDistributions, useSyncClient };
|
|
59
|
+
export { type ClaimCommitInput, type ClaimFlowClaimResult, type ClaimFlowResult, type ClaimFlowSigner, type ClaimFlowState, type ClaimTransactionInput, type SyncClient, SyncProvider, type SyncProviderProps, SyncReactError, useClaimFlow, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useDistribution, useDistributions, useSyncClient };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -36,5 +36,24 @@ type ClaimTransactionInput = Partial<Omit<BuildClaimTransactionRequest, "distrib
|
|
|
36
36
|
declare function useClaimTransaction(distributionId: string | null | undefined, options?: UseMutationOptions<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>): UseMutationResult<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>;
|
|
37
37
|
type ClaimCommitInput = Omit<CommitClaimRequest, "distributionId">;
|
|
38
38
|
declare function useCommitClaim(distributionId: string | null | undefined, options?: UseMutationOptions<CommitClaimResponse, SyncReactError, ClaimCommitInput>): UseMutationResult<CommitClaimResponse, SyncReactError, ClaimCommitInput>;
|
|
39
|
+
interface ClaimFlowState {
|
|
40
|
+
latestPayload: BuildClaimTransactionResponse | null;
|
|
41
|
+
building: boolean;
|
|
42
|
+
claiming: boolean;
|
|
43
|
+
error: SyncReactError | null;
|
|
44
|
+
}
|
|
45
|
+
type ClaimFlowSigner = (payload: BuildClaimTransactionResponse) => Promise<ClaimCommitInput> | ClaimCommitInput;
|
|
46
|
+
interface ClaimFlowClaimResult {
|
|
47
|
+
payload: BuildClaimTransactionResponse;
|
|
48
|
+
commit: CommitClaimResponse;
|
|
49
|
+
signerInput: ClaimCommitInput;
|
|
50
|
+
}
|
|
51
|
+
interface ClaimFlowResult {
|
|
52
|
+
state: ClaimFlowState;
|
|
53
|
+
build: (input?: ClaimTransactionInput) => Promise<BuildClaimTransactionResponse>;
|
|
54
|
+
claim: (signer: ClaimFlowSigner, input?: ClaimTransactionInput) => Promise<ClaimFlowClaimResult>;
|
|
55
|
+
reset: () => void;
|
|
56
|
+
}
|
|
57
|
+
declare function useClaimFlow(distributionId: string | null | undefined): ClaimFlowResult;
|
|
39
58
|
|
|
40
|
-
export { type ClaimCommitInput, type ClaimTransactionInput, type SyncClient, SyncProvider, type SyncProviderProps, SyncReactError, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useDistribution, useDistributions, useSyncClient };
|
|
59
|
+
export { type ClaimCommitInput, type ClaimFlowClaimResult, type ClaimFlowResult, type ClaimFlowSigner, type ClaimFlowState, type ClaimTransactionInput, type SyncClient, SyncProvider, type SyncProviderProps, SyncReactError, useClaimFlow, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useDistribution, useDistributions, useSyncClient };
|
package/dist/react/index.js
CHANGED
|
@@ -39,6 +39,7 @@ var react_exports = {};
|
|
|
39
39
|
__export(react_exports, {
|
|
40
40
|
SyncProvider: () => SyncProvider,
|
|
41
41
|
SyncReactError: () => SyncReactError,
|
|
42
|
+
useClaimFlow: () => useClaimFlow,
|
|
42
43
|
useClaimHistory: () => useClaimHistory,
|
|
43
44
|
useClaimTransaction: () => useClaimTransaction,
|
|
44
45
|
useClaimableDistributions: () => useClaimableDistributions,
|
|
@@ -149,6 +150,42 @@ function useCommitClaim(distributionId, options) {
|
|
|
149
150
|
}
|
|
150
151
|
}, options));
|
|
151
152
|
}
|
|
153
|
+
function useClaimFlow(distributionId) {
|
|
154
|
+
var _a2, _b2;
|
|
155
|
+
const buildMutation = useClaimTransaction(distributionId);
|
|
156
|
+
const commitMutation = useCommitClaim(distributionId);
|
|
157
|
+
const [latestPayload, setLatestPayload] = (0, import_react.useState)(null);
|
|
158
|
+
const build = (0, import_react.useCallback)(
|
|
159
|
+
async (input) => {
|
|
160
|
+
const payload = await buildMutation.mutateAsync(input != null ? input : {});
|
|
161
|
+
setLatestPayload(payload);
|
|
162
|
+
return payload;
|
|
163
|
+
},
|
|
164
|
+
[buildMutation]
|
|
165
|
+
);
|
|
166
|
+
const claim = (0, import_react.useCallback)(
|
|
167
|
+
async (signer, input) => {
|
|
168
|
+
const payload = await build(input);
|
|
169
|
+
const signerInput = await signer(payload);
|
|
170
|
+
if (!signerInput || !signerInput.signature && !signerInput.transaction && !signerInput.signedTransactionBase64) {
|
|
171
|
+
throw new SyncReactError(400, "claim_signature_required");
|
|
172
|
+
}
|
|
173
|
+
const commit = await commitMutation.mutateAsync(signerInput);
|
|
174
|
+
return { payload, commit, signerInput };
|
|
175
|
+
},
|
|
176
|
+
[build, commitMutation]
|
|
177
|
+
);
|
|
178
|
+
const reset = (0, import_react.useCallback)(() => {
|
|
179
|
+
setLatestPayload(null);
|
|
180
|
+
}, []);
|
|
181
|
+
const state = {
|
|
182
|
+
latestPayload,
|
|
183
|
+
building: buildMutation.isPending,
|
|
184
|
+
claiming: commitMutation.isPending,
|
|
185
|
+
error: (_b2 = (_a2 = buildMutation.error) != null ? _a2 : commitMutation.error) != null ? _b2 : null
|
|
186
|
+
};
|
|
187
|
+
return { state, build, claim, reset };
|
|
188
|
+
}
|
|
152
189
|
async function requestJSON(config, path, init) {
|
|
153
190
|
var _a2;
|
|
154
191
|
const url = buildUrl(config.basePath, path);
|
|
@@ -217,6 +254,7 @@ function isRelativeUrl(path) {
|
|
|
217
254
|
0 && (module.exports = {
|
|
218
255
|
SyncProvider,
|
|
219
256
|
SyncReactError,
|
|
257
|
+
useClaimFlow,
|
|
220
258
|
useClaimHistory,
|
|
221
259
|
useClaimTransaction,
|
|
222
260
|
useClaimableDistributions,
|
package/dist/react/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "../chunk-I4E63NIC.mjs";
|
|
5
5
|
|
|
6
6
|
// src/react/index.tsx
|
|
7
|
-
import { createContext, createElement, useContext, useMemo } from "react";
|
|
7
|
+
import { createContext, createElement, useCallback, useContext, useMemo, useState } from "react";
|
|
8
8
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
9
9
|
var FALLBACK_BASE_PATH = "/api/v1/fractals-sync";
|
|
10
10
|
var _a, _b;
|
|
@@ -105,6 +105,42 @@ function useCommitClaim(distributionId, options) {
|
|
|
105
105
|
}
|
|
106
106
|
}, options));
|
|
107
107
|
}
|
|
108
|
+
function useClaimFlow(distributionId) {
|
|
109
|
+
var _a2, _b2;
|
|
110
|
+
const buildMutation = useClaimTransaction(distributionId);
|
|
111
|
+
const commitMutation = useCommitClaim(distributionId);
|
|
112
|
+
const [latestPayload, setLatestPayload] = useState(null);
|
|
113
|
+
const build = useCallback(
|
|
114
|
+
async (input) => {
|
|
115
|
+
const payload = await buildMutation.mutateAsync(input != null ? input : {});
|
|
116
|
+
setLatestPayload(payload);
|
|
117
|
+
return payload;
|
|
118
|
+
},
|
|
119
|
+
[buildMutation]
|
|
120
|
+
);
|
|
121
|
+
const claim = useCallback(
|
|
122
|
+
async (signer, input) => {
|
|
123
|
+
const payload = await build(input);
|
|
124
|
+
const signerInput = await signer(payload);
|
|
125
|
+
if (!signerInput || !signerInput.signature && !signerInput.transaction && !signerInput.signedTransactionBase64) {
|
|
126
|
+
throw new SyncReactError(400, "claim_signature_required");
|
|
127
|
+
}
|
|
128
|
+
const commit = await commitMutation.mutateAsync(signerInput);
|
|
129
|
+
return { payload, commit, signerInput };
|
|
130
|
+
},
|
|
131
|
+
[build, commitMutation]
|
|
132
|
+
);
|
|
133
|
+
const reset = useCallback(() => {
|
|
134
|
+
setLatestPayload(null);
|
|
135
|
+
}, []);
|
|
136
|
+
const state = {
|
|
137
|
+
latestPayload,
|
|
138
|
+
building: buildMutation.isPending,
|
|
139
|
+
claiming: commitMutation.isPending,
|
|
140
|
+
error: (_b2 = (_a2 = buildMutation.error) != null ? _a2 : commitMutation.error) != null ? _b2 : null
|
|
141
|
+
};
|
|
142
|
+
return { state, build, claim, reset };
|
|
143
|
+
}
|
|
108
144
|
async function requestJSON(config, path, init) {
|
|
109
145
|
var _a2;
|
|
110
146
|
const url = buildUrl(config.basePath, path);
|
|
@@ -172,6 +208,7 @@ function isRelativeUrl(path) {
|
|
|
172
208
|
export {
|
|
173
209
|
SyncProvider,
|
|
174
210
|
SyncReactError,
|
|
211
|
+
useClaimFlow,
|
|
175
212
|
useClaimHistory,
|
|
176
213
|
useClaimTransaction,
|
|
177
214
|
useClaimableDistributions,
|