Skip to content

useBalance loads forever on a newly created wallet #165

@renra

Description

@renra

Describe the bug

A clear and concise description of what the bug is.

const { data, isLoading } = useBalance({ chainId: MyChainId, denom: MyDenom })

console.log(isLoading)

In case of a newly created wallet that has no balance, isLoading is always true which makes it look like the balance is loading forever where instead there's actually no balance.
...

To Reproduce

Steps to reproduce the behavior:

  1. Create an app that connects a wallet and displays a balance using useBalance
  2. Create a new wallet that has no coins
  3. Connect the wallet

Expected behavior

isLoading becomes false to indicate the balance has been loaded. data can continue to be undefined to indicate there is no balance.

Temporary workaround

const { isLoading, data } = useBalances({ chainId: MyChainId, denom: MyDenom })

const balance = isLoading 
  ? undefined
  : (data && data.find((coin) => coin.denom === MyDenom)) || { denom: MyDenom, amount: '0' }
  
return {
  data: balance,
  isLoading
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions