@fractalshq/sync 0.0.6 → 0.0.7
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/LICENSE +24 -0
- package/dist/index.mjs +7 -7
- package/dist/react/index.d.mts +29 -1
- package/dist/react/index.d.ts +29 -1
- package/dist/react/index.js +61 -0
- package/dist/react/index.mjs +60 -0
- package/package.json +3 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Fractals
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
GET,
|
|
3
|
-
POST,
|
|
4
|
-
SyncServerClient,
|
|
5
|
-
createMethodHandler,
|
|
6
|
-
syncRouteHandler
|
|
7
|
-
} from "./chunk-JZGD7RD2.mjs";
|
|
8
1
|
import {
|
|
9
2
|
DEFAULT_BASE_PATH,
|
|
10
3
|
DEFAULT_RPC_ENDPOINT,
|
|
@@ -30,6 +23,13 @@ import {
|
|
|
30
23
|
resolveRequestConfig,
|
|
31
24
|
sanitizeBasePath
|
|
32
25
|
} from "./chunk-VXNOPXKB.mjs";
|
|
26
|
+
import {
|
|
27
|
+
GET,
|
|
28
|
+
POST,
|
|
29
|
+
SyncServerClient,
|
|
30
|
+
createMethodHandler,
|
|
31
|
+
syncRouteHandler
|
|
32
|
+
} from "./chunk-JZGD7RD2.mjs";
|
|
33
33
|
import "./chunk-FWCSY2DS.mjs";
|
|
34
34
|
export {
|
|
35
35
|
DEFAULT_BASE_PATH,
|
package/dist/react/index.d.mts
CHANGED
|
@@ -79,5 +79,33 @@ interface ClaimFlowResult {
|
|
|
79
79
|
reset: () => void;
|
|
80
80
|
}
|
|
81
81
|
declare function useClaimFlow(distributionId: string | null | undefined): ClaimFlowResult;
|
|
82
|
+
interface RecipientComposerRow {
|
|
83
|
+
id: string;
|
|
84
|
+
address: string;
|
|
85
|
+
amount: string;
|
|
86
|
+
}
|
|
87
|
+
type RecipientRow = RecipientComposerRow;
|
|
88
|
+
interface RecipientComposerState {
|
|
89
|
+
rows: RecipientComposerRow[];
|
|
90
|
+
totals: {
|
|
91
|
+
count: number;
|
|
92
|
+
totalAmount: number;
|
|
93
|
+
normalized: Array<{
|
|
94
|
+
id: string;
|
|
95
|
+
address: string;
|
|
96
|
+
amount: number;
|
|
97
|
+
shareBps: number;
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
interface RecipientComposerApi {
|
|
102
|
+
state: RecipientComposerState;
|
|
103
|
+
addRow: () => void;
|
|
104
|
+
removeRow: (id: string) => void;
|
|
105
|
+
updateRow: (id: string, patch: Partial<Omit<RecipientComposerRow, "id">>) => void;
|
|
106
|
+
replaceRows: (rows: Array<Pick<RecipientComposerRow, "address" | "amount">>) => void;
|
|
107
|
+
clearRows: () => void;
|
|
108
|
+
}
|
|
109
|
+
declare function useRecipientComposer(initial?: Array<Pick<RecipientComposerRow, "address" | "amount">>): RecipientComposerApi;
|
|
82
110
|
|
|
83
|
-
export { type ClaimCommitInput, type ClaimFlowClaimResult, type ClaimFlowResult, type ClaimFlowSigner, type ClaimFlowState, type ClaimTransactionInput, type DistributionCommitInput, type DistributionFlowCommitResult, type DistributionFlowResult, type DistributionFlowSigner, type DistributionFlowSignerInput, type DistributionFlowState, type DistributionTransactionInput, type DistributionsQueryParams, type SyncClient, SyncProvider, type SyncProviderProps, useClaimFlow, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useCommitDistribution, useDistribution, useDistributionFlow, useDistributionTransaction, useDistributions, useSyncClient };
|
|
111
|
+
export { type ClaimCommitInput, type ClaimFlowClaimResult, type ClaimFlowResult, type ClaimFlowSigner, type ClaimFlowState, type ClaimTransactionInput, type DistributionCommitInput, type DistributionFlowCommitResult, type DistributionFlowResult, type DistributionFlowSigner, type DistributionFlowSignerInput, type DistributionFlowState, type DistributionTransactionInput, type DistributionsQueryParams, type RecipientComposerApi, type RecipientComposerRow, type RecipientComposerState, type RecipientRow, type SyncClient, SyncProvider, type SyncProviderProps, useClaimFlow, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useCommitDistribution, useDistribution, useDistributionFlow, useDistributionTransaction, useDistributions, useRecipientComposer, useSyncClient };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -79,5 +79,33 @@ interface ClaimFlowResult {
|
|
|
79
79
|
reset: () => void;
|
|
80
80
|
}
|
|
81
81
|
declare function useClaimFlow(distributionId: string | null | undefined): ClaimFlowResult;
|
|
82
|
+
interface RecipientComposerRow {
|
|
83
|
+
id: string;
|
|
84
|
+
address: string;
|
|
85
|
+
amount: string;
|
|
86
|
+
}
|
|
87
|
+
type RecipientRow = RecipientComposerRow;
|
|
88
|
+
interface RecipientComposerState {
|
|
89
|
+
rows: RecipientComposerRow[];
|
|
90
|
+
totals: {
|
|
91
|
+
count: number;
|
|
92
|
+
totalAmount: number;
|
|
93
|
+
normalized: Array<{
|
|
94
|
+
id: string;
|
|
95
|
+
address: string;
|
|
96
|
+
amount: number;
|
|
97
|
+
shareBps: number;
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
interface RecipientComposerApi {
|
|
102
|
+
state: RecipientComposerState;
|
|
103
|
+
addRow: () => void;
|
|
104
|
+
removeRow: (id: string) => void;
|
|
105
|
+
updateRow: (id: string, patch: Partial<Omit<RecipientComposerRow, "id">>) => void;
|
|
106
|
+
replaceRows: (rows: Array<Pick<RecipientComposerRow, "address" | "amount">>) => void;
|
|
107
|
+
clearRows: () => void;
|
|
108
|
+
}
|
|
109
|
+
declare function useRecipientComposer(initial?: Array<Pick<RecipientComposerRow, "address" | "amount">>): RecipientComposerApi;
|
|
82
110
|
|
|
83
|
-
export { type ClaimCommitInput, type ClaimFlowClaimResult, type ClaimFlowResult, type ClaimFlowSigner, type ClaimFlowState, type ClaimTransactionInput, type DistributionCommitInput, type DistributionFlowCommitResult, type DistributionFlowResult, type DistributionFlowSigner, type DistributionFlowSignerInput, type DistributionFlowState, type DistributionTransactionInput, type DistributionsQueryParams, type SyncClient, SyncProvider, type SyncProviderProps, useClaimFlow, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useCommitDistribution, useDistribution, useDistributionFlow, useDistributionTransaction, useDistributions, useSyncClient };
|
|
111
|
+
export { type ClaimCommitInput, type ClaimFlowClaimResult, type ClaimFlowResult, type ClaimFlowSigner, type ClaimFlowState, type ClaimTransactionInput, type DistributionCommitInput, type DistributionFlowCommitResult, type DistributionFlowResult, type DistributionFlowSigner, type DistributionFlowSignerInput, type DistributionFlowState, type DistributionTransactionInput, type DistributionsQueryParams, type RecipientComposerApi, type RecipientComposerRow, type RecipientComposerState, type RecipientRow, type SyncClient, SyncProvider, type SyncProviderProps, useClaimFlow, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useCommitDistribution, useDistribution, useDistributionFlow, useDistributionTransaction, useDistributions, useRecipientComposer, useSyncClient };
|
package/dist/react/index.js
CHANGED
|
@@ -60,6 +60,7 @@ __export(react_exports, {
|
|
|
60
60
|
useDistributionFlow: () => useDistributionFlow,
|
|
61
61
|
useDistributionTransaction: () => useDistributionTransaction,
|
|
62
62
|
useDistributions: () => useDistributions,
|
|
63
|
+
useRecipientComposer: () => useRecipientComposer,
|
|
63
64
|
useSyncClient: () => useSyncClient
|
|
64
65
|
});
|
|
65
66
|
module.exports = __toCommonJS(react_exports);
|
|
@@ -472,6 +473,65 @@ function buildDistributionsPath(params) {
|
|
|
472
473
|
const qs = search.toString();
|
|
473
474
|
return qs ? `/distributions/me?${qs}` : "/distributions/me";
|
|
474
475
|
}
|
|
476
|
+
function createRecipientRowId() {
|
|
477
|
+
return `recipient-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
478
|
+
}
|
|
479
|
+
function hydrateRecipientRow(partial) {
|
|
480
|
+
var _a2, _b2;
|
|
481
|
+
return {
|
|
482
|
+
id: createRecipientRowId(),
|
|
483
|
+
address: (_a2 = partial == null ? void 0 : partial.address) != null ? _a2 : "",
|
|
484
|
+
amount: (_b2 = partial == null ? void 0 : partial.amount) != null ? _b2 : ""
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function useRecipientComposer(initial = []) {
|
|
488
|
+
const [rows, setRows] = (0, import_react.useState)(() => {
|
|
489
|
+
if (initial.length === 0) return [hydrateRecipientRow()];
|
|
490
|
+
return initial.map((row) => hydrateRecipientRow(row));
|
|
491
|
+
});
|
|
492
|
+
const addRow = (0, import_react.useCallback)(() => {
|
|
493
|
+
setRows((current) => [...current, hydrateRecipientRow()]);
|
|
494
|
+
}, []);
|
|
495
|
+
const removeRow = (0, import_react.useCallback)((id) => {
|
|
496
|
+
setRows((current) => {
|
|
497
|
+
if (current.length <= 1) return [hydrateRecipientRow()];
|
|
498
|
+
return current.filter((row) => row.id !== id);
|
|
499
|
+
});
|
|
500
|
+
}, []);
|
|
501
|
+
const updateRow = (0, import_react.useCallback)((id, patch) => {
|
|
502
|
+
setRows((current) => current.map((row) => row.id === id ? __spreadValues(__spreadValues({}, row), patch) : row));
|
|
503
|
+
}, []);
|
|
504
|
+
const replaceRows = (0, import_react.useCallback)((incoming) => {
|
|
505
|
+
if (!incoming.length) {
|
|
506
|
+
setRows([hydrateRecipientRow()]);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
setRows(incoming.map((row) => hydrateRecipientRow(row)));
|
|
510
|
+
}, []);
|
|
511
|
+
const clearRows = (0, import_react.useCallback)(() => {
|
|
512
|
+
setRows([hydrateRecipientRow()]);
|
|
513
|
+
}, []);
|
|
514
|
+
const totals = (0, import_react.useMemo)(() => {
|
|
515
|
+
const normalized = rows.map((row) => ({ id: row.id, address: row.address.trim(), amount: Number(row.amount) || 0 }));
|
|
516
|
+
const totalAmount = normalized.reduce((sum, row) => sum + Math.max(0, row.amount), 0);
|
|
517
|
+
const withShare = normalized.map((row) => __spreadProps(__spreadValues({}, row), {
|
|
518
|
+
shareBps: totalAmount > 0 ? Math.round(Math.max(0, row.amount) / totalAmount * 1e4) : 0
|
|
519
|
+
}));
|
|
520
|
+
return {
|
|
521
|
+
count: rows.length,
|
|
522
|
+
totalAmount,
|
|
523
|
+
normalized: withShare
|
|
524
|
+
};
|
|
525
|
+
}, [rows]);
|
|
526
|
+
return {
|
|
527
|
+
state: { rows, totals },
|
|
528
|
+
addRow,
|
|
529
|
+
removeRow,
|
|
530
|
+
updateRow,
|
|
531
|
+
replaceRows,
|
|
532
|
+
clearRows
|
|
533
|
+
};
|
|
534
|
+
}
|
|
475
535
|
// Annotate the CommonJS export names for ESM import in node:
|
|
476
536
|
0 && (module.exports = {
|
|
477
537
|
SyncProvider,
|
|
@@ -485,5 +545,6 @@ function buildDistributionsPath(params) {
|
|
|
485
545
|
useDistributionFlow,
|
|
486
546
|
useDistributionTransaction,
|
|
487
547
|
useDistributions,
|
|
548
|
+
useRecipientComposer,
|
|
488
549
|
useSyncClient
|
|
489
550
|
});
|
package/dist/react/index.mjs
CHANGED
|
@@ -252,6 +252,65 @@ function buildDistributionsPath(params) {
|
|
|
252
252
|
const qs = search.toString();
|
|
253
253
|
return qs ? `/distributions/me?${qs}` : "/distributions/me";
|
|
254
254
|
}
|
|
255
|
+
function createRecipientRowId() {
|
|
256
|
+
return `recipient-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
257
|
+
}
|
|
258
|
+
function hydrateRecipientRow(partial) {
|
|
259
|
+
var _a, _b;
|
|
260
|
+
return {
|
|
261
|
+
id: createRecipientRowId(),
|
|
262
|
+
address: (_a = partial == null ? void 0 : partial.address) != null ? _a : "",
|
|
263
|
+
amount: (_b = partial == null ? void 0 : partial.amount) != null ? _b : ""
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function useRecipientComposer(initial = []) {
|
|
267
|
+
const [rows, setRows] = useState(() => {
|
|
268
|
+
if (initial.length === 0) return [hydrateRecipientRow()];
|
|
269
|
+
return initial.map((row) => hydrateRecipientRow(row));
|
|
270
|
+
});
|
|
271
|
+
const addRow = useCallback(() => {
|
|
272
|
+
setRows((current) => [...current, hydrateRecipientRow()]);
|
|
273
|
+
}, []);
|
|
274
|
+
const removeRow = useCallback((id) => {
|
|
275
|
+
setRows((current) => {
|
|
276
|
+
if (current.length <= 1) return [hydrateRecipientRow()];
|
|
277
|
+
return current.filter((row) => row.id !== id);
|
|
278
|
+
});
|
|
279
|
+
}, []);
|
|
280
|
+
const updateRow = useCallback((id, patch) => {
|
|
281
|
+
setRows((current) => current.map((row) => row.id === id ? __spreadValues(__spreadValues({}, row), patch) : row));
|
|
282
|
+
}, []);
|
|
283
|
+
const replaceRows = useCallback((incoming) => {
|
|
284
|
+
if (!incoming.length) {
|
|
285
|
+
setRows([hydrateRecipientRow()]);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
setRows(incoming.map((row) => hydrateRecipientRow(row)));
|
|
289
|
+
}, []);
|
|
290
|
+
const clearRows = useCallback(() => {
|
|
291
|
+
setRows([hydrateRecipientRow()]);
|
|
292
|
+
}, []);
|
|
293
|
+
const totals = useMemo(() => {
|
|
294
|
+
const normalized = rows.map((row) => ({ id: row.id, address: row.address.trim(), amount: Number(row.amount) || 0 }));
|
|
295
|
+
const totalAmount = normalized.reduce((sum, row) => sum + Math.max(0, row.amount), 0);
|
|
296
|
+
const withShare = normalized.map((row) => __spreadProps(__spreadValues({}, row), {
|
|
297
|
+
shareBps: totalAmount > 0 ? Math.round(Math.max(0, row.amount) / totalAmount * 1e4) : 0
|
|
298
|
+
}));
|
|
299
|
+
return {
|
|
300
|
+
count: rows.length,
|
|
301
|
+
totalAmount,
|
|
302
|
+
normalized: withShare
|
|
303
|
+
};
|
|
304
|
+
}, [rows]);
|
|
305
|
+
return {
|
|
306
|
+
state: { rows, totals },
|
|
307
|
+
addRow,
|
|
308
|
+
removeRow,
|
|
309
|
+
updateRow,
|
|
310
|
+
replaceRows,
|
|
311
|
+
clearRows
|
|
312
|
+
};
|
|
313
|
+
}
|
|
255
314
|
export {
|
|
256
315
|
SyncProvider,
|
|
257
316
|
useClaimFlow,
|
|
@@ -264,5 +323,6 @@ export {
|
|
|
264
323
|
useDistributionFlow,
|
|
265
324
|
useDistributionTransaction,
|
|
266
325
|
useDistributions,
|
|
326
|
+
useRecipientComposer,
|
|
267
327
|
useSyncClient
|
|
268
328
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fractalshq/sync",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Fractals Sync SDK: shared types, server client, React hooks, and widgets",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"sdk",
|
|
52
52
|
"fractals"
|
|
53
53
|
],
|
|
54
|
-
"author": "Fractals <
|
|
55
|
-
"license": "
|
|
54
|
+
"author": "Fractals <max@fractals.fun>",
|
|
55
|
+
"license": "MIT",
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@fractalshq/auth-core": "^0.1.9",
|
|
58
58
|
"@fractalshq/jito-distributor-sdk": "^1.0.7",
|