File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -387,6 +387,48 @@ export const readCoinBalances = (contractAddress: string, address: string) =>
387
387
} )
388
388
return coins
389
389
} )
390
+
391
+ export const getAllCoinsUnique = ( address : string ) =>
392
+ Effect . gen ( function * ( ) {
393
+ const client = ( yield * PublicClient ) . client
394
+
395
+ const params = {
396
+ owner : address ,
397
+ }
398
+
399
+ const coins = yield * Effect . tryPromise ( {
400
+ try : async ( ) => {
401
+ const result = await client . getAllCoins ( params )
402
+ return result . data
403
+ } ,
404
+ catch : err =>
405
+ new ReadCoinError ( {
406
+ cause : extractErrorDetails ( err as ReadCoinError ) ,
407
+ } ) ,
408
+ } )
409
+
410
+ // Group by coinType and sum balances
411
+ const coinMap : Record < string , bigint > = { }
412
+
413
+ for ( const coin of coins ) {
414
+ const coinType = coin . coinType
415
+ const balance = BigInt ( coin . balance )
416
+
417
+ if ( ! coinMap [ coinType ] ) {
418
+ coinMap [ coinType ] = balance
419
+ } else {
420
+ coinMap [ coinType ] += balance
421
+ }
422
+ }
423
+
424
+ // Convert to array of objects
425
+ const result = Object . entries ( coinMap ) . map ( ( [ coinType , totalBalance ] ) => ( {
426
+ coinType,
427
+ balance : totalBalance . toString ( ) , // or keep as BigInt if preferred
428
+ } ) )
429
+
430
+ return result
431
+ } )
390
432
391
433
// /**
392
434
// * Read the balance of an ERC20 token for a specific address
You can’t perform that action at this time.
0 commit comments