React Crypto Portfolio

hello,
I’m trying for several days now to complete my ‘componentDidMount’ function to retrieve my own list of crypto coins.
I added the “key” of each token to my coinData array. this is the most i could get but it still gives me an error : “Unhandled Rejection (TypeError): Cannot read property ‘USD’ of undefined”.
i’m a beginner so please its really working on my nerves.

componentDidMount= async () => {
const coinData = this.state.coinData.map(({name, ticker, price, key}) => {
Promise.all([
axios.get(‘https://api.coinpaprika.com/v1/tickers/’ + key)
]).then((coins)=> {
return {
key: coins.id,
name: coins.name,
ticker: coins.symbol,
balance: 1,
price: formatPrice(coins.quotes.USD.price)
}
})
});
this.setState({coinList:coinData})
}```

fixed it!
just had to make an array only with the key and itterate over it the same as in the lesson

const tickerUrl = `https://api.coinpaprika.com/v1/tickers/`
const coinIds = [ 
  "btc-bitcoin", 
  "eth-ethereum", 
  "xrp-xrp", 
]
componentDidMount= async () => {
      const newCoinData = coinIds.map(id => axios.get(tickerUrl + id));
      const coinData = await Promise.all(newCoinData);
      const coinPriceData = coinData.map(function(response) {
              const coin = response.data;
              return {
                key: coin.id,
                name: coin.name,
                ticker: coin.symbol,
                balance: 0,
                price: formatPrice(coin.quotes.USD.price)
              };
            })
            this.setState({coinData: coinPriceData});
    }
1 Like