import { DeployedWithoutEmailWallet } from '@unilogin/sdk' ; import { useState } from 'react' ; import { TokenDetailsWithBalance } from '@unilogin/commons' ; import { useAsyncEffect } from './useAsyncEffect' ; type GetBalanceBySymbol = ( symbol : string ) => TokenDetailsWithBalance | undefined ; export const useBalances = ( deployedWallet ) : [ TokenDetailsWithBalance [ ] , GetBalanceBySymbol ] => { const [ tokenDetailsWithBalance , setTokenDetailsWithBalance ] = useState < TokenDetailsWithBalance [ ] > ( [ ] ) ; useAsyncEffect ( ( ) => deployedWallet . subscribeToBalances ( setTokenDetailsWithBalance ) , [ ] ) ; const getBalanceBySymbol = ( symbol ) => tokenDetailsWithBalance . find ( ( token ) => token . symbol === symbol ) ; return [ tokenDetailsWithBalance , getBalanceBySymbol ] ; } ;