UNPKG

@rsksmart/rsk-cli

Version:

CLI tool for Rootstock network using Viem

43 lines (42 loc) 1.51 kB
import { loadWallets } from "../utils/index.js"; import inquirer from "inquirer"; import chalk from "chalk"; export async function selectAddress() { try { const walletsDataString = loadWallets(); const walletsData = JSON.parse(walletsDataString); walletsData.addressBook = walletsData.addressBook || {}; const addressBook = walletsData.addressBook; const addressBookLabels = Object.keys(addressBook); const addressChoices = [ ...addressBookLabels.map((label) => ({ name: `${label} (${addressBook[label]})`, value: addressBook[label], })), { name: "Enter a custom address", value: "custom" }, ]; const { selectedAddress } = await inquirer.prompt([ { type: "list", name: "selectedAddress", message: "Select an address:", choices: addressChoices, }, ]); if (selectedAddress === "custom") { const { customAddress } = await inquirer.prompt([ { type: "input", name: "customAddress", message: "Enter the address:", }, ]); return customAddress; } return selectedAddress; } catch (error) { console.error(chalk.red("❌ Error selecting address:"), chalk.yellow(error.message || error)); throw error; } }