11'use client' ;
22
3- import { useState , useRef , useCallback , useEffect } from 'react' ;
4- import { Upload , Download , File , Folder , Hash , Info , X , CheckCircle , AlertCircle , Plus , Database , ArrowLeft } from 'lucide-react' ;
5- import { type WalletClient , type PublicClient , formatEther } from 'viem' ;
3+ import { useState , useRef , useCallback } from 'react' ;
4+ import { Upload , Download , File , Folder , Hash , X , CheckCircle , AlertCircle , Plus , Database , ArrowLeft } from 'lucide-react' ;
5+ import { type WalletClient , type PublicClient } from 'viem' ;
66import { FileManager as StorageHubFileManager , initWasm , StorageHubClient , ReplicationLevel } from '@storagehub-sdk/core' ;
7- import { MspClient , type UploadReceipt , type DownloadResult , type Bucket , type FileListResponse , type FileTree , type DownloadOptions } from '@storagehub-sdk/msp-client' ;
7+ import { MspClient , type UploadReceipt , type Bucket , type FileTree } from '@storagehub-sdk/msp-client' ;
88import { TypeRegistry } from '@polkadot/types' ;
99import type { AccountId20 , H256 } from '@polkadot/types/interfaces' ;
1010
@@ -59,7 +59,7 @@ interface FileDownloadState {
5959 downloadError : string | null ;
6060}
6161
62- export function FileManager ( { walletClient , publicClient, walletAddress, mspClient, storageHubClient } : FileManagerProps ) {
62+ export function FileManager ( { publicClient, walletAddress, mspClient, storageHubClient } : FileManagerProps ) {
6363 const fileInputRef = useRef < HTMLInputElement > ( null ) ;
6464
6565 const [ uploadState , setUploadState ] = useState < FileUploadState > ( {
@@ -93,7 +93,6 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
9393
9494 const [ buckets , setBuckets ] = useState < Bucket [ ] > ( [ ] ) ;
9595 const [ selectedBucketId , setSelectedBucketId ] = useState < string > ( '' ) ;
96- const [ walletBalance , setWalletBalance ] = useState < string | null > ( null ) ;
9796 const [ isLoadingBuckets , setIsLoadingBuckets ] = useState < boolean > ( false ) ;
9897
9998 // File Browser State
@@ -112,21 +111,6 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
112111 downloadError : null ,
113112 } ) ;
114113
115- // Get wallet balance
116- useEffect ( ( ) => {
117- const getBalance = async ( ) => {
118- if ( publicClient && walletAddress ) {
119- try {
120- const balance = await publicClient . getBalance ( { address : walletAddress as `0x${string } ` } ) ;
121- setWalletBalance ( formatEther ( balance ) ) ;
122- } catch ( error ) {
123- console . error ( 'Failed to get balance:' , error ) ;
124- }
125- }
126- } ;
127- getBalance ( ) ;
128- } , [ publicClient , walletAddress ] ) ;
129-
130114 // File selection handler
131115 const handleFileSelect = useCallback ( async ( file : File ) => {
132116 setUploadState ( prev => ( {
@@ -224,7 +208,7 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
224208 } else {
225209 throw new Error ( 'Bucket creation transaction failed' ) ;
226210 }
227- } catch ( error : any ) {
211+ } catch ( error : unknown ) {
228212 console . error ( 'Bucket creation failed:' , error ) ;
229213 setBucketState ( prev => ( {
230214 ...prev ,
@@ -245,20 +229,20 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
245229
246230 try {
247231
248- let bucketList : any [ ] = [ ] ;
232+ let bucketList : Bucket [ ] = [ ] ;
249233 try {
250234 bucketList = await mspClient . buckets . listBuckets ( ) ;
251- } catch ( sdkError : any ) {
252- console . error ( '❌ Failed to load buckets:' , sdkError ? .message || sdkError ) ;
235+ } catch ( sdkError : unknown ) {
236+ console . error ( '❌ Failed to load buckets:' , sdkError instanceof Error ? sdkError . message : sdkError ) ;
253237 bucketList = [ ] ; // Fallback to empty array
254238 }
255239
256240 // Replace all buckets with the fresh list from MSP backend
257241 const freshBuckets = bucketList || [ ] ;
258242 setBuckets ( freshBuckets ) ;
259243
260- } catch ( error : any ) {
261- console . error ( '❌ Failed to refresh buckets:' , error ? .message || error ) ;
244+ } catch ( error : unknown ) {
245+ console . error ( '❌ Failed to refresh buckets:' , error instanceof Error ? error . message : error ) ;
262246 } finally {
263247 setIsLoadingBuckets ( false ) ;
264248 }
@@ -308,7 +292,7 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
308292
309293 console . log ( `📁 Loaded ${ extractedFiles . length } files` ) ;
310294
311- } catch ( error : any ) {
295+ } catch ( error : unknown ) {
312296 console . error ( '❌ Failed to load files:' , error ) ;
313297 setFileBrowserState ( prev => ( {
314298 ...prev ,
@@ -385,9 +369,8 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
385369 }
386370
387371 const bucketIdH256 = registry . createType ( "H256" , bucketIdForH256 ) as H256 ;
388- const fileKey = await fileManager . computeFileKey ( owner , bucketIdH256 , fileLocation ) ;
389-
390-
372+ // File key is computed by the MSP backend during upload
373+ await fileManager . computeFileKey ( owner , bucketIdH256 , fileLocation ) ;
391374
392375 setUploadState ( prev => ( { ...prev , uploadProgress : 25 } ) ) ;
393376
@@ -413,8 +396,8 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
413396 0 // replicas (used only when ReplicationLevel = Custom, like sdk-precompiles)
414397 // No gas options - let it estimate naturally like sdk-precompiles
415398 ) ;
416- } catch ( error : any ) {
417- console . error ( '❌ Storage request failed:' , error ? .message || error ) ;
399+ } catch ( error : unknown ) {
400+ console . error ( '❌ Storage request failed:' , error instanceof Error ? error . message : error ) ;
418401 throw error ;
419402 }
420403
@@ -451,8 +434,8 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
451434 fileLocation // location parameter like sdk-precompiles
452435 ) ;
453436
454- } catch ( error : any ) {
455- console . error ( '❌ MSP upload failed:' , error ? .message || error ) ;
437+ } catch ( error : unknown ) {
438+ console . error ( '❌ MSP upload failed:' , error instanceof Error ? error . message : error ) ;
456439 throw error ;
457440 }
458441
@@ -465,7 +448,7 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
465448 uploadProgress : 100
466449 } ) ) ;
467450
468- } catch ( error : any ) {
451+ } catch ( error : unknown ) {
469452 console . error ( 'Upload failed:' , error ) ;
470453 setUploadState ( prev => ( {
471454 ...prev ,
@@ -803,7 +786,7 @@ export function FileManager({ walletClient, publicClient, walletAddress, mspClie
803786
804787 console . log ( '✅ File download completed:' , file . name ) ;
805788
806- } catch ( error : any ) {
789+ } catch ( error : unknown ) {
807790 console . error ( '❌ Download failed:' , error ) ;
808791 setDownloadState ( prev => ( {
809792 ...prev ,
0 commit comments