@shelby-protocol/react 0.0.4 → 1.0.0
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 +21 -0
- package/README.md +31 -0
- package/dist/chunk-ESCNOV4I.js +2 -0
- package/dist/chunk-ESCNOV4I.js.map +1 -0
- package/dist/chunk-EYENPTAB.cjs +2 -0
- package/dist/chunk-EYENPTAB.cjs.map +1 -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/core/index.cjs +2 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/queries/accountBlobs.d.ts +8 -0
- package/dist/core/queries/accountBlobs.d.ts.map +1 -0
- package/dist/core/queries/blobMetadata.d.ts +8 -0
- package/dist/core/queries/blobMetadata.d.ts.map +1 -0
- package/dist/core/queries/index.d.ts +3 -0
- package/dist/core/queries/index.d.ts.map +1 -0
- package/dist/core/types.d.ts +6 -0
- package/dist/core/types.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 +4 -8
- package/dist/queries/useAccountBlobs.d.ts.map +1 -1
- package/dist/queries/useBlobMetadata.d.ts +4 -8
- 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 -5
- 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 +14 -5
- package/src/components/ShelbyClientProvider.tsx +26 -0
- package/src/components/index.ts +1 -0
- package/src/core/index.ts +2 -0
- package/src/core/queries/accountBlobs.ts +23 -0
- package/src/core/queries/blobMetadata.ts +16 -0
- package/src/core/queries/index.ts +8 -0
- package/src/core/types.ts +16 -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 +12 -23
- package/src/queries/useBlobMetadata.tsx +12 -16
- package/src/types/index.ts +1 -0
- package/src/types/mutations.ts +13 -4
- package/src/types/queries.ts +1 -16
- package/src/types/signers.ts +19 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shelby-protocol/react",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "React library for the Shelby Protocol",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"require": "./dist/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./core": {
|
|
20
|
+
"types": "./dist/core/index.d.ts",
|
|
21
|
+
"import": "./dist/core/index.js",
|
|
22
|
+
"require": "./dist/core/index.cjs"
|
|
18
23
|
}
|
|
19
24
|
},
|
|
20
25
|
"files": [
|
|
@@ -36,7 +41,7 @@
|
|
|
36
41
|
"react": "^18.0.0 || ^19.0.0",
|
|
37
42
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
38
43
|
"typescript": ">=5.0.4",
|
|
39
|
-
"@shelby-protocol/sdk": "0.0
|
|
44
|
+
"@shelby-protocol/sdk": "0.1.0"
|
|
40
45
|
},
|
|
41
46
|
"peerDependenciesMeta": {
|
|
42
47
|
"@aptos-labs/wallet-adapter-react": {
|
|
@@ -44,8 +49,9 @@
|
|
|
44
49
|
}
|
|
45
50
|
},
|
|
46
51
|
"devDependencies": {
|
|
47
|
-
"@aptos-labs/ts-sdk": "
|
|
52
|
+
"@aptos-labs/ts-sdk": "5.2.1",
|
|
48
53
|
"@aptos-labs/wallet-adapter-react": "^6.0.0 || ^7.0.0",
|
|
54
|
+
"@tanstack/react-query": "^5.90.16",
|
|
49
55
|
"@testing-library/dom": "^10.4.0",
|
|
50
56
|
"@testing-library/react": "^16.3.0",
|
|
51
57
|
"@types/react": "19.2.1",
|
|
@@ -54,9 +60,11 @@
|
|
|
54
60
|
"@vitest/coverage-v8": "^3.2.4",
|
|
55
61
|
"dotenv": "^16.5.0",
|
|
56
62
|
"happy-dom": "^20.0.10",
|
|
63
|
+
"react": "19.2.1",
|
|
64
|
+
"react-dom": "19.2.1",
|
|
57
65
|
"tsup": "^8.4.0",
|
|
58
66
|
"vitest": "^3.1.2",
|
|
59
|
-
"@shelby-protocol/sdk": "0.0
|
|
67
|
+
"@shelby-protocol/sdk": "0.1.0"
|
|
60
68
|
},
|
|
61
69
|
"keywords": [
|
|
62
70
|
"aptos",
|
|
@@ -75,6 +83,7 @@
|
|
|
75
83
|
"lint": "biome check .",
|
|
76
84
|
"fmt": "biome check . --write",
|
|
77
85
|
"test": "vitest dev --coverage",
|
|
78
|
-
"test:once": "
|
|
86
|
+
"test:once": "echo 'React tests require RPC server - use test:integration instead' && exit 0",
|
|
87
|
+
"test:integration": "vitest run --coverage"
|
|
79
88
|
}
|
|
80
89
|
}
|
|
@@ -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";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Network } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import type {
|
|
3
|
+
BlobMetadata,
|
|
4
|
+
ShelbyBlobClient,
|
|
5
|
+
} from "@shelby-protocol/sdk/browser";
|
|
6
|
+
import type { UseQueryOptionsWithClient } from "../types";
|
|
7
|
+
|
|
8
|
+
export type UseAccountBlobsOptions = UseQueryOptionsWithClient<BlobMetadata[]> &
|
|
9
|
+
Parameters<ShelbyBlobClient["getAccountBlobs"]>[0];
|
|
10
|
+
|
|
11
|
+
export const getUseAccountBlobsQueryKey = (
|
|
12
|
+
params: Parameters<ShelbyBlobClient["getAccountBlobs"]>[0] & {
|
|
13
|
+
network: Network;
|
|
14
|
+
},
|
|
15
|
+
) => [
|
|
16
|
+
"account-blobs",
|
|
17
|
+
params.network,
|
|
18
|
+
params.account.toString(),
|
|
19
|
+
params.pagination?.limit,
|
|
20
|
+
params.pagination?.offset,
|
|
21
|
+
params.orderBy,
|
|
22
|
+
params.where,
|
|
23
|
+
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Network } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import type {
|
|
3
|
+
BlobMetadata,
|
|
4
|
+
ShelbyBlobClient,
|
|
5
|
+
} from "@shelby-protocol/sdk/browser";
|
|
6
|
+
import type { UseQueryOptionsWithClient } from "../types";
|
|
7
|
+
|
|
8
|
+
export type UseBlobMetadataOptions =
|
|
9
|
+
UseQueryOptionsWithClient<BlobMetadata | null> &
|
|
10
|
+
Parameters<ShelbyBlobClient["getBlobMetadata"]>[0];
|
|
11
|
+
|
|
12
|
+
export const getUseBlobMetadataQueryKey = (
|
|
13
|
+
params: Parameters<ShelbyBlobClient["getBlobMetadata"]>[0] & {
|
|
14
|
+
network: Network;
|
|
15
|
+
},
|
|
16
|
+
) => ["blob-metadata", params.network, params.account.toString(), params.name];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
2
|
+
import type {
|
|
3
|
+
DefaultError,
|
|
4
|
+
QueryKey,
|
|
5
|
+
UseQueryOptions,
|
|
6
|
+
} from "@tanstack/react-query";
|
|
7
|
+
|
|
8
|
+
export type UseQueryOptionsWithClient<
|
|
9
|
+
TQueryFnData = unknown,
|
|
10
|
+
TError = DefaultError,
|
|
11
|
+
TData = TQueryFnData,
|
|
12
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
13
|
+
> = Omit<
|
|
14
|
+
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
15
|
+
"queryFn" | "queryKey"
|
|
16
|
+
> & { client?: ShelbyClient | null };
|
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
|
+
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
generateCommitments,
|
|
6
6
|
} from "@shelby-protocol/sdk/browser";
|
|
7
7
|
import { useMutation } from "@tanstack/react-query";
|
|
8
|
-
import type {
|
|
8
|
+
import type { UseMutationOptions } from "../types/mutations";
|
|
9
9
|
|
|
10
10
|
export type UseEncodeBlobsOnChunkEvent = {
|
|
11
11
|
/**
|
|
@@ -25,7 +25,14 @@ export type UseEncodeBlobsOnChunkEvent = {
|
|
|
25
25
|
*/
|
|
26
26
|
chunkData: Uint8Array;
|
|
27
27
|
/**
|
|
28
|
-
* The progress of the encoding.
|
|
28
|
+
* The progress of the encoding in percentage.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* onChunk: ({ progress }) => {
|
|
33
|
+
* console.log(`Encoding progress: ${progress * 100}%`);
|
|
34
|
+
* },
|
|
35
|
+
* ```
|
|
29
36
|
*/
|
|
30
37
|
progress: number;
|
|
31
38
|
};
|
|
@@ -45,7 +52,7 @@ export type UseEncodeBlobsVariables = {
|
|
|
45
52
|
onChunk?: (event: UseEncodeBlobsOnChunkEvent) => void;
|
|
46
53
|
};
|
|
47
54
|
|
|
48
|
-
export type UseEncodeBlobsOptions =
|
|
55
|
+
export type UseEncodeBlobsOptions = UseMutationOptions<
|
|
49
56
|
BlobCommitments[],
|
|
50
57
|
Error,
|
|
51
58
|
UseEncodeBlobsVariables
|
|
@@ -60,13 +67,9 @@ export type UseEncodeBlobsOptions = UseMutationOptionsWithClient<
|
|
|
60
67
|
*
|
|
61
68
|
* @example
|
|
62
69
|
* ```tsx
|
|
63
|
-
* import { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
64
|
-
* import { Network } from "@aptos-labs/ts-sdk";
|
|
65
70
|
* import { useEncodeBlobs } from "@shelby-protocol/react";
|
|
66
71
|
*
|
|
67
|
-
* const shelbyClient = new ShelbyClient({ network: Network.SHELBYNET });
|
|
68
72
|
* const encodeBlobs = useEncodeBlobs({
|
|
69
|
-
* client: shelbyClient,
|
|
70
73
|
* onSuccess: (commitments) => console.log('Encoded', commitments.length, 'blobs'),
|
|
71
74
|
* });
|
|
72
75
|
*
|
|
@@ -78,10 +81,7 @@ export type UseEncodeBlobsOptions = UseMutationOptionsWithClient<
|
|
|
78
81
|
* });
|
|
79
82
|
* ```
|
|
80
83
|
*/
|
|
81
|
-
export function useEncodeBlobs({
|
|
82
|
-
client: shelbyClient,
|
|
83
|
-
...options
|
|
84
|
-
}: UseEncodeBlobsOptions) {
|
|
84
|
+
export function useEncodeBlobs({ ...options }: UseEncodeBlobsOptions = {}) {
|
|
85
85
|
return useMutation({
|
|
86
86
|
mutationFn: async ({ blobs, provider, onChunk }) => {
|
|
87
87
|
const activeProvider =
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type UploadOptions,
|
|
8
8
|
} from "@shelby-protocol/sdk/browser";
|
|
9
9
|
import { useMutation } from "@tanstack/react-query";
|
|
10
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
10
11
|
import type { UseMutationOptionsWithClient } from "../types/mutations";
|
|
11
12
|
import type { AccountSigner, Signer } from "../types/signers";
|
|
12
13
|
|
|
@@ -76,9 +77,10 @@ export type UseRegisterCommitmentsOptions = UseMutationOptionsWithClient<
|
|
|
76
77
|
* ```
|
|
77
78
|
*/
|
|
78
79
|
export function useRegisterCommitments({
|
|
79
|
-
client
|
|
80
|
+
client,
|
|
80
81
|
...options
|
|
81
82
|
}: UseRegisterCommitmentsOptions) {
|
|
83
|
+
const shelbyClient = useShelbyClient(client);
|
|
82
84
|
return useMutation({
|
|
83
85
|
mutationFn: async ({
|
|
84
86
|
commitments,
|
|
@@ -86,7 +88,7 @@ export function useRegisterCommitments({
|
|
|
86
88
|
options,
|
|
87
89
|
signer: signerOrFn,
|
|
88
90
|
}) => {
|
|
89
|
-
if (!("
|
|
91
|
+
if (!("signAndSubmitTransaction" in signerOrFn)) {
|
|
90
92
|
const accountSigner: AccountSigner = signerOrFn;
|
|
91
93
|
|
|
92
94
|
const { transaction } =
|
|
@@ -105,9 +107,21 @@ export function useRegisterCommitments({
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
const { account, signAndSubmitTransaction } = signerOrFn;
|
|
110
|
+
|
|
111
|
+
if (!account) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
"'account' is required if using a wallet adapter signer with 'useRegisterCommitments'",
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const accountAddress =
|
|
118
|
+
typeof account === "object" && "address" in account
|
|
119
|
+
? account.address
|
|
120
|
+
: account;
|
|
121
|
+
|
|
108
122
|
const transaction = await signAndSubmitTransaction({
|
|
109
123
|
data: ShelbyBlobClient.createBatchRegisterBlobsPayload({
|
|
110
|
-
account: AccountAddress.from(
|
|
124
|
+
account: AccountAddress.from(accountAddress),
|
|
111
125
|
expirationMicros,
|
|
112
126
|
blobs: commitments.map((commitment) => ({
|
|
113
127
|
blobName: commitment.blobName,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "@shelby-protocol/sdk/browser";
|
|
11
11
|
import { useMutation } from "@tanstack/react-query";
|
|
12
12
|
import pLimit from "p-limit";
|
|
13
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
13
14
|
import type { UseMutationOptionsWithClient } from "../types/mutations";
|
|
14
15
|
import type { AccountSigner, Signer } from "../types/signers";
|
|
15
16
|
|
|
@@ -93,10 +94,8 @@ export type UseUploadBlobsOptions = UseMutationOptionsWithClient<
|
|
|
93
94
|
* });
|
|
94
95
|
* ```
|
|
95
96
|
*/
|
|
96
|
-
export function useUploadBlobs({
|
|
97
|
-
|
|
98
|
-
...options
|
|
99
|
-
}: UseUploadBlobsOptions) {
|
|
97
|
+
export function useUploadBlobs({ client, ...options }: UseUploadBlobsOptions) {
|
|
98
|
+
const shelbyClient = useShelbyClient(client);
|
|
100
99
|
return useMutation({
|
|
101
100
|
mutationFn: async ({
|
|
102
101
|
blobs,
|
|
@@ -105,7 +104,7 @@ export function useUploadBlobs({
|
|
|
105
104
|
signer: signerOrFn,
|
|
106
105
|
maxConcurrentUploads = 3,
|
|
107
106
|
}: UseUploadBlobsVariables) => {
|
|
108
|
-
if (!("
|
|
107
|
+
if (!("signAndSubmitTransaction" in signerOrFn)) {
|
|
109
108
|
const accountSigner: AccountSigner = signerOrFn;
|
|
110
109
|
|
|
111
110
|
await shelbyClient.batchUpload({
|
|
@@ -120,6 +119,17 @@ export function useUploadBlobs({
|
|
|
120
119
|
} else {
|
|
121
120
|
const { account, signAndSubmitTransaction } = signerOrFn;
|
|
122
121
|
|
|
122
|
+
if (!account) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
"'account' is required if using a wallet adapter signer with 'useUploadBlobs'",
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const accountAddress =
|
|
129
|
+
typeof account === "object" && "address" in account
|
|
130
|
+
? account.address
|
|
131
|
+
: account;
|
|
132
|
+
|
|
123
133
|
const chunksetSize =
|
|
124
134
|
options?.chunksetSizeBytes ?? DEFAULT_CHUNKSET_SIZE_BYTES;
|
|
125
135
|
|
|
@@ -127,7 +137,10 @@ export function useUploadBlobs({
|
|
|
127
137
|
where: {
|
|
128
138
|
blob_name: {
|
|
129
139
|
_in: blobs.map((blob) =>
|
|
130
|
-
createBlobKey({
|
|
140
|
+
createBlobKey({
|
|
141
|
+
account: accountAddress,
|
|
142
|
+
blobName: blob.blobName,
|
|
143
|
+
}),
|
|
131
144
|
),
|
|
132
145
|
},
|
|
133
146
|
},
|
|
@@ -138,7 +151,10 @@ export function useUploadBlobs({
|
|
|
138
151
|
!existingBlobs.some(
|
|
139
152
|
(existingBlob) =>
|
|
140
153
|
existingBlob.name ===
|
|
141
|
-
createBlobKey({
|
|
154
|
+
createBlobKey({
|
|
155
|
+
account: accountAddress,
|
|
156
|
+
blobName: blob.blobName,
|
|
157
|
+
}),
|
|
142
158
|
),
|
|
143
159
|
);
|
|
144
160
|
|
|
@@ -154,7 +170,7 @@ export function useUploadBlobs({
|
|
|
154
170
|
const pendingRegisterBlobTransaction = await signAndSubmitTransaction(
|
|
155
171
|
{
|
|
156
172
|
data: ShelbyBlobClient.createBatchRegisterBlobsPayload({
|
|
157
|
-
account: AccountAddress.from(
|
|
173
|
+
account: AccountAddress.from(accountAddress),
|
|
158
174
|
expirationMicros,
|
|
159
175
|
blobs: blobsToRegister.map((blob, index) => ({
|
|
160
176
|
blobName: blob.blobName,
|
|
@@ -179,7 +195,7 @@ export function useUploadBlobs({
|
|
|
179
195
|
const uploadPromises = blobs.map((blob) =>
|
|
180
196
|
limit(() =>
|
|
181
197
|
shelbyClient.rpc.putBlob({
|
|
182
|
-
account,
|
|
198
|
+
account: accountAddress,
|
|
183
199
|
blobName: blob.blobName,
|
|
184
200
|
blobData: blob.blobData,
|
|
185
201
|
}),
|
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
BlobMetadata,
|
|
4
|
-
ShelbyBlobClient,
|
|
5
|
-
} from "@shelby-protocol/sdk/browser";
|
|
1
|
+
import type { BlobMetadata } from "@shelby-protocol/sdk/browser";
|
|
6
2
|
import { useQuery } from "@tanstack/react-query";
|
|
7
|
-
import
|
|
3
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
4
|
+
import {
|
|
5
|
+
getUseAccountBlobsQueryKey,
|
|
6
|
+
type UseAccountBlobsOptions,
|
|
7
|
+
} from "../core/queries/accountBlobs";
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
) => [
|
|
14
|
-
"account-blobs",
|
|
15
|
-
params.network,
|
|
16
|
-
params.account.toString(),
|
|
17
|
-
params.pagination?.limit,
|
|
18
|
-
params.pagination?.offset,
|
|
19
|
-
params.orderBy,
|
|
20
|
-
params.where,
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export type UseAccountBlobsOptions = UseQueryOptionsWithClient<BlobMetadata[]> &
|
|
24
|
-
Parameters<ShelbyBlobClient["getAccountBlobs"]>[0];
|
|
9
|
+
export {
|
|
10
|
+
getUseAccountBlobsQueryKey,
|
|
11
|
+
type UseAccountBlobsOptions,
|
|
12
|
+
} from "../core/queries/accountBlobs";
|
|
25
13
|
|
|
26
14
|
/**
|
|
27
15
|
* Queries blobs associated with an account.
|
|
@@ -49,9 +37,10 @@ export function useAccountBlobs({
|
|
|
49
37
|
pagination,
|
|
50
38
|
orderBy,
|
|
51
39
|
where,
|
|
52
|
-
client
|
|
40
|
+
client,
|
|
53
41
|
...options
|
|
54
42
|
}: UseAccountBlobsOptions) {
|
|
43
|
+
const shelbyClient = useShelbyClient(client);
|
|
55
44
|
return useQuery<BlobMetadata[]>({
|
|
56
45
|
queryKey: getUseAccountBlobsQueryKey({
|
|
57
46
|
network: shelbyClient.config.network,
|