@filoz/synapse-react 0.1.3 → 0.2.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/dist/src/calibration.d.ts +1 -2
- package/dist/src/calibration.d.ts.map +1 -1
- package/dist/src/calibration.js.map +1 -1
- package/dist/src/erc20.d.ts +6 -7
- package/dist/src/erc20.d.ts.map +1 -1
- package/dist/src/erc20.js +1 -1
- package/dist/src/erc20.js.map +1 -1
- package/dist/src/filsnap.d.ts.map +1 -1
- package/dist/src/filsnap.js +3 -0
- package/dist/src/filsnap.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/payments/index.d.ts +13 -14
- package/dist/src/payments/index.d.ts.map +1 -1
- package/dist/src/payments/index.js +19 -20
- package/dist/src/payments/index.js.map +1 -1
- package/dist/src/payments/use-deposit-and-approve.d.ts +4 -5
- package/dist/src/payments/use-deposit-and-approve.d.ts.map +1 -1
- package/dist/src/payments/use-deposit-and-approve.js +1 -1
- package/dist/src/payments/use-deposit-and-approve.js.map +1 -1
- package/dist/src/warm-storage/use-create-data-set.d.ts +11 -5
- package/dist/src/warm-storage/use-create-data-set.d.ts.map +1 -1
- package/dist/src/warm-storage/use-create-data-set.js +3 -4
- package/dist/src/warm-storage/use-create-data-set.js.map +1 -1
- package/dist/src/warm-storage/use-data-sets.d.ts +11 -21
- package/dist/src/warm-storage/use-data-sets.d.ts.map +1 -1
- package/dist/src/warm-storage/use-data-sets.js +6 -22
- package/dist/src/warm-storage/use-data-sets.js.map +1 -1
- package/dist/src/warm-storage/use-delete-piece.d.ts +3 -3
- package/dist/src/warm-storage/use-delete-piece.d.ts.map +1 -1
- package/dist/src/warm-storage/use-delete-piece.js +6 -5
- package/dist/src/warm-storage/use-delete-piece.js.map +1 -1
- package/dist/src/warm-storage/use-providers.d.ts +3 -3
- package/dist/src/warm-storage/use-providers.d.ts.map +1 -1
- package/dist/src/warm-storage/use-providers.js +2 -2
- package/dist/src/warm-storage/use-providers.js.map +1 -1
- package/dist/src/warm-storage/use-service-price.d.ts +4 -4
- package/dist/src/warm-storage/use-service-price.d.ts.map +1 -1
- package/dist/src/warm-storage/use-service-price.js +2 -2
- package/dist/src/warm-storage/use-service-price.js.map +1 -1
- package/dist/src/warm-storage/use-upload.d.ts +10 -2
- package/dist/src/warm-storage/use-upload.d.ts.map +1 -1
- package/dist/src/warm-storage/use-upload.js +2 -2
- package/dist/src/warm-storage/use-upload.js.map +1 -1
- package/package.json +23 -9
- package/src/calibration.ts +3 -5
- package/src/erc20.ts +7 -7
- package/src/filsnap.ts +4 -0
- package/src/index.ts +0 -1
- package/src/payments/index.ts +36 -59
- package/src/payments/use-deposit-and-approve.ts +8 -12
- package/src/warm-storage/use-create-data-set.ts +6 -7
- package/src/warm-storage/use-data-sets.ts +7 -29
- package/src/warm-storage/use-delete-piece.ts +8 -6
- package/src/warm-storage/use-providers.ts +3 -3
- package/src/warm-storage/use-service-price.ts +8 -8
- package/src/warm-storage/use-upload.ts +2 -3
|
@@ -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
|
|
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,
|
|
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
|
-
* @
|
|
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 }:
|
|
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.
|
|
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 {
|
|
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<
|
|
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 =
|
|
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
|
-
|
|
41
|
+
serviceURL: provider.pdp.serviceURL,
|
|
43
42
|
cdn,
|
|
44
43
|
// metadata: {
|
|
45
44
|
// title: 'Test Data Set',
|
|
@@ -48,7 +47,7 @@ export function useCreateDataSet(props: UseCreateDataSetProps) {
|
|
|
48
47
|
})
|
|
49
48
|
props?.onHash?.(txHash)
|
|
50
49
|
|
|
51
|
-
const dataSet = await SP.
|
|
50
|
+
const dataSet = await SP.waitForCreateDataSet({ statusUrl })
|
|
52
51
|
|
|
53
52
|
queryClient.invalidateQueries({
|
|
54
53
|
queryKey: ['synapse-warm-storage-data-sets', account.address],
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
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 {
|
|
8
|
-
import { useChainId, useConfig } from 'wagmi'
|
|
5
|
+
import { useConfig } from 'wagmi'
|
|
9
6
|
|
|
10
|
-
export
|
|
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
22
|
queryKey: ['synapse-warm-storage-data-sets', address],
|
|
30
23
|
queryFn: address
|
|
31
24
|
? async () => {
|
|
32
|
-
const dataSets = await
|
|
25
|
+
const dataSets = await getPdpDataSets(config.getClient(), { address })
|
|
33
26
|
const dataSetsWithPieces = await Promise.all(
|
|
34
27
|
dataSets.map(async (dataSet) => {
|
|
35
|
-
const
|
|
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:
|
|
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
|
|
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:
|
|
21
|
+
dataSet: PdpDataSet
|
|
20
22
|
pieceId: bigint
|
|
21
23
|
}
|
|
22
24
|
export function useDeletePiece(props: UseDeletePieceProps) {
|
|
@@ -39,15 +41,15 @@ export function useDeletePiece(props: UseDeletePieceProps) {
|
|
|
39
41
|
connectorClient = props?.sessionKey.client(chain, client.transport)
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
const deletePieceRsp = await
|
|
43
|
-
|
|
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.
|
|
50
|
-
const rsp = await
|
|
51
|
+
props?.onHash?.(deletePieceRsp.hash)
|
|
52
|
+
const rsp = await waitForTransactionReceipt(client, deletePieceRsp)
|
|
51
53
|
|
|
52
54
|
queryClient.invalidateQueries({
|
|
53
55
|
queryKey: ['synapse-warm-storage-data-sets', account.address],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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,7 +6,7 @@ export interface UseProvidersProps {
|
|
|
6
6
|
query?: Omit<UseQueryOptions<UseProvidersResult>, 'queryKey' | 'queryFn'>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export type UseProvidersResult =
|
|
9
|
+
export type UseProvidersResult = getApprovedPDPProviders.OutputType
|
|
10
10
|
|
|
11
11
|
export function useProviders(props?: UseProvidersProps) {
|
|
12
12
|
const config = useConfig()
|
|
@@ -15,7 +15,7 @@ export function useProviders(props?: UseProvidersProps) {
|
|
|
15
15
|
...props?.query,
|
|
16
16
|
queryKey: ['synapse-warm-storage-providers'],
|
|
17
17
|
queryFn: () => {
|
|
18
|
-
return
|
|
18
|
+
return getApprovedPDPProviders(config.getClient())
|
|
19
19
|
},
|
|
20
20
|
})
|
|
21
21
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
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
|
|
6
|
+
* The result for the useServicePrice hook.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
9
|
-
query?: Omit<UseQueryOptions<ServicePriceResult>, 'queryKey' | 'queryFn'>
|
|
10
|
-
}
|
|
8
|
+
export type UseServicePriceResult = getServicePrice.OutputType
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
|
-
* The
|
|
11
|
+
* The props for the useServicePrice hook.
|
|
14
12
|
*/
|
|
15
|
-
export
|
|
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.
|
|
@@ -27,7 +27,7 @@ export function useServicePrice(props?: UseServicePriceProps) {
|
|
|
27
27
|
...props?.query,
|
|
28
28
|
queryKey: ['synapse-warm-storage-get-service-price'],
|
|
29
29
|
queryFn: async () => {
|
|
30
|
-
const result = await
|
|
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/
|
|
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,7 +44,7 @@ export function useUpload(props: UseUploadProps) {
|
|
|
45
44
|
})
|
|
46
45
|
|
|
47
46
|
props?.onHash?.(uploadRsp.txHash)
|
|
48
|
-
const rsp = await SP.
|
|
47
|
+
const rsp = await SP.waitForAddPieces(uploadRsp)
|
|
49
48
|
|
|
50
49
|
queryClient.invalidateQueries({
|
|
51
50
|
queryKey: ['synapse-warm-storage-data-sets', account.address],
|