File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -344,6 +344,31 @@ export const readCoinBalances = (contractAddress: string, address: string) =>
344
344
return coins
345
345
} )
346
346
347
+ export const readTotalCoinBalance = ( contractAddress : string , address : string ) =>
348
+ Effect . gen ( function * ( ) {
349
+ const client = ( yield * PublicClient ) . client
350
+ let params = {
351
+ owner : address ,
352
+ coinType : contractAddress ,
353
+ }
354
+
355
+ const coins = yield * Effect . tryPromise ( {
356
+ try : async ( ) => {
357
+ const result = await client . getCoins ( params )
358
+ return result . data
359
+ } ,
360
+ catch : err =>
361
+ new ReadCoinError ( {
362
+ cause : extractErrorDetails ( err as ReadCoinError ) ,
363
+ } ) ,
364
+ } )
365
+ // Calculate total balance
366
+ const totalBalance = coins . reduce ( ( acc , coin ) => acc + BigInt ( coin . balance ) , BigInt ( 0 ) )
367
+
368
+ return totalBalance
369
+ } )
370
+
371
+
347
372
// /**
348
373
// * Read the balance of an ERC20 token for a specific address
349
374
// *
You can’t perform that action at this time.
0 commit comments