From 6dfd8b2297af2e26dbd8b827629c72edb05ae983 Mon Sep 17 00:00:00 2001 From: Nayyir Jutha Date: Tue, 6 Aug 2024 19:08:12 -0400 Subject: [PATCH] cleanup from smoke test --- src/accounts/command.ts | 4 ++-- src/accounts/constants.ts | 2 +- src/cli.ts | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/accounts/command.ts b/src/accounts/command.ts index 5b9c6a01..f85c1d1f 100644 --- a/src/accounts/command.ts +++ b/src/accounts/command.ts @@ -43,7 +43,7 @@ export class AccountsCommand extends BaseCommand { } public async selectAccount (accounts: EntropyAccountConfig[]) { - const answers = await inquirer.prompt([selectAccountQuestions(accounts)]) + const answers = await inquirer.prompt(selectAccountQuestions(accounts)) return { selectedAccount: answers.selectedAccount.address } } @@ -91,7 +91,7 @@ export class AccountsCommand extends BaseCommand { public async runInteraction (config): Promise { const { accounts } = config const { interactionChoice } = await inquirer.prompt(manageAccountsQuestions) - + switch (interactionChoice) { case 'create-account': { const createAccountParams = await this.getUserInput() diff --git a/src/accounts/constants.ts b/src/accounts/constants.ts index b8c407a0..4c815477 100644 --- a/src/accounts/constants.ts +++ b/src/accounts/constants.ts @@ -25,7 +25,7 @@ export const ACCOUNTS_CONTENT = { message: "Choose account:", }, interactionChoice: { - name: 'choice', + name: 'interactionChoice', choices: [ { name: 'Create/Import Account', value: 'create-import' }, { name: 'Select Account', value: 'select-account' }, diff --git a/src/cli.ts b/src/cli.ts index 808ed709..8833cfd0 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -9,7 +9,7 @@ import { EntropyTuiOptions } from './types' import { cliEntropyTransfer } from './flows/entropyTransfer/cli' import { cliSign } from './flows/sign/cli' -import { getSelectedAccount, stringify } from './common/utils' +import { getSelectedAccount, stringify, updateConfig } from './common/utils' import Entropy from '@entropyxyz/sdk' import { initializeEntropy } from './common/initializeEntropy' import { BalanceCommand } from './balance/command' @@ -150,7 +150,7 @@ program.command('new-account') ) .addOption( new Option( - '-p, --path', + '-pa, --path', 'Derivation path' ).default(ACCOUNTS_CONTENT.path.default) ) @@ -165,6 +165,41 @@ program.command('new-account') process.exit(0) }) +/* register */ +program.command('register') + .description('Register an entropy account with a program') + .argument('address', 'Address of existing entropy account') + .addOption(passwordOption()) + .addOption(endpointOption()) + .addOption( + new Option( + '-pointer, --pointer', + 'Program pointer of program to be used for registering' + ) + ) + .addOption( + new Option( + '-data, --program-data', + 'Path to file containing program data in JSON format' + ) + ) + .action(async (address, opts) => { + const storedConfig = await config.get() + const { accounts } = storedConfig + const accountsCommand = new AccountsCommand(entropy, opts.endpoint) + writeOut('Attempting to register account with addtess: ' + address) + const accountToRegister = getSelectedAccount(accounts, address) + if (!accountToRegister) { + throw new Error('AccountError: Unable to register non-existent account') + } + const updatedAccount = await accountsCommand.registerAccount(accountToRegister) + const arrIdx = accounts.indexOf(accountToRegister) + accounts.splice(arrIdx, 1, updatedAccount) + await updateConfig(storedConfig, { accounts, selectedAccount: updatedAccount.address }) + writeOut("Your address" + updatedAccount.address + "has been successfully registered.") + process.exit(0) + }) + /* balance */ program.command('balance') .description('Get the balance of an Entropy account. Output is a number')