@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
|
@@ -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
|
}),
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ShelbyBlobClient,
|
|
5
5
|
} from "@shelby-protocol/sdk/browser";
|
|
6
6
|
import { useQuery } from "@tanstack/react-query";
|
|
7
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
7
8
|
import type { UseQueryOptionsWithClient } from "../types/queries";
|
|
8
9
|
|
|
9
10
|
export const getUseAccountBlobsQueryKey = (
|
|
@@ -49,9 +50,10 @@ export function useAccountBlobs({
|
|
|
49
50
|
pagination,
|
|
50
51
|
orderBy,
|
|
51
52
|
where,
|
|
52
|
-
client
|
|
53
|
+
client,
|
|
53
54
|
...options
|
|
54
55
|
}: UseAccountBlobsOptions) {
|
|
56
|
+
const shelbyClient = useShelbyClient(client);
|
|
55
57
|
return useQuery<BlobMetadata[]>({
|
|
56
58
|
queryKey: getUseAccountBlobsQueryKey({
|
|
57
59
|
network: shelbyClient.config.network,
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ShelbyBlobClient,
|
|
5
5
|
} from "@shelby-protocol/sdk/browser";
|
|
6
6
|
import { useQuery } from "@tanstack/react-query";
|
|
7
|
+
import { useShelbyClient } from "../components/ShelbyClientProvider";
|
|
7
8
|
import type { UseQueryOptionsWithClient } from "../types/queries";
|
|
8
9
|
|
|
9
10
|
export const getUseBlobMetadataQueryKey = (
|
|
@@ -39,9 +40,10 @@ export type UseBlobMetadataOptions =
|
|
|
39
40
|
export function useBlobMetadata({
|
|
40
41
|
account,
|
|
41
42
|
name,
|
|
42
|
-
client
|
|
43
|
+
client,
|
|
43
44
|
...options
|
|
44
45
|
}: UseBlobMetadataOptions) {
|
|
46
|
+
const shelbyClient = useShelbyClient(client);
|
|
45
47
|
return useQuery<BlobMetadata | null>({
|
|
46
48
|
queryKey: getUseBlobMetadataQueryKey({
|
|
47
49
|
network: shelbyClient.config.network,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./signers";
|
package/src/types/mutations.ts
CHANGED
|
@@ -2,15 +2,24 @@ import type { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
|
2
2
|
import type {
|
|
3
3
|
DefaultError,
|
|
4
4
|
MutationKey,
|
|
5
|
-
UseMutationOptions,
|
|
5
|
+
UseMutationOptions as UseMutationOptionsTanstack,
|
|
6
6
|
} from "@tanstack/react-query";
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type UseMutationOptions<
|
|
9
9
|
TMutationFnData = unknown,
|
|
10
10
|
TError = DefaultError,
|
|
11
11
|
TData = TMutationFnData,
|
|
12
12
|
TMutationKey extends MutationKey = MutationKey,
|
|
13
13
|
> = Omit<
|
|
14
|
-
|
|
14
|
+
UseMutationOptionsTanstack<TMutationFnData, TError, TData, TMutationKey>,
|
|
15
15
|
"mutationFn"
|
|
16
|
-
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export type UseMutationOptionsWithClient<
|
|
19
|
+
TMutationFnData = unknown,
|
|
20
|
+
TError = DefaultError,
|
|
21
|
+
TData = TMutationFnData,
|
|
22
|
+
TMutationKey extends MutationKey = MutationKey,
|
|
23
|
+
> = UseMutationOptions<TMutationFnData, TError, TData, TMutationKey> & {
|
|
24
|
+
client?: ShelbyClient | null;
|
|
25
|
+
};
|
package/src/types/queries.ts
CHANGED
package/src/types/signers.ts
CHANGED
|
@@ -4,8 +4,26 @@ import type { SignAndSubmitTransactionFn } from "./walletAdapter";
|
|
|
4
4
|
export type AccountSigner = Account;
|
|
5
5
|
|
|
6
6
|
export type WalletAdapterSigner = {
|
|
7
|
-
account: AccountAddressInput;
|
|
7
|
+
account?: AccountAddressInput | { address: AccountAddressInput } | null;
|
|
8
8
|
signAndSubmitTransaction: SignAndSubmitTransactionFn;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* A signer is a user who can sign transactions on the Shelby network.
|
|
13
|
+
* It can be an account signer or a wallet adapter signer.
|
|
14
|
+
*
|
|
15
|
+
* @example AccountSigner
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const signer = new Account.generate();
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example WalletAdapterSigner
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const walletAdapterSigner = useWallet();
|
|
23
|
+
*
|
|
24
|
+
* if (!walletAdapterSigner.account) throw new Error("A wallet must be connected to sign transactions");
|
|
25
|
+
*
|
|
26
|
+
* const signer = walletAdapterSigner;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
11
29
|
export type Signer = AccountSigner | WalletAdapterSigner;
|