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

157
Visualizações
Is there a different way to provide different options for inquirer javascript inputs?
inquirer
.prompt([
    { type:'list',
    message: "Select an option",
    name: 'walletOptions',
    choices: [
        'Wallet',
        'Normal Transaction',
        'Arbitrage'
    ]}
])
.then(({walletOptions}) => {
    
    if (walletOptions === 'Wallet') {
        //let them view and edit wallet
        inquirer
            .prompt([
                { type:'list',
                message: "Select an account",
                name: 'accountOptions',
                choices: [
                    '1',
                    '2',
                    '3',
                    '<<< Quit'
                ]}
            ])
            .then(({accountOptions}) => {
                if (accountOptions === '1') {
                    //display account info for one
                    var walletOne = wallet[1]
                    console.log(walletOne);
                } else if (accountOptions === '2') {
                    //display account info for two
                    var walletTwo = wallet[2]
                    console.log(walletTwo);
                } else if (accountOptions === '3') {
                    //display account info for three
                    var walletThree = wallet[3]
                    console.log(walletThree);
                } else {
                    return ;
                }
        
            })
    
    } else if (walletOptions === 'Normal Transaction') {
        //continue with mainswap.js
        var normalTx = require("./mainswap");
        mainswap.deploy()
        
    } else {
        //continue with ...
    }
});

Instead of using a bunch of ifs is there a way to show different options for different selections rather than having to specify directly for each one like I am doing? I think there is the .when option but I am not really sure how to use it in this situation. I am trying to let them select the wallet option and then let them view the wallet that they choose. Also I cant seem to figure out how to send the user back to the beginning of the menu when they select the <<< quit key so any input into how to do that would be good

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