@filoz/synapse-react 0.1.4 → 0.2.1

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.
Files changed (59) hide show
  1. package/dist/src/calibration.d.ts +1 -2
  2. package/dist/src/calibration.d.ts.map +1 -1
  3. package/dist/src/calibration.js.map +1 -1
  4. package/dist/src/erc20.d.ts +6 -7
  5. package/dist/src/erc20.d.ts.map +1 -1
  6. package/dist/src/erc20.js +1 -1
  7. package/dist/src/erc20.js.map +1 -1
  8. package/dist/src/filsnap.d.ts.map +1 -1
  9. package/dist/src/filsnap.js +3 -0
  10. package/dist/src/filsnap.js.map +1 -1
  11. package/dist/src/index.d.ts +0 -1
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/index.js +0 -1
  14. package/dist/src/index.js.map +1 -1
  15. package/dist/src/payments/index.d.ts +13 -14
  16. package/dist/src/payments/index.d.ts.map +1 -1
  17. package/dist/src/payments/index.js +19 -20
  18. package/dist/src/payments/index.js.map +1 -1
  19. package/dist/src/payments/use-deposit-and-approve.d.ts +4 -5
  20. package/dist/src/payments/use-deposit-and-approve.d.ts.map +1 -1
  21. package/dist/src/payments/use-deposit-and-approve.js +1 -1
  22. package/dist/src/payments/use-deposit-and-approve.js.map +1 -1
  23. package/dist/src/warm-storage/use-create-data-set.d.ts +11 -5
  24. package/dist/src/warm-storage/use-create-data-set.d.ts.map +1 -1
  25. package/dist/src/warm-storage/use-create-data-set.js +4 -8
  26. package/dist/src/warm-storage/use-create-data-set.js.map +1 -1
  27. package/dist/src/warm-storage/use-data-sets.d.ts +11 -21
  28. package/dist/src/warm-storage/use-data-sets.d.ts.map +1 -1
  29. package/dist/src/warm-storage/use-data-sets.js +7 -23
  30. package/dist/src/warm-storage/use-data-sets.js.map +1 -1
  31. package/dist/src/warm-storage/use-delete-piece.d.ts +3 -3
  32. package/dist/src/warm-storage/use-delete-piece.d.ts.map +1 -1
  33. package/dist/src/warm-storage/use-delete-piece.js +7 -6
  34. package/dist/src/warm-storage/use-delete-piece.js.map +1 -1
  35. package/dist/src/warm-storage/use-providers.d.ts +3 -3
  36. package/dist/src/warm-storage/use-providers.d.ts.map +1 -1
  37. package/dist/src/warm-storage/use-providers.js +3 -3
  38. package/dist/src/warm-storage/use-providers.js.map +1 -1
  39. package/dist/src/warm-storage/use-service-price.d.ts +4 -4
  40. package/dist/src/warm-storage/use-service-price.d.ts.map +1 -1
  41. package/dist/src/warm-storage/use-service-price.js +3 -3
  42. package/dist/src/warm-storage/use-service-price.js.map +1 -1
  43. package/dist/src/warm-storage/use-upload.d.ts +10 -2
  44. package/dist/src/warm-storage/use-upload.d.ts.map +1 -1
  45. package/dist/src/warm-storage/use-upload.js +3 -3
  46. package/dist/src/warm-storage/use-upload.js.map +1 -1
  47. package/package.json +23 -9
  48. package/src/calibration.ts +3 -5
  49. package/src/erc20.ts +7 -7
  50. package/src/filsnap.ts +4 -0
  51. package/src/index.ts +0 -1
  52. package/src/payments/index.ts +36 -59
  53. package/src/payments/use-deposit-and-approve.ts +8 -12
  54. package/src/warm-storage/use-create-data-set.ts +7 -11
  55. package/src/warm-storage/use-data-sets.ts +8 -30
  56. package/src/warm-storage/use-delete-piece.ts +9 -7
  57. package/src/warm-storage/use-providers.ts +4 -4
  58. package/src/warm-storage/use-service-price.ts +9 -9
  59. package/src/warm-storage/use-upload.ts +3 -4
