@shelby-protocol/react 0.0.4 → 0.0.5
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/CHANGELOG.md +8 -0
- package/dist/components/ShelbyClientProvider.d.ts +8 -0
- package/dist/components/ShelbyClientProvider.d.ts.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mutations/index.d.ts +2 -0
- package/dist/mutations/index.d.ts.map +1 -1
- package/dist/mutations/useCommitBlobs.d.ts +1 -1
- package/dist/mutations/useCommitBlobs.d.ts.map +1 -1
- package/dist/mutations/useDeleteBlob.d.ts +60 -0
- package/dist/mutations/useDeleteBlob.d.ts.map +1 -0
- package/dist/mutations/useDeleteBlobs.d.ts +77 -0
- package/dist/mutations/useDeleteBlobs.d.ts.map +1 -0
- package/dist/mutations/useEncodeBlobs.d.ts +11 -8
- package/dist/mutations/useEncodeBlobs.d.ts.map +1 -1
- package/dist/mutations/useRegisterCommitments.d.ts +1 -1
- package/dist/mutations/useRegisterCommitments.d.ts.map +1 -1
- package/dist/mutations/useUploadBlobs.d.ts +1 -1
- package/dist/mutations/useUploadBlobs.d.ts.map +1 -1
- package/dist/queries/useAccountBlobs.d.ts +1 -1
- package/dist/queries/useAccountBlobs.d.ts.map +1 -1
- package/dist/queries/useBlobMetadata.d.ts +1 -1
- package/dist/queries/useBlobMetadata.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/mutations.d.ts +4 -3
- package/dist/types/mutations.d.ts.map +1 -1
- package/dist/types/queries.d.ts +1 -1
- package/dist/types/queries.d.ts.map +1 -1
- package/dist/types/signers.d.ts +21 -1
- package/dist/types/signers.d.ts.map +1 -1
- package/package.json +6 -2
- package/src/components/ShelbyClientProvider.tsx +26 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/mutations/index.ts +2 -0
- package/src/mutations/useCommitBlobs.tsx +3 -4
- package/src/mutations/useDeleteBlob.tsx +93 -0
- package/src/mutations/useDeleteBlobs.tsx +139 -0
- package/src/mutations/useEncodeBlobs.tsx +11 -11
- package/src/mutations/useRegisterCommitments.tsx +17 -3
- package/src/mutations/useUploadBlobs.tsx +25 -9
- package/src/queries/useAccountBlobs.tsx +3 -1
- package/src/queries/useBlobMetadata.tsx +3 -1
- package/src/types/index.ts +1 -0
- package/src/types/mutations.ts +13 -4
- package/src/types/queries.ts +1 -1
- package/src/types/signers.ts +19 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { InputGenerateTransactionOptions } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import type { UseMutationOptionsWithClient } from "../types/mutations";
|
|
3
|
+
import type { Signer } from "../types/signers";
|
|
4
|
+
export type UseDeleteBlobsVariables = {
|
|
5
|
+
/**
|
|
6
|
+
* The signer to use for the transaction.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link Signer}
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const signer = new Account.generate();
|
|
13
|
+
* deleteBlobs.mutate({
|
|
14
|
+
* signer,
|
|
15
|
+
* blobNames: ["folder/file1.txt", "folder/file2.txt"],
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
signer: Signer;
|
|
20
|
+
/**
|
|
21
|
+
* The names/paths of the blobs to delete, without the account address prefix
|
|
22
|
+
* (e.g. ["folder/file1.txt", "folder/file2.txt"], NOT ["0x1/folder/file1.txt"]).
|
|
23
|
+
* The account address prefix is automatically derived from the signer.
|
|
24
|
+
*/
|
|
25
|
+
blobNames: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Optional transaction building options.
|
|
28
|
+
*/
|
|
29
|
+
options?: InputGenerateTransactionOptions;
|
|
30
|
+
};
|
|
31
|
+
export type UseDeleteBlobsOptions = UseMutationOptionsWithClient<{
|
|
32
|
+
hash: string;
|
|
33
|
+
}, Error, UseDeleteBlobsVariables>;
|
|
34
|
+
/**
|
|
35
|
+
* Deletes one or more blobs on-chain.
|
|
36
|
+
*
|
|
37
|
+
* This hook automatically optimizes gas costs by using `delete_blob` for single
|
|
38
|
+
* blob deletion and `delete_multiple_blobs` for multiple blobs.
|
|
39
|
+
*
|
|
40
|
+
* **Note:** Deleting multiple blobs (more than one) requires the `delete_multiple_blobs`
|
|
41
|
+
* entry function which will be deployed to the smart contract on 2026-02-04.
|
|
42
|
+
* Using this hook with multiple blobs before that date will result in a transaction failure.
|
|
43
|
+
* Single blob deletion works immediately.
|
|
44
|
+
*
|
|
45
|
+
* This mutation deletes blob metadata from the Shelby contract. It supports
|
|
46
|
+
* both account signers and wallet adapter signers.
|
|
47
|
+
*
|
|
48
|
+
* When deleting multiple blobs, the operation is atomic: if any blob deletion
|
|
49
|
+
* fails (e.g., blob not found), the entire transaction fails and no blobs are deleted.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* import { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
54
|
+
* import { Network } from "@aptos-labs/ts-sdk";
|
|
55
|
+
* import { useDeleteBlobs } from "@shelby-protocol/react";
|
|
56
|
+
*
|
|
57
|
+
* const shelbyClient = new ShelbyClient({ network: Network.SHELBYNET });
|
|
58
|
+
* const deleteBlobs = useDeleteBlobs({
|
|
59
|
+
* client: shelbyClient,
|
|
60
|
+
* onSuccess: ({ hash }) => console.log("Delete tx:", hash),
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Delete a single blob
|
|
64
|
+
* deleteBlobs.mutate({
|
|
65
|
+
* signer,
|
|
66
|
+
* blobNames: ["folder/file.txt"],
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Delete multiple blobs in one transaction
|
|
70
|
+
* deleteBlobs.mutate({
|
|
71
|
+
* signer,
|
|
72
|
+
* blobNames: ["folder/file1.txt", "folder/file2.txt"],
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function useDeleteBlobs({ client, ...options }: UseDeleteBlobsOptions): import("@tanstack/react-query").UseMutationResult<import("@aptos-labs/wallet-adapter-react").AptosSignAndSubmitTransactionOutput, Error, UseDeleteBlobsVariables, readonly unknown[]>;
|
|
77
|
+
//# sourceMappingURL=useDeleteBlobs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDeleteBlobs.d.ts","sourceRoot":"","sources":["../../src/mutations/useDeleteBlobs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAI1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;;;;;;;;;OAaG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,+BAA+B,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,4BAA4B,CAC9D;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAChB,KAAK,EACL,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,qBAAqB,yLAuD3E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BlobCommitments, type ErasureCodingProvider } from "@shelby-protocol/sdk/browser";
|
|
2
|
-
import type {
|
|
2
|
+
import type { UseMutationOptions } from "../types/mutations";
|
|
3
3
|
export type UseEncodeBlobsOnChunkEvent = {
|
|
4
4
|
/**
|
|
5
5
|
* The index of the blob being encoded.
|
|
@@ -18,7 +18,14 @@ export type UseEncodeBlobsOnChunkEvent = {
|
|
|
18
18
|
*/
|
|
19
19
|
chunkData: Uint8Array;
|
|
20
20
|
/**
|
|
21
|
-
* The progress of the encoding.
|
|
21
|
+
* The progress of the encoding in percentage.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* onChunk: ({ progress }) => {
|
|
26
|
+
* console.log(`Encoding progress: ${progress * 100}%`);
|
|
27
|
+
* },
|
|
28
|
+
* ```
|
|
22
29
|
*/
|
|
23
30
|
progress: number;
|
|
24
31
|
};
|
|
@@ -38,7 +45,7 @@ export type UseEncodeBlobsVariables = {
|
|
|
38
45
|
*/
|
|
39
46
|
onChunk?: (event: UseEncodeBlobsOnChunkEvent) => void;
|
|
40
47
|
};
|
|
41
|
-
export type UseEncodeBlobsOptions =
|
|
48
|
+
export type UseEncodeBlobsOptions = UseMutationOptions<BlobCommitments[], Error, UseEncodeBlobsVariables>;
|
|
42
49
|
/**
|
|
43
50
|
* Encodes blobs using erasure coding.
|
|
44
51
|
*
|
|
@@ -48,13 +55,9 @@ export type UseEncodeBlobsOptions = UseMutationOptionsWithClient<BlobCommitments
|
|
|
48
55
|
*
|
|
49
56
|
* @example
|
|
50
57
|
* ```tsx
|
|
51
|
-
* import { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
52
|
-
* import { Network } from "@aptos-labs/ts-sdk";
|
|
53
58
|
* import { useEncodeBlobs } from "@shelby-protocol/react";
|
|
54
59
|
*
|
|
55
|
-
* const shelbyClient = new ShelbyClient({ network: Network.SHELBYNET });
|
|
56
60
|
* const encodeBlobs = useEncodeBlobs({
|
|
57
|
-
* client: shelbyClient,
|
|
58
61
|
* onSuccess: (commitments) => console.log('Encoded', commitments.length, 'blobs'),
|
|
59
62
|
* });
|
|
60
63
|
*
|
|
@@ -66,7 +69,7 @@ export type UseEncodeBlobsOptions = UseMutationOptionsWithClient<BlobCommitments
|
|
|
66
69
|
* });
|
|
67
70
|
* ```
|
|
68
71
|
*/
|
|
69
|
-
export declare function useEncodeBlobs({
|
|
72
|
+
export declare function useEncodeBlobs({ ...options }?: UseEncodeBlobsOptions): import("@tanstack/react-query").UseMutationResult<{
|
|
70
73
|
schema_version: string;
|
|
71
74
|
raw_data_size: number;
|
|
72
75
|
blob_merkle_root: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEncodeBlobs.d.ts","sourceRoot":"","sources":["../../src/mutations/useEncodeBlobs.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,qBAAqB,EAE3B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useEncodeBlobs.d.ts","sourceRoot":"","sources":["../../src/mutations/useEncodeBlobs.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,qBAAqB,EAE3B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,SAAS,EAAE,UAAU,CAAC;IACtB;;;;;;;;;OASG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,KAAK,EAAE;QAAE,QAAQ,EAAE,UAAU,CAAA;KAAE,EAAE,CAAC;IAClC;;OAEG;IACH,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,CACpD,eAAe,EAAE,EACjB,KAAK,EACL,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,EAAE,GAAG,OAAO,EAAE,GAAE,qBAA0B;;;;;;;;yDAsCxE"}
|
|
@@ -65,5 +65,5 @@ export type UseRegisterCommitmentsOptions = UseMutationOptionsWithClient<{
|
|
|
65
65
|
* });
|
|
66
66
|
* ```
|
|
67
67
|
*/
|
|
68
|
-
export declare function useRegisterCommitments({ client
|
|
68
|
+
export declare function useRegisterCommitments({ client, ...options }: UseRegisterCommitmentsOptions): import("@tanstack/react-query").UseMutationResult<import("@aptos-labs/wallet-adapter-react").AptosSignAndSubmitTransactionOutput, Error, UseRegisterCommitmentsVariables, readonly unknown[]>;
|
|
69
69
|
//# sourceMappingURL=useRegisterCommitments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRegisterCommitments.d.ts","sourceRoot":"","sources":["../../src/mutations/useRegisterCommitments.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EAIpB,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"useRegisterCommitments.d.ts","sourceRoot":"","sources":["../../src/mutations/useRegisterCommitments.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EAIpB,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;;;;;;;;;;;;;OAcG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,eAAe,CAAA;KAAE,EAAE,CAAC;IACjE;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,4BAA4B,CACtE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAChB,KAAK,EACL,+BAA+B,CAChC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,MAAM,EACN,GAAG,OAAO,EACX,EAAE,6BAA6B,iMA6D/B"}
|
|
@@ -75,5 +75,5 @@ export type UseUploadBlobsOptions = UseMutationOptionsWithClient<void, Error, Us
|
|
|
75
75
|
* });
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
export declare function useUploadBlobs({ client
|
|
78
|
+
export declare function useUploadBlobs({ client, ...options }: UseUploadBlobsOptions): import("@tanstack/react-query").UseMutationResult<void, Error, UseUploadBlobsVariables, readonly unknown[]>;
|
|
79
79
|
//# sourceMappingURL=useUploadBlobs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUploadBlobs.d.ts","sourceRoot":"","sources":["../../src/mutations/useUploadBlobs.tsx"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"useUploadBlobs.d.ts","sourceRoot":"","sources":["../../src/mutations/useUploadBlobs.tsx"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAItC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,UAAU,CAAC;KACtB,EAAE,CAAC;IACJ;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,4BAA4B,CAC9D,IAAI,EACJ,KAAK,EACL,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,qBAAqB,+GAiH3E"}
|
|
@@ -26,5 +26,5 @@ export type UseAccountBlobsOptions = UseQueryOptionsWithClient<BlobMetadata[]> &
|
|
|
26
26
|
* });
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
export declare function useAccountBlobs({ account, pagination, orderBy, where, client
|
|
29
|
+
export declare function useAccountBlobs({ account, pagination, orderBy, where, client, ...options }: UseAccountBlobsOptions): import("@tanstack/react-query").UseQueryResult<BlobMetadata[], Error>;
|
|
30
30
|
//# sourceMappingURL=useAccountBlobs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccountBlobs.d.ts","sourceRoot":"","sources":["../../src/queries/useAccountBlobs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"useAccountBlobs.d.ts","sourceRoot":"","sources":["../../src/queries/useAccountBlobs.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAElE,eAAO,MAAM,0BAA0B,GACrC,QAAQ,UAAU,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;IAC3D,OAAO,EAAE,OAAO,CAAC;CAClB,mKASF,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,yBAAyB,CAAC,YAAY,EAAE,CAAC,GAC5E,UAAU,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,UAAU,EACV,OAAO,EACP,KAAK,EACL,MAAM,EACN,GAAG,OAAO,EACX,EAAE,sBAAsB,yEAmBxB"}
|
|
@@ -25,5 +25,5 @@ export type UseBlobMetadataOptions = UseQueryOptionsWithClient<BlobMetadata | nu
|
|
|
25
25
|
* });
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare function useBlobMetadata({ account, name, client
|
|
28
|
+
export declare function useBlobMetadata({ account, name, client, ...options }: UseBlobMetadataOptions): import("@tanstack/react-query").UseQueryResult<BlobMetadata | null, Error>;
|
|
29
29
|
//# sourceMappingURL=useBlobMetadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlobMetadata.d.ts","sourceRoot":"","sources":["../../src/queries/useBlobMetadata.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"useBlobMetadata.d.ts","sourceRoot":"","sources":["../../src/queries/useBlobMetadata.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAElE,eAAO,MAAM,0BAA0B,GACrC,QAAQ,UAAU,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;IAC3D,OAAO,EAAE,OAAO,CAAC;CAClB,aAC2E,CAAC;AAE/E,MAAM,MAAM,sBAAsB,GAChC,yBAAyB,CAAC,YAAY,GAAG,IAAI,CAAC,GAC5C,UAAU,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,IAAI,EACJ,MAAM,EACN,GAAG,OAAO,EACX,EAAE,sBAAsB,8EAaxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
2
|
-
import type { DefaultError, MutationKey, UseMutationOptions } from "@tanstack/react-query";
|
|
3
|
-
export type
|
|
4
|
-
|
|
2
|
+
import type { DefaultError, MutationKey, UseMutationOptions as UseMutationOptionsTanstack } from "@tanstack/react-query";
|
|
3
|
+
export type UseMutationOptions<TMutationFnData = unknown, TError = DefaultError, TData = TMutationFnData, TMutationKey extends MutationKey = MutationKey> = Omit<UseMutationOptionsTanstack<TMutationFnData, TError, TData, TMutationKey>, "mutationFn">;
|
|
4
|
+
export type UseMutationOptionsWithClient<TMutationFnData = unknown, TError = DefaultError, TData = TMutationFnData, TMutationKey extends MutationKey = MutationKey> = UseMutationOptions<TMutationFnData, TError, TData, TMutationKey> & {
|
|
5
|
+
client?: ShelbyClient | null;
|
|
5
6
|
};
|
|
6
7
|
//# sourceMappingURL=mutations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/types/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,kBAAkB,
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/types/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,kBAAkB,IAAI,0BAA0B,EACjD,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,kBAAkB,CAC5B,eAAe,GAAG,OAAO,EACzB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,eAAe,EACvB,YAAY,SAAS,WAAW,GAAG,WAAW,IAC5C,IAAI,CACN,0BAA0B,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,EACxE,YAAY,CACb,CAAC;AAEF,MAAM,MAAM,4BAA4B,CACtC,eAAe,GAAG,OAAO,EACzB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,eAAe,EACvB,YAAY,SAAS,WAAW,GAAG,WAAW,IAC5C,kBAAkB,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG;IACrE,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CAC9B,CAAC"}
|
package/dist/types/queries.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
2
2
|
import type { DefaultError, QueryKey, UseQueryOptions } from "@tanstack/react-query";
|
|
3
3
|
export type UseQueryOptionsWithClient<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, "queryFn" | "queryKey"> & {
|
|
4
|
-
client
|
|
4
|
+
client?: ShelbyClient | null;
|
|
5
5
|
};
|
|
6
6
|
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/types/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,yBAAyB,CACnC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,IAAI,CACN,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EACvD,SAAS,GAAG,UAAU,CACvB,GAAG;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/types/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,yBAAyB,CACnC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,IAAI,CACN,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EACvD,SAAS,GAAG,UAAU,CACvB,GAAG;IAAE,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;CAAE,CAAC"}
|
package/dist/types/signers.d.ts
CHANGED
|
@@ -2,8 +2,28 @@ import type { Account, AccountAddressInput } from "@aptos-labs/ts-sdk";
|
|
|
2
2
|
import type { SignAndSubmitTransactionFn } from "./walletAdapter";
|
|
3
3
|
export type AccountSigner = Account;
|
|
4
4
|
export type WalletAdapterSigner = {
|
|
5
|
-
account
|
|
5
|
+
account?: AccountAddressInput | {
|
|
6
|
+
address: AccountAddressInput;
|
|
7
|
+
} | null;
|
|
6
8
|
signAndSubmitTransaction: SignAndSubmitTransactionFn;
|
|
7
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* A signer is a user who can sign transactions on the Shelby network.
|
|
12
|
+
* It can be an account signer or a wallet adapter signer.
|
|
13
|
+
*
|
|
14
|
+
* @example AccountSigner
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const signer = new Account.generate();
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example WalletAdapterSigner
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const walletAdapterSigner = useWallet();
|
|
22
|
+
*
|
|
23
|
+
* if (!walletAdapterSigner.account) throw new Error("A wallet must be connected to sign transactions");
|
|
24
|
+
*
|
|
25
|
+
* const signer = walletAdapterSigner;
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
8
28
|
export type Signer = AccountSigner | WalletAdapterSigner;
|
|
9
29
|
//# sourceMappingURL=signers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signers.d.ts","sourceRoot":"","sources":["../../src/types/signers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC;AAEpC,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"signers.d.ts","sourceRoot":"","sources":["../../src/types/signers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC;AAEpC,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,CAAC,EAAE,mBAAmB,GAAG;QAAE,OAAO,EAAE,mBAAmB,CAAA;KAAE,GAAG,IAAI,CAAC;IACxE,wBAAwB,EAAE,0BAA0B,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,MAAM,GAAG,aAAa,GAAG,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shelby-protocol/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "React library for the Shelby Protocol",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@aptos-labs/ts-sdk": "^5.1.1",
|
|
48
48
|
"@aptos-labs/wallet-adapter-react": "^6.0.0 || ^7.0.0",
|
|
49
|
+
"@tanstack/react-query": "^5.90.16",
|
|
49
50
|
"@testing-library/dom": "^10.4.0",
|
|
50
51
|
"@testing-library/react": "^16.3.0",
|
|
51
52
|
"@types/react": "19.2.1",
|
|
@@ -54,6 +55,8 @@
|
|
|
54
55
|
"@vitest/coverage-v8": "^3.2.4",
|
|
55
56
|
"dotenv": "^16.5.0",
|
|
56
57
|
"happy-dom": "^20.0.10",
|
|
58
|
+
"react": "19.2.1",
|
|
59
|
+
"react-dom": "19.2.1",
|
|
57
60
|
"tsup": "^8.4.0",
|
|
58
61
|
"vitest": "^3.1.2",
|
|
59
62
|
"@shelby-protocol/sdk": "0.0.9"
|
|
@@ -75,6 +78,7 @@
|
|
|
75
78
|
"lint": "biome check .",
|
|
76
79
|
"fmt": "biome check . --write",
|
|
77
80
|
"test": "vitest dev --coverage",
|
|
78
|
-
"test:once": "
|
|
81
|
+
"test:once": "echo 'React tests require RPC server - use test:integration instead' && exit 0",
|
|
82
|
+
"test:integration": "vitest run --coverage"
|
|
79
83
|
}
|
|
80
84
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
2
|
+
import { createContext, type PropsWithChildren, useContext } from "react";
|
|
3
|
+
|
|
4
|
+
export const ShelbyClientContext = createContext<ShelbyClient | null>(null);
|
|
5
|
+
|
|
6
|
+
export function ShelbyClientProvider({
|
|
7
|
+
children,
|
|
8
|
+
client,
|
|
9
|
+
}: PropsWithChildren & { client: ShelbyClient }) {
|
|
10
|
+
return (
|
|
11
|
+
<ShelbyClientContext.Provider value={client}>
|
|
12
|
+
{children}
|
|
13
|
+
</ShelbyClientContext.Provider>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useShelbyClient(client?: ShelbyClient | null) {
|
|
18
|
+
const contextClient = useContext(ShelbyClientContext);
|
|
19
|
+
const resolvedClient = client ?? contextClient;
|
|
20
|
+
if (!resolvedClient) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
"`useShelbyClient` requires a client or `ShelbyClientProvider`",
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return resolvedClient;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ShelbyClientProvider";
|
package/src/index.ts
CHANGED
package/src/mutations/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AccountAddressInput } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import { useMutation } from "@tanstack/react-query";
|
|
3
3
|
import pLimit from "p-limit";
|
|
4
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
4
5
|
import type { UseMutationOptionsWithClient } from "../types/mutations";
|
|
5
6
|
|
|
6
7
|
export type UseCommitBlobsVariables = {
|
|
@@ -55,10 +56,8 @@ export type UseCommitBlobsOptions = UseMutationOptionsWithClient<
|
|
|
55
56
|
* });
|
|
56
57
|
* ```
|
|
57
58
|
*/
|
|
58
|
-
export function useCommitBlobs({
|
|
59
|
-
|
|
60
|
-
...options
|
|
61
|
-
}: UseCommitBlobsOptions) {
|
|
59
|
+
export function useCommitBlobs({ client, ...options }: UseCommitBlobsOptions) {
|
|
60
|
+
const shelbyClient = useShelbyClient(client);
|
|
62
61
|
return useMutation({
|
|
63
62
|
mutationFn: async ({
|
|
64
63
|
account,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { InputGenerateTransactionOptions } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { ShelbyBlobClient } from "@shelby-protocol/sdk/browser";
|
|
3
|
+
import { useMutation } from "@tanstack/react-query";
|
|
4
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
5
|
+
import type { UseMutationOptionsWithClient } from "../types/mutations";
|
|
6
|
+
import type { AccountSigner, Signer } from "../types/signers";
|
|
7
|
+
|
|
8
|
+
export type UseDeleteBlobVariables = {
|
|
9
|
+
/**
|
|
10
|
+
* The signer to use for the transaction.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link Signer}
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const signer = new Account.generate();
|
|
17
|
+
* deleteBlob.mutate({
|
|
18
|
+
* signer,
|
|
19
|
+
* blobName: "folder/file.txt",
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
signer: Signer;
|
|
24
|
+
/**
|
|
25
|
+
* The name/path of the blob (e.g. "folder/file.txt").
|
|
26
|
+
*/
|
|
27
|
+
blobName: string;
|
|
28
|
+
/**
|
|
29
|
+
* Optional transaction building options.
|
|
30
|
+
*/
|
|
31
|
+
options?: InputGenerateTransactionOptions;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type UseDeleteBlobOptions = UseMutationOptionsWithClient<
|
|
35
|
+
{ hash: string },
|
|
36
|
+
Error,
|
|
37
|
+
UseDeleteBlobVariables
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Deletes a blob on-chain.
|
|
42
|
+
*
|
|
43
|
+
* @deprecated Use {@link useDeleteBlobs} instead, which supports both single
|
|
44
|
+
* and multiple blob deletion with automatic gas optimization.
|
|
45
|
+
*
|
|
46
|
+
* This mutation deletes blob metadata from the Shelby contract. It supports
|
|
47
|
+
* both account signers and wallet adapter signers.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* import { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
52
|
+
* import { Network } from "@aptos-labs/ts-sdk";
|
|
53
|
+
* import { useDeleteBlobs } from "@shelby-protocol/react";
|
|
54
|
+
*
|
|
55
|
+
* const shelbyClient = new ShelbyClient({ network: Network.SHELBYNET });
|
|
56
|
+
* const deleteBlobs = useDeleteBlobs({
|
|
57
|
+
* client: shelbyClient,
|
|
58
|
+
* onSuccess: ({ hash }) => console.log("Delete tx:", hash),
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* deleteBlobs.mutate({
|
|
62
|
+
* signer,
|
|
63
|
+
* blobNames: ["folder/file.txt"],
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function useDeleteBlob({ client, ...options }: UseDeleteBlobOptions) {
|
|
68
|
+
const shelbyClient = useShelbyClient(client);
|
|
69
|
+
return useMutation({
|
|
70
|
+
mutationFn: async ({ blobName, signer: signerOrFn, options }) => {
|
|
71
|
+
if (!("signAndSubmitTransaction" in signerOrFn)) {
|
|
72
|
+
const accountSigner: AccountSigner = signerOrFn;
|
|
73
|
+
|
|
74
|
+
const { transaction } = await shelbyClient.coordination.deleteBlob({
|
|
75
|
+
account: accountSigner,
|
|
76
|
+
blobName,
|
|
77
|
+
options,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return transaction;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { signAndSubmitTransaction } = signerOrFn;
|
|
84
|
+
const transaction = await signAndSubmitTransaction({
|
|
85
|
+
data: ShelbyBlobClient.createDeleteBlobPayload({ blobName }),
|
|
86
|
+
options,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return transaction;
|
|
90
|
+
},
|
|
91
|
+
...options,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { InputGenerateTransactionOptions } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { ShelbyBlobClient } from "@shelby-protocol/sdk/browser";
|
|
3
|
+
import { useMutation } from "@tanstack/react-query";
|
|
4
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
5
|
+
import type { UseMutationOptionsWithClient } from "../types/mutations";
|
|
6
|
+
import type { AccountSigner, Signer } from "../types/signers";
|
|
7
|
+
|
|
8
|
+
export type UseDeleteBlobsVariables = {
|
|
9
|
+
/**
|
|
10
|
+
* The signer to use for the transaction.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link Signer}
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const signer = new Account.generate();
|
|
17
|
+
* deleteBlobs.mutate({
|
|
18
|
+
* signer,
|
|
19
|
+
* blobNames: ["folder/file1.txt", "folder/file2.txt"],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
signer: Signer;
|
|
24
|
+
/**
|
|
25
|
+
* The names/paths of the blobs to delete, without the account address prefix
|
|
26
|
+
* (e.g. ["folder/file1.txt", "folder/file2.txt"], NOT ["0x1/folder/file1.txt"]).
|
|
27
|
+
* The account address prefix is automatically derived from the signer.
|
|
28
|
+
*/
|
|
29
|
+
blobNames: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Optional transaction building options.
|
|
32
|
+
*/
|
|
33
|
+
options?: InputGenerateTransactionOptions;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type UseDeleteBlobsOptions = UseMutationOptionsWithClient<
|
|
37
|
+
{ hash: string },
|
|
38
|
+
Error,
|
|
39
|
+
UseDeleteBlobsVariables
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Deletes one or more blobs on-chain.
|
|
44
|
+
*
|
|
45
|
+
* This hook automatically optimizes gas costs by using `delete_blob` for single
|
|
46
|
+
* blob deletion and `delete_multiple_blobs` for multiple blobs.
|
|
47
|
+
*
|
|
48
|
+
* **Note:** Deleting multiple blobs (more than one) requires the `delete_multiple_blobs`
|
|
49
|
+
* entry function which will be deployed to the smart contract on 2026-02-04.
|
|
50
|
+
* Using this hook with multiple blobs before that date will result in a transaction failure.
|
|
51
|
+
* Single blob deletion works immediately.
|
|
52
|
+
*
|
|
53
|
+
* This mutation deletes blob metadata from the Shelby contract. It supports
|
|
54
|
+
* both account signers and wallet adapter signers.
|
|
55
|
+
*
|
|
56
|
+
* When deleting multiple blobs, the operation is atomic: if any blob deletion
|
|
57
|
+
* fails (e.g., blob not found), the entire transaction fails and no blobs are deleted.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* import { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
62
|
+
* import { Network } from "@aptos-labs/ts-sdk";
|
|
63
|
+
* import { useDeleteBlobs } from "@shelby-protocol/react";
|
|
64
|
+
*
|
|
65
|
+
* const shelbyClient = new ShelbyClient({ network: Network.SHELBYNET });
|
|
66
|
+
* const deleteBlobs = useDeleteBlobs({
|
|
67
|
+
* client: shelbyClient,
|
|
68
|
+
* onSuccess: ({ hash }) => console.log("Delete tx:", hash),
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* // Delete a single blob
|
|
72
|
+
* deleteBlobs.mutate({
|
|
73
|
+
* signer,
|
|
74
|
+
* blobNames: ["folder/file.txt"],
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Delete multiple blobs in one transaction
|
|
78
|
+
* deleteBlobs.mutate({
|
|
79
|
+
* signer,
|
|
80
|
+
* blobNames: ["folder/file1.txt", "folder/file2.txt"],
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function useDeleteBlobs({ client, ...options }: UseDeleteBlobsOptions) {
|
|
85
|
+
const shelbyClient = useShelbyClient(client);
|
|
86
|
+
return useMutation({
|
|
87
|
+
mutationFn: async ({ blobNames, signer: signerOrFn, options }) => {
|
|
88
|
+
if (blobNames.length === 0) {
|
|
89
|
+
throw new Error("blobNames must contain at least one blob name");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const isSingleBlob = blobNames.length === 1;
|
|
93
|
+
|
|
94
|
+
if (!("signAndSubmitTransaction" in signerOrFn)) {
|
|
95
|
+
const accountSigner: AccountSigner = signerOrFn;
|
|
96
|
+
|
|
97
|
+
// Use single delete for gas optimization
|
|
98
|
+
if (isSingleBlob) {
|
|
99
|
+
const { transaction } = await shelbyClient.coordination.deleteBlob({
|
|
100
|
+
account: accountSigner,
|
|
101
|
+
blobName: blobNames[0],
|
|
102
|
+
options,
|
|
103
|
+
});
|
|
104
|
+
return transaction;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Use batch delete for multiple blobs
|
|
108
|
+
const { transaction } =
|
|
109
|
+
await shelbyClient.coordination.deleteMultipleBlobs({
|
|
110
|
+
account: accountSigner,
|
|
111
|
+
blobNames,
|
|
112
|
+
options,
|
|
113
|
+
});
|
|
114
|
+
return transaction;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const { signAndSubmitTransaction } = signerOrFn;
|
|
118
|
+
|
|
119
|
+
if (isSingleBlob) {
|
|
120
|
+
// Use single delete for gas optimization
|
|
121
|
+
const transaction = await signAndSubmitTransaction({
|
|
122
|
+
data: ShelbyBlobClient.createDeleteBlobPayload({
|
|
123
|
+
blobName: blobNames[0],
|
|
124
|
+
}),
|
|
125
|
+
options,
|
|
126
|
+
});
|
|
127
|
+
return transaction;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Use batch delete for multiple blobs
|
|
131
|
+
const transaction = await signAndSubmitTransaction({
|
|
132
|
+
data: ShelbyBlobClient.createDeleteMultipleBlobsPayload({ blobNames }),
|
|
133
|
+
options,
|
|
134
|
+
});
|
|
135
|
+
return transaction;
|
|
136
|
+
},
|
|
137
|
+
...options,
|
|
138
|
+
});
|
|
139
|
+
}
|