sdk
sdk copied to clipboard
Feature request: return explicit error if getBalancesFromProvider failed
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?
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.
The SDK v3 has been released. Please see the documentation here https://docs.li.fi/integrate-li.fi-sdk/li.fi-sdk-overview