@@ -1,17 +1,5 @@
1
1
  import { getChain } from '@filoz/synapse-core/chains'
2
- import {
3
- type AccountInfoOptions,
4
- type AccountInfoResult,
5
- accountInfo,
6
- type DepositOptions,
7
- deposit,
8
- type OperatorApprovalsOptions,
9
- type OperatorApprovalsResult,
10
- operatorApprovals,
11
- setOperatorApproval,
12
- type WithdrawOptions,
13
- withdraw,
14
- } from '@filoz/synapse-core/pay'
2
+ import { accounts, deposit, operatorApprovals, setOperatorApproval, withdraw } from '@filoz/synapse-core/pay'
15
3
  import {
16
4
  type MutateOptions,
17
5
  skipToken,
@@ -23,16 +11,16 @@ import {
23
11
  import type { SetOptional } from 'type-fest'
24
12
  import type { Address, TransactionReceipt } from 'viem'
25
13
  import { waitForTransactionReceipt } from 'viem/actions'
26
- import { useAccount, useBlock, useChainId, useConfig } from 'wagmi'
14
+ import { useAccount, useBlock, useChainId, useConfig, useConnection } from 'wagmi'
27
15
  import { getConnectorClient } from 'wagmi/actions'
28
16
 
29
- interface UseAccountInfoProps extends SetOptional<AccountInfoOptions, 'address'> {
17
+ export interface UseAccountInfoProps extends SetOptional<accounts.OptionsType, 'address'> {
30
18
  /**
31
19
  * Whether to watch blocks.
32
20
  * @default false
33
21
  */
34
22
  watch?: boolean
35
- query?: Omit<UseQueryOptions<AccountInfoResult>, 'queryKey' | 'queryFn'>
23
+ query?: Omit<UseQueryOptions<accounts.OutputType>, 'queryKey' | 'queryFn'>
36
24
  }
37
25
 
38
26
  /**
@@ -50,7 +38,7 @@ export function useAccountInfo(props?: UseAccountInfoProps) {
50
38
  const chainId = useChainId({ config })
51
39
  const chain = getChain(chainId)
52
40
  const token = props?.token ?? chain.contracts.usdfc.address
53
- const address = props?.address
41
+ const owner = props?.address
54
42
  const { data } = useBlock({
55
43
  blockTag: 'latest',
56
44
  chainId,
@@ -59,12 +47,13 @@ export function useAccountInfo(props?: UseAccountInfoProps) {
59
47
 
60
48
  const result = useQuery({
61
49
  ...props?.query,
62
- queryKey: ['synapse-payments-account-info', address, token, data?.number?.toString()],
63
- queryFn: address
50
+ queryKey: ['synapse-payments-account-info', owner, token, data?.number?.toString()],
51
+ queryFn: owner
64
52
  ? async () => {
65
- return await accountInfo(config.getClient(), {
53
+ return await accounts(config.getClient(), {
66
54
  token,
67
- address,
55
+ address: owner,
56
+
68
57
  blockNumber: data?.number,
69
58
  })
70
59
  }
@@ -73,12 +62,10 @@ export function useAccountInfo(props?: UseAccountInfoProps) {
73
62
  return result
74
63
  }
75
64
 
76
- export interface UseOperatorApprovalsProps extends SetOptional<OperatorApprovalsOptions, 'address'> {
77
- query?: Omit<UseQueryOptions<OperatorApprovalsResult>, 'queryKey' | 'queryFn'>
65
+ export interface UseOperatorApprovalsProps extends SetOptional<operatorApprovals.OptionsType, 'address'> {
66
+ query?: Omit<UseQueryOptions<operatorApprovals.OutputType>, 'queryKey' | 'queryFn'>
78
67
  }
79
68
 
80
- export type { OperatorApprovalsResult } from '@filoz/synapse-core/pay'
81
-
82
69
  /**
83
70
  * Get the operator approvals from the payments contract.
84
71
  *
@@ -90,7 +77,7 @@ export function useOperatorApprovals(props?: UseOperatorApprovalsProps) {
90
77
  const chainId = useChainId({ config })
91
78
  const chain = getChain(chainId)
92
79
  const token = props?.token ?? chain.contracts.usdfc.address
93
- const operator = props?.operator ?? chain.contracts.storage.address
80
+ const operator = props?.operator ?? chain.contracts.fwss.address
94
81
  const address = props?.address
95
82
 
96
83
  const result = useQuery({
@@ -109,8 +96,8 @@ export function useOperatorApprovals(props?: UseOperatorApprovalsProps) {
109
96
  return result
110
97
  }
111
98
 
112
- type UseDepositVariables = Pick<DepositOptions, 'amount'>
113
- interface UseDepositProps extends Omit<DepositOptions, 'amount'> {
99
+ export type UseDepositVariables = Pick<deposit.OptionsType, 'amount'>
100
+ export interface UseDepositProps extends Omit<deposit.OptionsType, 'amount'> {
114
101
  /**
115
102
  * The mutation options.
116
103
  */
@@ -124,21 +111,17 @@ interface UseDepositProps extends Omit<DepositOptions, 'amount'> {
124
111
  /**
125
112
  * Deposit ERC20 tokens into the payments contract.
126
113
  *
127
- * @param props - The props for the deposit.
128
- * @param props.address - The address of the account to deposit from.
129
- * @param props.token - The address of the ERC20 token to deposit.
130
- * @param props.mutation - The mutation options.
131
- * @param props.onHash - The callback to call when the hash is available.
114
+ * @param props - The props for the deposit. {@link UseDepositProps}
132
115
  * @returns The deposit mutation.
133
116
  */
134
117
  export function useDeposit(props?: UseDepositProps) {
135
118
  const config = useConfig()
136
119
  const chainId = useChainId({ config })
137
120
  const chain = getChain(chainId)
138
- const account = useAccount({ config })
121
+ const account = useConnection({ config })
139
122
  const queryClient = useQueryClient()
140
123
  const token = props?.token ?? chain.contracts.usdfc.address
141
- const from = props?.address ?? account.address
124
+ const to = props?.to ?? account.address
142
125
 
143
126
  return useMutation({
144
127
  mutationFn: async ({ amount }: UseDepositVariables) => {
@@ -149,8 +132,9 @@ export function useDeposit(props?: UseDepositProps) {
149
132
 
150
133
  const hash = await deposit(client, {
151
134
  amount,
152
- address: account.address,
135
+ to,
153
136
  token,
137
+ contractAddress: props?.contractAddress,
154
138
  })
155
139
 
156
140
  props?.onHash?.(hash)
@@ -159,10 +143,10 @@ export function useDeposit(props?: UseDepositProps) {
159
143
  })
160
144
 
161
145
  queryClient.invalidateQueries({
162
- queryKey: ['synapse-payments-account-info', from, token],
146
+ queryKey: ['synapse-payments-account-info', to, token],
163
147
  })
164
148
  queryClient.invalidateQueries({
165
- queryKey: ['synapse-erc20-balance', from, token],
149
+ queryKey: ['synapse-erc20-balance', to, token],
166
150
  })
167
151
  return transactionReceipt
168
152
  },
@@ -170,8 +154,8 @@ export function useDeposit(props?: UseDepositProps) {
170
154
  })
171
155
  }
172
156
 
173
- type UseWithdrawVariables = Pick<WithdrawOptions, 'amount'>
174
- type UseWithdrawProps = Omit<WithdrawOptions, 'amount'> & {
157
+ export type UseWithdrawVariables = Pick<withdraw.OptionsType, 'amount'>
158
+ export type UseWithdrawProps = Omit<withdraw.OptionsType, 'amount'> & {
175
159
  mutation?: Omit<MutateOptions<TransactionReceipt, Error, UseWithdrawVariables>, 'mutationFn'>
176
160
  onHash?: (hash: string) => void
177
161
  }
@@ -185,10 +169,9 @@ export function useWithdraw(props?: UseWithdrawProps) {
185
169
  const config = useConfig()
186
170
  const chainId = useChainId({ config })
187
171
  const chain = getChain(chainId)
188
- const account = useAccount({ config })
172
+ const account = useConnection({ config })
189
173
  const queryClient = useQueryClient()
190
174
  const token = props?.token ?? chain.contracts.usdfc.address
191
- const from = props?.address ?? account.address
192
175
 
193
176
  return useMutation({
194
177
  mutationFn: async ({ amount }: UseWithdrawVariables) => {
@@ -199,7 +182,6 @@ export function useWithdraw(props?: UseWithdrawProps) {
199
182
 
200
183
  const hash = await withdraw(client, {
201
184
  amount,
202
- address: account.address,
203
185
  token,
204
186
  })
205
187
  props?.onHash?.(hash)
@@ -208,10 +190,10 @@ export function useWithdraw(props?: UseWithdrawProps) {
208
190
  })
209
191
 
210
192
  queryClient.invalidateQueries({
211
- queryKey: ['synapse-payments-account-info', from, token],
193
+ queryKey: ['synapse-payments-account-info', account.address, token],
212
194
  })
213
195
  queryClient.invalidateQueries({
214
- queryKey: ['synapse-erc20-balance', from, token],
196
+ queryKey: ['synapse-erc20-balance', account.address, token],
215
197
  })
216
198
  return transactionReceipt
217
199
  },
@@ -219,7 +201,7 @@ export function useWithdraw(props?: UseWithdrawProps) {
219
201
  })
220
202
  }
221
203
 
222
- type ApproveOperatorProps =
204
+ export type ApproveOperatorProps =
223
205
  | {
224
206
  /**
225
207
  * The address of the operator to approve.
@@ -242,11 +224,7 @@ type ApproveOperatorProps =
242
224
  /**
243
225
  * Approve a service contract to act as an operator for payment rails.
244
226
  *
245
- * @param props - The props for the deposit.
246
- * @param props.operator - The address of the operator to approve.
247
- * @param props.token - The address of the ERC20 token to deposit.
248
- * @param props.mutation - The mutation options.
249
- * @param props.onHash - The callback to call when the hash is available.
227
+ * @param props - The props for the deposit. {@link ApproveOperatorProps}
250
228
  * @returns The deposit mutation.
251
229
  */
252
230
  export function useApproveOperator(props?: ApproveOperatorProps) {
@@ -256,7 +234,7 @@ export function useApproveOperator(props?: ApproveOperatorProps) {
256
234
  const account = useAccount({ config })
257
235
  const queryClient = useQueryClient()
258
236
  const token = props?.token ?? chain.contracts.usdfc.address
259
- const operator = props?.operator ?? chain.contracts.storage.address
237
+ const operator = props?.operator ?? chain.contracts.fwss.address
260
238
 
261
239
  return useMutation({
262
240
  ...props?.mutation,
@@ -288,7 +266,7 @@ export function useApproveOperator(props?: ApproveOperatorProps) {
288
266
  })
289
267
  }
290
268
 
291
- type RevokeOperatorProps =
269
+ export type RevokeOperatorProps =
292
270
  | {
293
271
  /**
294
272
  * The address of the operator to revoke.
@@ -304,6 +282,9 @@ type RevokeOperatorProps =
304
282
  * The mutation options.
305
283
  */
306
284
  mutation?: Omit<MutateOptions<TransactionReceipt, Error>, 'mutationFn'>
285
+ /**
286
+ * The callback to call when the hash is available.
287
+ */
307
288
  onHash?: (hash: string) => void
308
289
  }
309
290
  | undefined
@@ -311,11 +292,7 @@ type RevokeOperatorProps =
311
292
  /**
312
293
  * Revoke the operator to deposit and withdraw ERC20 tokens from the payments contract.
313
294
  *
314
- * @param props - The props for the deposit.
315
- * @param props.operator - The address of the operator to approve.
316
- * @param props.token - The address of the ERC20 token to deposit.
317
- * @param props.mutation - The mutation options.
318
- * @param props.onHash - The callback to call when the hash is available.
295
+ * @param props - The props for the deposit. {@link RevokeOperatorProps}
319
296
  * @returns The deposit mutation.
320
297
  */
321
298
  export function useRevokeOperator(props?: RevokeOperatorProps) {
@@ -325,7 +302,7 @@ export function useRevokeOperator(props?: RevokeOperatorProps) {
325
302
  const account = useAccount({ config })
326
303
  const queryClient = useQueryClient()
327
304
  const token = props?.token ?? chain.contracts.usdfc.address
328
- const operator = props?.operator ?? chain.contracts.storage.address
305
+ const operator = props?.operator ?? chain.contracts.fwss.address
329
306
 
330
307
  return useMutation({
331
308
  ...props?.mutation,
@@ -7,12 +7,12 @@ import { waitForTransactionReceipt } from 'viem/actions'
7
7
  import { useAccount, useChainId, useConfig } from 'wagmi'
8
8
  import { getConnectorClient } from 'wagmi/actions'
9
9
 
10
- type UseDepositVariables = Pick<DepositAndApproveOptions, 'amount'>
11
- interface UseDepositAndApproveProps extends Omit<DepositAndApproveOptions, 'amount'> {
10
+ export type UseDepositAndApproveVariables = Pick<DepositAndApproveOptions, 'amount'>
11
+ export interface UseDepositAndApproveProps extends Omit<DepositAndApproveOptions, 'amount'> {
12
12
  /**
13
13
  * The mutation options.
14
14
  */
15
- mutation?: Omit<MutateOptions<TransactionReceipt, Error, UseDepositVariables>, 'mutationFn'>
15
+ mutation?: Omit<MutateOptions<TransactionReceipt, Error, UseDepositAndApproveVariables>, 'mutationFn'>
16
16
  /**
17
17
  * The callback to call when the hash is available.
18
18
  */
@@ -20,14 +20,10 @@ interface UseDepositAndApproveProps extends Omit<DepositAndApproveOptions, 'amou
20
20
  }
21
21
 
22
22
  /**
23
- * Deposit ERC20 tokens into the payments contract.
23
+ * Deposit and approve ERC20 tokens into the payments contract.
24
24
  *
25
- * @param props - The props for the deposit.
26
- * @param props.address - The address of the account to deposit from.
27
- * @param props.token - The address of the ERC20 token to deposit.
28
- * @param props.mutation - The mutation options.
29
- * @param props.onHash - The callback to call when the hash is available.
30
- * @returns The deposit mutation.
25
+ * @param props - The props for the deposit. {@link UseDepositAndApproveProps}
26
+ * @returns The deposit and approve mutation.
31
27
  */
32
28
  export function useDepositAndApprove(props?: UseDepositAndApproveProps) {
33
29
  const config = useConfig()
@@ -39,7 +35,7 @@ export function useDepositAndApprove(props?: UseDepositAndApproveProps) {
39
35
  const from = props?.address ?? account.address
40
36
 
41
37
  return useMutation({
42
- mutationFn: async ({ amount }: UseDepositVariables) => {
38
+ mutationFn: async ({ amount }: UseDepositAndApproveVariables) => {
43
39
  const client = await getConnectorClient(config, {
44
40
  account: account.address,
45
41
  chainId,
@@ -61,7 +57,7 @@ export function useDepositAndApprove(props?: UseDepositAndApproveProps) {
61
57
  queryKey: ['synapse-erc20-balance', from, token],
62
58
  })
63
59
  queryClient.invalidateQueries({
64
- queryKey: ['synapse-payments-operator-approvals', from, token, chain.contracts.storage.address],
60
+ queryKey: ['synapse-payments-operator-approvals', from, token, chain.contracts.fwss.address],
65
61
  })
66
62
 
67
63
  return transactionReceipt
@@ -1,6 +1,5 @@
1
- import type { DataSetCreatedResponse } from '@filoz/synapse-core/sp'
2
1
  import * as SP from '@filoz/synapse-core/sp'
3
- import { createDataSet, type PDPProvider } from '@filoz/synapse-core/warm-storage'
2
+ import type { PDPProvider } from '@filoz/synapse-core/sp-registry'
4
3
  import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
5
4
  import { useAccount, useChainId, useConfig } from 'wagmi'
6
5
  import { getConnectorClient } from 'wagmi/actions'
@@ -10,7 +9,7 @@ export interface UseCreateDataSetProps {
10
9
  * The callback to call when the hash is available.
11
10
  */
12
11
  onHash?: (hash: string) => void
13
- mutation?: Omit<MutateOptions<DataSetCreatedResponse, Error, UseCreateDataSetVariables>, 'mutationFn'>
12
+ mutation?: Omit<MutateOptions<SP.waitForCreateDataSet.ReturnType, Error, UseCreateDataSetVariables>, 'mutationFn'>
14
13
  }
15
14
 
16
15
  export interface UseCreateDataSetVariables {
@@ -21,7 +20,7 @@ export interface UseCreateDataSetVariables {
21
20
  cdn: boolean
22
21
  }
23
22
 
24
- export type UseCreateDataSetResult = DataSetCreatedResponse
23
+ export type UseCreateDataSetResult = SP.waitForCreateDataSet.ReturnType
25
24
 
26
25
  export function useCreateDataSet(props: UseCreateDataSetProps) {
27
26
  const config = useConfig()
@@ -36,10 +35,10 @@ export function useCreateDataSet(props: UseCreateDataSetProps) {
36
35
  chainId,
37
36
  })
38
37
 
39
- const { txHash, statusUrl } = await createDataSet(connectorClient, {
38
+ const { txHash, statusUrl } = await SP.createDataSet(connectorClient, {
40
39
  payee: provider.payee,
41
40
  payer: account.address,
42
- endpoint: provider.pdp.serviceURL,
41
+ serviceURL: provider.pdp.serviceURL,
43
42
  cdn,
44
43
  // metadata: {
45
44
  // title: 'Test Data Set',
@@ -48,13 +47,10 @@ export function useCreateDataSet(props: UseCreateDataSetProps) {
48
47
  })
49
48
  props?.onHash?.(txHash)
50
49
 
51
- const dataSet = await SP.pollForDataSetCreationStatus({ statusUrl })
50
+ const dataSet = await SP.waitForCreateDataSet({ statusUrl })
52
51
 
53
52
  queryClient.invalidateQueries({
54
- queryKey: ['synapse-warm-storage-data-sets', account.address],
55
- })
56
- queryClient.invalidateQueries({
57
- queryKey: ['synapse-warm-storage-providers-with-data-sets', account.address],
53
+ queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
58
54
  })
59
55
  return dataSet
60
56
  },
@@ -1,15 +1,10 @@
1
- import { getChain } from '@filoz/synapse-core/chains'
2
- import { type MetadataObject, metadataArrayToObject } from '@filoz/synapse-core/utils'
3
- import { type DataSet, getDataSets, getPieces, type Piece } from '@filoz/synapse-core/warm-storage'
1
+ import { getPiecesWithMetadata } from '@filoz/synapse-core/pdp-verifier'
2
+ import { getPdpDataSets, type PdpDataSet, type PieceWithMetadata } from '@filoz/synapse-core/warm-storage'
4
3
  import { skipToken, type UseQueryOptions, useQuery } from '@tanstack/react-query'
5
- import type { Simplify } from 'type-fest'
6
4
  import type { Address } from 'viem'
7
- import { readContract } from 'viem/actions'
8
- import { useChainId, useConfig } from 'wagmi'
5
+ import { useConfig } from 'wagmi'
9
6
 
10
- export type PieceWithMetadata = Simplify<Piece & { metadata: MetadataObject }>
11
-
12
- export interface DataSetWithPieces extends DataSet {
7
+ export interface DataSetWithPieces extends PdpDataSet {
13
8
  pieces: PieceWithMetadata[]
14
9
  }
15
10
 
@@ -22,39 +17,22 @@ export interface UseDataSetsProps {
22
17
 
23
18
  export function useDataSets(props: UseDataSetsProps) {
24
19
  const config = useConfig()
25
- const chainId = useChainId()
26
20
  const address = props.address
27
- const chain = getChain(chainId)
28
21
  return useQuery({
29
- queryKey: ['synapse-warm-storage-data-sets', address],
22
+ queryKey: ['synapse-warm-storage-data-sets', address, config.getClient().chain.id],
30
23
  queryFn: address
31
24
  ? async () => {
32
- const dataSets = await getDataSets(config.getClient(), { address })
25
+ const dataSets = await getPdpDataSets(config.getClient(), { address })
33
26
  const dataSetsWithPieces = await Promise.all(
34
27
  dataSets.map(async (dataSet) => {
35
- const piecesPaginated = await getPieces(config.getClient(), {
28
+ const result = await getPiecesWithMetadata(config.getClient(), {
36
29
  dataSet,
37
30
  address,
38
31
  })
39
32
 
40
- const piecesWithMetadata = await Promise.all(
41
- piecesPaginated.pieces.map(async (piece) => {
42
- const metadata = await readContract(config.getClient(), {
43
- address: chain.contracts.storageView.address,
44
- abi: chain.contracts.storageView.abi,
45
- functionName: 'getAllPieceMetadata',
46
- args: [dataSet.dataSetId, BigInt(piece.id)],
47
- })
48
- return {
49
- ...piece,
50
- metadata: metadataArrayToObject(metadata),
51
- }
52
- })
53
- )
54
-
55
33
  return {
56
34
  ...dataSet,
57
- pieces: piecesWithMetadata,
35
+ pieces: result.pieces,
58
36
  }
59
37
  })
60
38
  )
@@ -1,8 +1,10 @@
1
1
  import { getChain } from '@filoz/synapse-core/chains'
2
2
  import type { SessionKey } from '@filoz/synapse-core/session-key'
3
- import { type DataSet, deletePiece, pollForDeletePieceStatus } from '@filoz/synapse-core/warm-storage'
3
+ import * as SP from '@filoz/synapse-core/sp'
4
+ import type { PdpDataSet } from '@filoz/synapse-core/warm-storage'
4
5
  import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
5
6
  import type { TransactionReceipt } from 'viem'
7
+ import { waitForTransactionReceipt } from 'viem/actions'
6
8
  import { useAccount, useChainId, useConfig } from 'wagmi'
7
9
  import { getConnectorClient } from 'wagmi/actions'
8
10
 
@@ -16,7 +18,7 @@ export interface UseDeletePieceProps {
16
18
  }
17
19
 
18
20
  export interface UseDeletePieceVariables {
19
- dataSet: DataSet
21
+ dataSet: PdpDataSet
20
22
  pieceId: bigint
21
23
  }
22
24
  export function useDeletePiece(props: UseDeletePieceProps) {
@@ -39,18 +41,18 @@ export function useDeletePiece(props: UseDeletePieceProps) {
39
41
  connectorClient = props?.sessionKey.client(chain, client.transport)
40
42
  }
41
43
 
42
- const deletePieceRsp = await deletePiece(connectorClient, {
43
- endpoint: dataSet.pdp.serviceURL,
44
+ const deletePieceRsp = await SP.schedulePieceDeletion(connectorClient, {
45
+ serviceURL: dataSet.provider.pdp.serviceURL,
44
46
  dataSetId: dataSet.dataSetId,
45
47
  clientDataSetId: dataSet.clientDataSetId,
46
48
  pieceId,
47
49
  })
48
50
 
49
- props?.onHash?.(deletePieceRsp.txHash)
50
- const rsp = await pollForDeletePieceStatus(client, deletePieceRsp)
51
+ props?.onHash?.(deletePieceRsp.hash)
52
+ const rsp = await waitForTransactionReceipt(client, deletePieceRsp)
51
53
 
52
54
  queryClient.invalidateQueries({
53
- queryKey: ['synapse-warm-storage-data-sets', account.address],
55
+ queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
54
56
  })
55
57
  return rsp
56
58
  },
@@ -1,4 +1,4 @@
1
- import { type PDPProvider, readProviders } from '@filoz/synapse-core/warm-storage'
1
+ import { getApprovedPDPProviders } from '@filoz/synapse-core/sp-registry'
2
2
  import { type UseQueryOptions, useQuery } from '@tanstack/react-query'
3
3
  import { useConfig } from 'wagmi'
4
4
 
@@ -6,16 +6,16 @@ export interface UseProvidersProps {
6
6
  query?: Omit<UseQueryOptions<UseProvidersResult>, 'queryKey' | 'queryFn'>
7
7
  }
8
8
 
9
- export type UseProvidersResult = PDPProvider[]
9
+ export type UseProvidersResult = getApprovedPDPProviders.OutputType
10
10
 
11
11
  export function useProviders(props?: UseProvidersProps) {
12
12
  const config = useConfig()
13
13
 
14
14
  return useQuery({
15
15
  ...props?.query,
16
- queryKey: ['synapse-warm-storage-providers'],
16
+ queryKey: ['synapse-warm-storage-providers', config.getClient().chain.id],
17
17
  queryFn: () => {
18
- return readProviders(config.getClient())
18
+ return getApprovedPDPProviders(config.getClient())
19
19
  },
20
20
  })
21
21
  }
@@ -1,18 +1,18 @@
1
- import { type ServicePriceResult, servicePrice } from '@filoz/synapse-core/warm-storage'
1
+ import { getServicePrice } from '@filoz/synapse-core/warm-storage'
2
2
  import { type UseQueryOptions, useQuery } from '@tanstack/react-query'
3
3
  import { useConfig } from 'wagmi'
4
4
 
5
5
  /**
6
- * The props for the useServicePrice hook.
6
+ * The result for the useServicePrice hook.
7
7
  */
8
- export interface UseServicePriceProps {
9
- query?: Omit<UseQueryOptions<ServicePriceResult>, 'queryKey' | 'queryFn'>
10
- }
8
+ export type UseServicePriceResult = getServicePrice.OutputType
11
9
 
12
10
  /**
13
- * The result for the useServicePrice hook.
11
+ * The props for the useServicePrice hook.
14
12
  */
15
- export type UseServicePriceResult = ServicePriceResult
13
+ export interface UseServicePriceProps {
14
+ query?: Omit<UseQueryOptions<UseServicePriceResult>, 'queryKey' | 'queryFn'>
15
+ }
16
16
 
17
17
  /**
18
18
  * Get the service price for the warm storage.
@@ -25,9 +25,9 @@ export function useServicePrice(props?: UseServicePriceProps) {
25
25
 
26
26
  return useQuery({
27
27
  ...props?.query,
28
- queryKey: ['synapse-warm-storage-get-service-price'],
28
+ queryKey: ['synapse-warm-storage-get-service-price', config.getClient().chain.id],
29
29
  queryFn: async () => {
30
- const result = await servicePrice(config.getClient())
30
+ const result = await getServicePrice(config.getClient())
31
31
  return result
32
32
  },
33
33
  })
@@ -1,8 +1,7 @@
1
1
  import { getChain } from '@filoz/synapse-core/chains'
2
2
  import type { SessionKey } from '@filoz/synapse-core/session-key'
3
- import type { AddPiecesSuccess } from '@filoz/synapse-core/sp'
4
3
  import * as SP from '@filoz/synapse-core/sp'
5
- import { upload } from '@filoz/synapse-core/warm-storage'
4
+ import { type AddPiecesSuccess, upload } from '@filoz/synapse-core/sp'
6
5
  import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
7
6
  import { useAccount, useChainId, useConfig } from 'wagmi'
8
7
  import { getConnectorClient } from 'wagmi/actions'
@@ -45,10 +44,10 @@ export function useUpload(props: UseUploadProps) {
45
44
  })
46
45
 
47
46
  props?.onHash?.(uploadRsp.txHash)
48
- const rsp = await SP.pollForAddPiecesStatus(uploadRsp)
47
+ const rsp = await SP.waitForAddPieces(uploadRsp)
49
48
 
50
49
  queryClient.invalidateQueries({
51
- queryKey: ['synapse-warm-storage-data-sets', account.address],
50
+ queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
52
51
  })
53
52
  return rsp
54
53
  },