diff --git a/packages/agoric-cli/src/commands/wallet.js b/packages/agoric-cli/src/commands/wallet.js index 10bed0a0ee3..8fc3405fbf6 100644 --- a/packages/agoric-cli/src/commands/wallet.js +++ b/packages/agoric-cli/src/commands/wallet.js @@ -29,19 +29,26 @@ const SLEEP_SECONDS = 3; * @returns {Promise} */ export const makeWalletCommand = async command => { - const wallet = command('wallet') - .description('wallet commands') - .option('--home ', 'agd application home directory') - .option( - '--keyring-backend ', - 'keyring\'s backend (os|file|test) (default "os")', - ); + /** + * @param {import('commander').Command} baseCmd + */ + const withSharedTxOptions = baseCmd => + baseCmd + .option('--home ', 'agd application home directory') + .option( + '--keyring-backend ', + 'keyring\'s backend (os|file|test) (default "os")', + ); + /** @typedef {{home?: string, keyringBackend: 'os' | 'file' | 'test'}} SharedTxOptions */ + + const wallet = withSharedTxOptions(command('wallet')).description( + 'wallet commands', + ); const normalizeAddress = literalOrName => normalizeAddressWithOptions(literalOrName, wallet.opts()); - wallet - .command('provision') + withSharedTxOptions(wallet.command('provision')) .description('provision a Smart Wallet') .requiredOption( '--account [address]', @@ -51,8 +58,14 @@ export const makeWalletCommand = async command => { .option('--spend', 'confirm you want to spend') .option('--nickname ', 'nickname to use', 'my-wallet') .action(function (opts) { - const { account, nickname, spend } = opts; - const { home, keyringBackend: backend } = wallet.opts(); + /** @typedef {{account: string, spend?: boolean, nickname: 'my-wallet' | string }} Opts */ + const { + account, + nickname, + spend, + home, + keyringBackend: backend, + } = /** @type {SharedTxOptions & Opts} */ ({ ...wallet.opts(), ...opts }); const tx = ['provision-one', nickname, account, 'SMART_WALLET']; if (spend) { execSwingsetTransaction(tx, { @@ -110,8 +123,7 @@ export const makeWalletCommand = async command => { console.log(offerObj.offer.id); }); - wallet - .command('send') + withSharedTxOptions(wallet.command('send')) .description('send a prepared offer') .requiredOption( '--from [address]', @@ -121,8 +133,14 @@ export const makeWalletCommand = async command => { .requiredOption('--offer [filename]', 'path to file with prepared offer') .option('--dry-run', 'spit out the command instead of running it') .action(function (opts) { - const { dryRun, from, offer } = opts; - const { home, keyringBackend: backend } = wallet.opts(); + /** @typedef {{ from: string, offer: string, dryRun: boolean }} Opts */ + const { + dryRun, + from, + offer, + home, + keyringBackend: backend, + } = /** @type {SharedTxOptions & Opts} */ ({ ...wallet.opts(), ...opts }); const offerBody = fs.readFileSync(offer).toString(); execSwingsetTransaction(['wallet-action', '--allow-spend', offerBody], {