* moved api/openingFee to hook * moved api/icns and api/balances to hooks * moved api/assetIncentivesApy to hooks * moved api/incentives to hooks * fix relative import
30 lines
766 B
TypeScript
30 lines
766 B
TypeScript
import useSWR from 'swr'
|
|
|
|
import useChainConfig from 'hooks/useChainConfig'
|
|
|
|
export default function useWalletBalances(address?: string) {
|
|
const chainConfig = useChainConfig()
|
|
|
|
return useSWR(
|
|
address && `chains/${chainConfig.id}/wallets/${address}/balances`,
|
|
() => getWalletBalances(chainConfig, address!),
|
|
{
|
|
isPaused: () => !address,
|
|
fallbackData: [],
|
|
},
|
|
)
|
|
}
|
|
|
|
async function getWalletBalances(chainConfig: ChainConfig, address: string): Promise<Coin[]> {
|
|
const uri = '/cosmos/bank/v1beta1/balances/'
|
|
|
|
const response = await fetch(`${chainConfig.endpoints.rest}${uri}${address}`)
|
|
|
|
if (response.ok) {
|
|
const data = await response.json()
|
|
return data.balances
|
|
}
|
|
|
|
return new Promise((_, reject) => reject('No data'))
|
|
}
|