Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

79
Visualizações
Async Await but wrong?`

I am fairly new to this and aparently i have not understand async calls...

The function below makes in the case of "claimRewards" an Api call. i thought with Async Await the promise resolves to a useable value but instead the function returns a promise like:

amount: Promise {<fulfilled>: '198816.61958'} 

why is this the case. it does not matter if i wrap the async await around the fetchApi function or the transactionCases function, or leave it completely. i suspect im using it wrong but cannot figure out why this is the case! please help & and kind thank you for your advice.

async function transactionCases(cases, data) {
        const url = 'https://api.elrond.com/transactions?withOperations=true&hashes=' + data.txHash;

        switch (cases){
                        case 'claimRewards': 
                            const claimRewards = await fetchApi(url).then(data => {
                                var filtered = data[0].operations.filter(operation => operation.action.includes("addQuantity"))
                                return converttodecimals(filtered[0].value);
                            }); 
                            return claimRewards;
                            break;
                        default: "No Result";
                    }
    }

function fetchApi(url) {
    return fetch(url)
        .then(response => response.json())
        .then(data => data)
        .catch(error => console.log(error));
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda