0

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 can't 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.

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 ...
    }
});
Nat Riddle
  • 928
  • 1
  • 10
  • 24
Reece
  • 1
  • 3

1 Answers1

0

Use "rawlist" instead of "list" in the type attribute as in the Official Example

Also remove the unwanted "}" after the choices list.

SH3LDR0ID
  • 1
  • 2