Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: return explicit error if getBalancesFromProvider failed #142

Closed
olekon opened this issue May 15, 2023 · 2 comments
Closed

Comments

@olekon
Copy link

olekon commented May 15, 2023

Now it is almost impossible to know if getBalancesFromProvider failed, as it just swallows the error, prints console warning and returns amount: 0.

const getBalancesFromProvider = async (
  walletAddress: string,
  tokens: Token[]
): Promise<TokenAmount[]> => {
  const chainId = tokens[0].chainId
  const rpc = await getRpcProvider(chainId)
  const tokenAmountPromises: Promise<TokenAmount>[] = tokens.map(
    async (token): Promise<TokenAmount> => {
      let amount = '0'
      let blockNumber

      try {
        const balance = await getBalanceFromProvider(
          walletAddress,
          token.address,
          chainId,
          rpc
        )
        amount = new BigNumber(balance.amount.toString())
          .shiftedBy(-token.decimals)
          .toString()
        blockNumber = balance.blockNumber
      } catch (e) {
        // eslint-disable-next-line no-console
        console.warn(e)
      }

      return {
        ...token,
        amount,
        blockNumber,
      }
    }
  )
  return Promise.all(tokenAmountPromises)
}

Can we somehow indicate that there was an error? For example return Error object or set amount to null in that case?

@chybisov
Copy link
Member

Hi, this was made not to throw whenever RPCs have some issue because the next try can be successful, but maybe we should reconsider how we handle this.

@chybisov
Copy link
Member

The SDK v3 has been released. Please see the documentation here https://docs.li.fi/integrate-li.fi-sdk/li.fi-sdk-overview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants