0

Why protocols.usd is always returning 0? I try making a dummy promise function to test it and it's working properly but it's not working with the await function.

async function addPrices() {
    const balances = await getBalances();

    await Promise.all(balances.map(protocols => {
        protocols.usd = 0;

        protocols.balances.map(balance => {
            if (balance.underlying) {
                balance.underlying.map(async token => {
                    let price = await getPrice(token.address);
                    protocols.usd += price.market_data.current_price.usd;
                });
            }
        });
    }));
    return balances;
}
  • 1
    you aren't returning anything in `protocols => {` - or `balance => {` - so, there's no actual promises in the array Promise.all is processing – Jaromanda X Sep 11 '20 at 04:46
  • you **may** need `return await Promise.all(protocols.balances.map(balance => { .... }))` and `return await Promise.all(balance.underlying.map(async token => { .... }))` – Jaromanda X Sep 11 '20 at 04:50

0 Answers0