@filoz/synapse-react 0.2.2 → 0.2.3
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/warm-storage/index.d.ts +1 -0
- package/dist/src/warm-storage/index.d.ts.map +1 -1
- package/dist/src/warm-storage/index.js +1 -0
- package/dist/src/warm-storage/index.js.map +1 -1
- package/dist/src/warm-storage/use-data-sets.d.ts +2 -2
- package/dist/src/warm-storage/use-upload-simple.d.ts +20 -0
- package/dist/src/warm-storage/use-upload-simple.d.ts.map +1 -0
- package/dist/src/warm-storage/use-upload-simple.js +31 -0
- package/dist/src/warm-storage/use-upload-simple.js.map +1 -0
- package/dist/src/warm-storage/use-upload.d.ts +8 -15
- package/dist/src/warm-storage/use-upload.d.ts.map +1 -1
- package/dist/src/warm-storage/use-upload.js +12 -10
- package/dist/src/warm-storage/use-upload.js.map +1 -1
- package/package.json +8 -6
- package/src/warm-storage/index.ts +1 -0
- package/src/warm-storage/use-upload-simple.ts +47 -0
- package/src/warm-storage/use-upload.ts +18 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA"}
|
|
@@ -25,8 +25,8 @@ export declare function useDataSets(props: UseDataSetsProps): import("@tanstack/
|
|
|
25
25
|
live: boolean;
|
|
26
26
|
managed: boolean;
|
|
27
27
|
cdn: boolean;
|
|
28
|
-
metadata: import("@filoz/synapse-
|
|
29
|
-
provider: import("@filoz/synapse-
|
|
28
|
+
metadata: import("@filoz/synapse-sdk").MetadataObject;
|
|
29
|
+
provider: import("@filoz/synapse-sdk").PDPProvider;
|
|
30
30
|
activePieceCount: bigint;
|
|
31
31
|
}[], Error>;
|
|
32
32
|
//# sourceMappingURL=use-data-sets.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AddPiecesSuccess } from '@filoz/synapse-core/sp';
|
|
2
|
+
import { type MutateOptions } from '@tanstack/react-query';
|
|
3
|
+
export interface UseUploadSimpleProps {
|
|
4
|
+
onHash?: (hash: string) => void;
|
|
5
|
+
mutation?: Omit<MutateOptions<AddPiecesSuccess, Error, UseUploadSimpleVariables>, 'mutationFn'>;
|
|
6
|
+
}
|
|
7
|
+
export interface UseUploadSimpleVariables {
|
|
8
|
+
files: File[];
|
|
9
|
+
dataSetId: bigint;
|
|
10
|
+
}
|
|
11
|
+
export declare function useUploadSimple(props: UseUploadSimpleProps): import("@tanstack/react-query").UseMutationResult<{
|
|
12
|
+
txHash: `0x${string}`;
|
|
13
|
+
txStatus: "confirmed";
|
|
14
|
+
dataSetId: bigint;
|
|
15
|
+
pieceCount: number;
|
|
16
|
+
addMessageOk: true;
|
|
17
|
+
piecesAdded: true;
|
|
18
|
+
confirmedPieceIds: bigint[];
|
|
19
|
+
}, Error, UseUploadSimpleVariables, unknown>;
|
|
20
|
+
//# sourceMappingURL=use-upload-simple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-upload-simple.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-upload-simple.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAU,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,KAAK,aAAa,EAA+B,MAAM,uBAAuB,CAAA;AAIvF,MAAM,WAAW,oBAAoB;IAInC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,QAAQ,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,KAAK,EAAE,wBAAwB,CAAC,EAAE,YAAY,CAAC,CAAA;CAChG;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB;AACD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;;;6CA4B1D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as SP from '@filoz/synapse-core/sp';
|
|
2
|
+
import { upload } from '@filoz/synapse-core/sp';
|
|
3
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { useChainId, useConfig, useConnection } from 'wagmi';
|
|
5
|
+
import { getConnectorClient } from 'wagmi/actions';
|
|
6
|
+
export function useUploadSimple(props) {
|
|
7
|
+
const config = useConfig();
|
|
8
|
+
const chainId = useChainId({ config });
|
|
9
|
+
const account = useConnection({ config });
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
return useMutation({
|
|
12
|
+
...props?.mutation,
|
|
13
|
+
mutationFn: async ({ files, dataSetId }) => {
|
|
14
|
+
const connectorClient = await getConnectorClient(config, {
|
|
15
|
+
account: account.address,
|
|
16
|
+
chainId,
|
|
17
|
+
});
|
|
18
|
+
const uploadRsp = await upload(connectorClient, {
|
|
19
|
+
dataSetId,
|
|
20
|
+
data: files,
|
|
21
|
+
});
|
|
22
|
+
props?.onHash?.(uploadRsp.txHash);
|
|
23
|
+
const rsp = await SP.waitForAddPieces(uploadRsp);
|
|
24
|
+
queryClient.invalidateQueries({
|
|
25
|
+
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|
|
26
|
+
});
|
|
27
|
+
return rsp;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=use-upload-simple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-upload-simple.js","sourceRoot":"","sources":["../../../src/warm-storage/use-upload-simple.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC5C,OAAO,EAAyB,MAAM,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAsB,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAclD,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IACtC,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IACzC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,OAAO,WAAW,CAAC;QACjB,GAAG,KAAK,EAAE,QAAQ;QAClB,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAA4B,EAAE,EAAE;YACnE,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE;gBACvD,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,OAAO;aACR,CAAC,CAAA;YAEF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE;gBAC9C,SAAS;gBACT,IAAI,EAAE,KAAK;aACZ,CAAC,CAAA;YAEF,KAAK,EAAE,MAAM,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;YACjC,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAA;YAEhD,WAAW,CAAC,iBAAiB,CAAC;gBAC5B,QAAQ,EAAE,CAAC,gCAAgC,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;aAC3F,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UploadResult } from '@filoz/synapse-sdk';
|
|
2
|
+
import type { StorageManagerUploadOptions } from '@filoz/synapse-sdk/storage';
|
|
2
3
|
import { type MutateOptions } from '@tanstack/react-query';
|
|
3
|
-
export interface UseUploadProps {
|
|
4
|
-
|
|
5
|
-
mutation?: Omit<MutateOptions<
|
|
4
|
+
export interface UseUploadProps extends Omit<StorageManagerUploadOptions, 'contexts' | 'pieceMetadata'> {
|
|
5
|
+
source: string | null;
|
|
6
|
+
mutation?: Omit<MutateOptions<UploadResult, Error, UseUploadVariables>, 'mutationFn'>;
|
|
6
7
|
}
|
|
7
8
|
export interface UseUploadVariables {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
file: File;
|
|
10
|
+
metadata?: Record<string, string>;
|
|
10
11
|
}
|
|
11
|
-
export declare function useUpload(props: UseUploadProps): import("@tanstack/react-query").UseMutationResult<
|
|
12
|
-
txHash: `0x${string}`;
|
|
13
|
-
txStatus: "confirmed";
|
|
14
|
-
dataSetId: bigint;
|
|
15
|
-
pieceCount: number;
|
|
16
|
-
addMessageOk: true;
|
|
17
|
-
piecesAdded: true;
|
|
18
|
-
confirmedPieceIds: bigint[];
|
|
19
|
-
}, Error, UseUploadVariables, unknown>;
|
|
12
|
+
export declare function useUpload(props: UseUploadProps): import("@tanstack/react-query").UseMutationResult<UploadResult, Error, UseUploadVariables, unknown>;
|
|
20
13
|
//# sourceMappingURL=use-upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAC7E,OAAO,EAAE,KAAK,aAAa,EAA+B,MAAM,uBAAuB,CAAA;AAIvF,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,2BAA2B,EAAE,UAAU,GAAG,eAAe,CAAC;IACrG,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,QAAQ,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,EAAE,kBAAkB,CAAC,EAAE,YAAY,CAAC,CAAA;CACtF;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,uGA8B9C"}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { asClient } from '@filoz/synapse-core/chains';
|
|
2
|
+
import { Synapse } from '@filoz/synapse-sdk';
|
|
3
3
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
import {
|
|
4
|
+
import { useChainId, useConfig, useConnection } from 'wagmi';
|
|
5
5
|
import { getConnectorClient } from 'wagmi/actions';
|
|
6
6
|
export function useUpload(props) {
|
|
7
7
|
const config = useConfig();
|
|
8
8
|
const chainId = useChainId({ config });
|
|
9
|
-
const account =
|
|
9
|
+
const account = useConnection({ config });
|
|
10
10
|
const queryClient = useQueryClient();
|
|
11
11
|
return useMutation({
|
|
12
12
|
...props?.mutation,
|
|
13
|
-
mutationFn: async ({
|
|
13
|
+
mutationFn: async ({ file, metadata }) => {
|
|
14
14
|
const connectorClient = await getConnectorClient(config, {
|
|
15
15
|
account: account.address,
|
|
16
16
|
chainId,
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const synapse = new Synapse({
|
|
19
|
+
client: asClient(connectorClient),
|
|
20
|
+
source: props.source,
|
|
21
|
+
});
|
|
22
|
+
const rsp = await synapse.storage.upload(new Uint8Array(await file.arrayBuffer()), {
|
|
23
|
+
...props,
|
|
24
|
+
pieceMetadata: metadata,
|
|
21
25
|
});
|
|
22
|
-
props?.onHash?.(uploadRsp.txHash);
|
|
23
|
-
const rsp = await SP.waitForAddPieces(uploadRsp);
|
|
24
26
|
queryClient.invalidateQueries({
|
|
25
27
|
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|
|
26
28
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-upload.js","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-upload.js","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,OAAO,EAAqB,MAAM,oBAAoB,CAAA;AAE/D,OAAO,EAAsB,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAWlD,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IACtC,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IACzC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,OAAO,WAAW,CAAC;QACjB,GAAG,KAAK,EAAE,QAAQ;QAClB,UAAU,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAsB,EAAE,EAAE;YAC3D,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE;gBACvD,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,OAAO;aACR,CAAC,CAAA;YAEF,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;gBAC1B,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC;gBACjC,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAA;YAEF,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;gBACjF,GAAG,KAAK;gBACR,aAAa,EAAE,QAAQ;aACxB,CAAC,CAAA;YAEF,WAAW,CAAC,iBAAiB,CAAC;gBAC5B,QAAQ,EAAE,CAAC,gCAAgC,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;aAC3F,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@filoz/synapse-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "React hooks for interacting with Filecoin Onchain Cloud smart contracts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -60,7 +60,8 @@
|
|
|
60
60
|
"dist/**"
|
|
61
61
|
],
|
|
62
62
|
"dependencies": [
|
|
63
|
-
"../synapse-core:build"
|
|
63
|
+
"../synapse-core:build",
|
|
64
|
+
"../synapse-sdk:build"
|
|
64
65
|
]
|
|
65
66
|
},
|
|
66
67
|
"lint": {
|
|
@@ -77,14 +78,15 @@
|
|
|
77
78
|
},
|
|
78
79
|
"dependencies": {
|
|
79
80
|
"@hugomrdias/filsnap-adapter": "^3.3.8",
|
|
80
|
-
"@filoz/synapse-
|
|
81
|
+
"@filoz/synapse-sdk": "^0.40.1",
|
|
82
|
+
"@filoz/synapse-core": "^0.3.3"
|
|
81
83
|
},
|
|
82
84
|
"devDependencies": {
|
|
83
|
-
"@biomejs/biome": "2.4.
|
|
84
|
-
"@types/node": "^25.
|
|
85
|
+
"@biomejs/biome": "2.4.8",
|
|
86
|
+
"@types/node": "^25.3.5",
|
|
85
87
|
"type-fest": "^5.4.3",
|
|
86
88
|
"typescript": "5.9.3",
|
|
87
|
-
"viem": "^2.
|
|
89
|
+
"viem": "^2.47.0"
|
|
88
90
|
},
|
|
89
91
|
"publishConfig": {
|
|
90
92
|
"access": "public"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as SP from '@filoz/synapse-core/sp'
|
|
2
|
+
import { type AddPiecesSuccess, upload } from '@filoz/synapse-core/sp'
|
|
3
|
+
import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
4
|
+
import { useChainId, useConfig, useConnection } from 'wagmi'
|
|
5
|
+
import { getConnectorClient } from 'wagmi/actions'
|
|
6
|
+
|
|
7
|
+
export interface UseUploadSimpleProps {
|
|
8
|
+
/**
|
|
9
|
+
* The callback to call when the hash is available.
|
|
10
|
+
*/
|
|
11
|
+
onHash?: (hash: string) => void
|
|
12
|
+
mutation?: Omit<MutateOptions<AddPiecesSuccess, Error, UseUploadSimpleVariables>, 'mutationFn'>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UseUploadSimpleVariables {
|
|
16
|
+
files: File[]
|
|
17
|
+
dataSetId: bigint
|
|
18
|
+
}
|
|
19
|
+
export function useUploadSimple(props: UseUploadSimpleProps) {
|
|
20
|
+
const config = useConfig()
|
|
21
|
+
const chainId = useChainId({ config })
|
|
22
|
+
const account = useConnection({ config })
|
|
23
|
+
const queryClient = useQueryClient()
|
|
24
|
+
|
|
25
|
+
return useMutation({
|
|
26
|
+
...props?.mutation,
|
|
27
|
+
mutationFn: async ({ files, dataSetId }: UseUploadSimpleVariables) => {
|
|
28
|
+
const connectorClient = await getConnectorClient(config, {
|
|
29
|
+
account: account.address,
|
|
30
|
+
chainId,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const uploadRsp = await upload(connectorClient, {
|
|
34
|
+
dataSetId,
|
|
35
|
+
data: files,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
props?.onHash?.(uploadRsp.txHash)
|
|
39
|
+
const rsp = await SP.waitForAddPieces(uploadRsp)
|
|
40
|
+
|
|
41
|
+
queryClient.invalidateQueries({
|
|
42
|
+
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|
|
43
|
+
})
|
|
44
|
+
return rsp
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type
|
|
1
|
+
import { asClient } from '@filoz/synapse-core/chains'
|
|
2
|
+
import { Synapse, type UploadResult } from '@filoz/synapse-sdk'
|
|
3
|
+
import type { StorageManagerUploadOptions } from '@filoz/synapse-sdk/storage'
|
|
3
4
|
import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
4
|
-
import {
|
|
5
|
+
import { useChainId, useConfig, useConnection } from 'wagmi'
|
|
5
6
|
import { getConnectorClient } from 'wagmi/actions'
|
|
6
7
|
|
|
7
|
-
export interface UseUploadProps {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
onHash?: (hash: string) => void
|
|
12
|
-
mutation?: Omit<MutateOptions<AddPiecesSuccess, Error, UseUploadVariables>, 'mutationFn'>
|
|
8
|
+
export interface UseUploadProps extends Omit<StorageManagerUploadOptions, 'contexts' | 'pieceMetadata'> {
|
|
9
|
+
source: string | null
|
|
10
|
+
mutation?: Omit<MutateOptions<UploadResult, Error, UseUploadVariables>, 'mutationFn'>
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
export interface UseUploadVariables {
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
file: File
|
|
15
|
+
metadata?: Record<string, string>
|
|
18
16
|
}
|
|
19
17
|
export function useUpload(props: UseUploadProps) {
|
|
20
18
|
const config = useConfig()
|
|
21
19
|
const chainId = useChainId({ config })
|
|
22
|
-
const account =
|
|
20
|
+
const account = useConnection({ config })
|
|
23
21
|
const queryClient = useQueryClient()
|
|
24
22
|
|
|
25
23
|
return useMutation({
|
|
26
24
|
...props?.mutation,
|
|
27
|
-
mutationFn: async ({
|
|
25
|
+
mutationFn: async ({ file, metadata }: UseUploadVariables) => {
|
|
28
26
|
const connectorClient = await getConnectorClient(config, {
|
|
29
27
|
account: account.address,
|
|
30
28
|
chainId,
|
|
31
29
|
})
|
|
32
30
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const synapse = new Synapse({
|
|
32
|
+
client: asClient(connectorClient),
|
|
33
|
+
source: props.source,
|
|
36
34
|
})
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const rsp = await synapse.storage.upload(new Uint8Array(await file.arrayBuffer()), {
|
|
37
|
+
...props,
|
|
38
|
+
pieceMetadata: metadata,
|
|
39
|
+
})
|
|
40
40
|
|
|
41
41
|
queryClient.invalidateQueries({
|
|
42
42
|
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|