How to use the readline-sync.keyInSelect function in readline-sync

To help you get started, we’ve selected a few readline-sync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PolymathNetwork / polymath-core / CLI / commands / module_manager.js View on Github external
function backToMenu() {
    let options = ['Return to Menu','Exit'];
    let index = readlineSync.keyInSelect(options, chalk.yellow('What do you want to do?'), {cancel: false});
    switch (index) {
        case 0:
            break;
        case 1:
            process.exit();
    }
}
github PolymathNetwork / polymath-core / CLI / commands / token_manager.js View on Github external
async function addModule() {
  let options = ['Permission Manager', 'Transfer Manager', 'Security Token Offering', 'Dividends', 'Burn'];
  let index = readlineSync.keyInSelect(options, 'What type of module would you like to add?', { cancel: 'Return' });
  switch (options[index]) {
    case 'Permission Manager':
      console.log(chalk.red(`
    *********************************
    This option is not yet available.
    *********************************`));
      break;
    case 'Transfer Manager':
      await transferManager.addTransferManagerModule(tokenSymbol)
      break;
    case 'Security Token Offering':
      await stoManager.addSTOModule(tokenSymbol)
      break;
    case 'Dividends':
      console.log(chalk.red(`
    *********************************
github PolymathNetwork / polymath-core / CLI / commands / dividends_manager.js View on Github external
if (typeof filter.reclaimed !== 'undefined') {
      dividends = dividends.filter(d => filter.reclaimed == d.reclaimed);
    }
  }

  if (dividends.length > 0) {
    let options = dividends.map(function(d) {
      return `Created: ${moment.unix(d.created).format('MMMM Do YYYY, HH:mm:ss')}
    Maturity: ${moment.unix(d.maturity).format('MMMM Do YYYY, HH:mm:ss')}
    Expiry: ${moment.unix(d.expiry).format('MMMM Do YYYY, HH:mm:ss')}
    Amount: ${web3.utils.fromWei(d.amount)} ${dividendsType}
    Claimed Amount: ${web3.utils.fromWei(d.claimedAmount)} ${dividendsType}
    At checkpoint: ${d.checkpointId}`
    });

    let index = readlineSync.keyInSelect(options, 'Select a dividend:');
    if (index != -1) {
      result = dividends[index];
    }
  } else {
    console.log(chalk.red(`No dividends were found meeting the requirements`))
    console.log(chalk.red(`Requirements: Valid: ${filter.valid} - Expired: ${filter.expired} - Reclaimed: ${filter.reclaimed}\n`))
  }

  return result;
}
github PolymathNetwork / polymath-core / CLI / commands / ST20Generator.js View on Github external
let result;
  let userTickers = (await securityTokenRegistry.methods.getTickersByOwner(Issuer.address).call()).map(t => web3.utils.hexToAscii(t));
  let options = await Promise.all(userTickers.map(async function (t) {
    let tickerDetails = await securityTokenRegistry.methods.getTickerDetails(t).call();
    let tickerInfo;
    if (tickerDetails[4]) {
      tickerInfo = `Token launched at ${(await securityTokenRegistry.methods.getSecurityTokenAddress(t).call())}`;
    } else {
      tickerInfo = `Expires at ${moment.unix(tickerDetails[2]).format('MMMM Do YYYY, HH:mm:ss')}`;
    }
    return `${t}
    ${tickerInfo}`;
  }));
  options.push('Register a new ticker');

  let index = readlineSync.keyInSelect(options, 'Select a ticker:');
  if (index == -1) {
    process.exit(0);
  } else if (index == options.length - 1) {
    result = readlineSync.question('Enter a symbol for your new ticker: ');
  } else {
    result = userTickers[index];
  }

  return result;
}
github PolymathNetwork / polymath-core / CLI / commands / transfer_manager.js View on Github external
nonArchivedModules.map(m => console.log(`- ${m.name} at ${m.address}`))
  } else {
    console.log(`There are no Transfer Manager modules attached`);
  }

  let options = ['Verify transfer', 'Transfer'];
  let forcedTransferDisabled = await securityToken.methods.controllerDisabled().call();
  if (!forcedTransferDisabled) {
    options.push('Forced transfers');
  }
  if (nonArchivedModules.length > 0) {
    options.push('Config existing modules');
  }
  options.push('Add new Transfer Manager module');

  let index = readlineSync.keyInSelect(options, 'What do you want to do?', { cancel: 'EXIT' });
  let optionSelected = index !== -1 ? options[index] : 'EXIT';
  console.log('Selected:', optionSelected, '\n');
  switch (optionSelected) {
    case 'Verify transfer':
      let verifyTransferFrom = readlineSync.question(`Enter the sender account (${Issuer.address}): `, {
        limit: function (input) {
          return web3.utils.isAddress(input);
        },
        limitMessage: "Must be a valid address",
        defaultInput: Issuer.address
      });
      let verifyFromBalance = web3.utils.fromWei(await securityToken.methods.balanceOf(verifyTransferFrom).call());
      console.log(chalk.yellow(`Balance of ${verifyTransferFrom}: ${verifyFromBalance} ${tokenSymbol}`));
      let verifyTransferTo = readlineSync.question('Enter the receiver account: ', {
        limit: function (input) {
          return web3.utils.isAddress(input);
github PolymathNetwork / polymath-core / CLI / commands / transfer_manager.js View on Github external
case 'Check if investor is whitelisted':
      let investorToCheck = readlineSync.question('Enter the address of the investor: ', {
        limit: function (input) {
          return web3.utils.isAddress(input);
        },
        limitMessage: "Must be a valid address"
      });
      let isWhitelisted = await currentTransferManager.methods.whitelist(investorToCheck).call();
      if (isWhitelisted) {
        console.log(chalk.green(`${investorToCheck} is whitelisted!`));
      } else {
        console.log(chalk.yellow(`${investorToCheck} is not whitelisted!`));
      }
      break;
    case 'Modify whitelist':
      let valid = !!readlineSync.keyInSelect(['Remove investor from whitelist', 'Add investor to whitelist'], 'How do you want to do? ', { cancel: false });
      let investorToWhitelist = readlineSync.question('Enter the address of the investor: ', {
        limit: function (input) {
          return web3.utils.isAddress(input);
        },
        limitMessage: "Must be a valid address"
      });
      let modifyWhitelistAction = currentTransferManager.methods.modifyWhitelist(investorToWhitelist, valid);
      let modifyWhitelistReceipt = await common.sendTransaction(modifyWhitelistAction);
      let modifyWhitelistEvent = common.getEventFromLogs(currentTransferManager._jsonInterface, modifyWhitelistReceipt.logs, 'ModifyWhitelist');
      if (modifyWhitelistEvent._valid) {
        console.log(chalk.green(`${modifyWhitelistEvent._investor} has been added to the whitelist sucessfully!`));
      } else {
        console.log(chalk.green(`${modifyWhitelistEvent._investor} has been removed from the whitelist sucessfully!`));
      }
      break;
    case 'Modify whitelist from CSV':
github PolymathNetwork / polymath-core / CLI / commands / voting_manager.js View on Github external
}
  if (allBalotsToShow.length > 0) {
    options.push('Manage existing ballots');
  }
  if (allBalotsToShow.length < 500) {
    options.push('Create a new ballot');
  }
  if (pendingCommitBallots.length > 0) {
    options.push('Commit vote');
  }
  if (pendingRevealBallots.length > 0) {
    options.push('Reveal vote');
  }
  options.push('Reclaim ETH or ERC20 tokens from contract');

  const index = readlineSync.keyInSelect(options, 'What do you want to do?', { cancel: 'RETURN' });
  const selected = index !== -1 ? options[index] : 'RETURN';
  console.log('Selected:', selected, '\n');
  switch (selected) {
    case 'Create checkpoint':
      await createCheckpointFromModule();
      break;
    case 'Explore checkpoint':
      const checkpoint = await selectCheckpoint(false)
      await exploreCheckpoint(checkpoint);
      break;
    case 'Show current exempted voters by default':
      showAddresses('Current exempted voters by default:', defaultExemptedVoters);
      break;
    case 'Add or remove exempted voters by default':
      await addOrRemoveExemptedVoters();
      break;
github PolymathNetwork / polymath-core / CLI / commands / token_manager.js View on Github external
async function removeModule(modules) {
  let options = modules.map(m => `${m.name} (${m.version}) at ${m.address}`);
  let index = readlineSync.keyInSelect(options, 'Which module would you like to remove?');
  if (index != -1) {
    console.log("\nSelected: ", options[index]);
    let removeModuleAction = securityToken.methods.removeModule(modules[index].address);
    await common.sendTransaction(removeModuleAction, { factor: 2 });
    console.log(chalk.green(`${modules[index].name} has been removed successfully!`));
  }
}
github nethruster / nethloader-backend / src / installer / index.js View on Github external
.catch(err => {
      if (err.name === 'SequelizeConnectionError') {
        console.log('Can not connect to the database.')
        let answer = readLine.keyInSelect(['Try again.', 'Close the installer'], 'What do you want to do?')
        if (answer === 0) {
          dbSync(force)
        } else {
          return false
        }
      } else {
        console.error(err)
      }
    })
}
github PolymathNetwork / polymath-core / CLI / commands / dividends_manager.js View on Github external
async function selectCheckpoint(includeCreate) {
  if (await securityToken.methods.currentCheckpointId().call() > 0) {
    let options = [];
    let fix = 1; //Checkpoint 0 is not included, so I need to add 1 to fit indexes for checkpoints and options
    let checkpoints = (await getCheckpoints()).map(function (c) { return c.timestamp });
    if (includeCreate) {
      options.push('Create new checkpoint');
      fix = 0; //If this option is added, fix isn't needed.
    }
    options = options.concat(checkpoints);

    return readlineSync.keyInSelect(options, 'Select a checkpoint:', { cancel: false }) + fix;
  } else {
    return 0;
  }
}