diff --git a/src/account/interaction.ts b/src/account/interaction.ts index af3554b3..11715d0f 100644 --- a/src/account/interaction.ts +++ b/src/account/interaction.ts @@ -1,6 +1,7 @@ import inquirer from "inquirer"; import { EntropyAccount } from './main' import { print } from "src/common/utils" +import * as config from '../config' import { manageAccountsQuestions, @@ -8,28 +9,32 @@ import { registerAccount, selectAccountQuestions } from "./utils"; - - -export async function entropyAccountCreate (entropy, endpoint) { - const { name, path } = await inquirer.prompt(newAccountQuestions) - - const service = new EntropyAccount(entropy, endpoint) - const account = await service.create({ name, path }) - - print(({ - name: account.name, - address: account.address - })) -} - -export async function entropyAccountCreate (entropy, endpoint) { - const { name, path } = await inquirer.prompt(newAccountQuestions) - - const service = new EntropyAccount(entropy, endpoint) - const account = await service.create({ name, path }) - - print(({ - name: account.name, - address: account.address - })) +import Entropy from "@entropyxyz/sdk"; +import { EntropyConfig } from "src/config/types"; + +export async function entropyManageAccounts (entropy: Entropy, endpoint: string, storedConfig: EntropyConfig) { + const AccountService = new EntropyAccount(entropy, endpoint) + const { interactionChoice } = await inquirer.prompt(manageAccountsQuestions) + switch (interactionChoice) { + case 'create-import': { + let { seed, name, path, importKey } = await inquirer.prompt(newAccountQuestions) + if (importKey && secret.includes('#debug')) { + // isDebugMode = true + seed = secret.split('#debug')[0] + } else { + seed = importKey ? secret : randomAsHex(32) + } + + } + case 'list-account': { + + } + case 'select-account': { + + } + case 'exit': { + + } + } + return { accounts: responses.accounts ? responses.accounts : storedConfig.accounts, selectedAccount: responses.selectedAccount || storedConfig.selectedAccount } } diff --git a/src/account/main.ts b/src/account/main.ts index 615fa01e..e64e3389 100644 --- a/src/account/main.ts +++ b/src/account/main.ts @@ -3,20 +3,19 @@ import Entropy from "@entropyxyz/sdk"; import Keyring from '@entropyxyz/sdk/keys' import { randomAsHex } from '@polkadot/util-crypto' -import { BaseCommand } from "../common/base-command"; +import { EntropyBase } from "../common/entropy-base"; import { print, updateConfig } from "../common/utils"; import { EntropyAccountConfig, EntropyConfig } from "../config/types"; import { FLOW_CONTEXT } from "./constants"; import { AccountCreateParams, AccountListResults } from "./types"; -export class EntropyAccount extends BaseCommand { +export class EntropyAccount extends EntropyBase { // NOTE: this class is different - it doesn't need an entropy instance constructor (entropy: Entropy | null, endpoint: string) { super(entropy, endpoint, FLOW_CONTEXT) } - async create ({ name, path }: AccountCreateParams): Promise { - const seed = randomAsHex(32) + async create ({ seed = randomAsHex(32), name, path }: AccountCreateParams): Promise { const keyring = new Keyring({ seed, path, debug: true }) const fullAccount = keyring.getAccount() // TODO: sdk should create account on constructor @@ -40,7 +39,7 @@ export class EntropyAccount extends BaseCommand { : [] if (!accountsArray.length) throw new Error( - 'There are currently no accounts available, please create or import a new account' + 'Accounts Error: There are currently no accounts available, please create or import a new account' ) return formatAccountsList(accountsArray) } diff --git a/src/account/types.ts b/src/account/types.ts index 66048778..e5a833a4 100644 --- a/src/account/types.ts +++ b/src/account/types.ts @@ -1,5 +1,6 @@ export interface AccountCreateParams { name: string + seed: string path?: string } diff --git a/src/balance/command.ts b/src/balance/command.ts index d3c1a70f..06c576d2 100644 --- a/src/balance/command.ts +++ b/src/balance/command.ts @@ -1,5 +1,5 @@ import Entropy from "@entropyxyz/sdk" -import { BaseCommand } from "../common/base-command" +import { BaseCommand } from "../common/entropy-base" import * as BalanceUtils from "./utils" const FLOW_CONTEXT = 'ENTROPY-BALANCE' diff --git a/src/common/base-command.ts b/src/common/entropy-base.ts similarity index 89% rename from src/common/base-command.ts rename to src/common/entropy-base.ts index ded342e4..1e14bf3b 100644 --- a/src/common/base-command.ts +++ b/src/common/entropy-base.ts @@ -1,7 +1,7 @@ import Entropy from "@entropyxyz/sdk"; import { EntropyLogger } from "./logger"; -export abstract class BaseCommand { +export abstract class EntropyBase { protected logger: EntropyLogger protected entropy: Entropy diff --git a/src/transfer/command.ts b/src/transfer/command.ts index 7fee0ff1..0fe1277a 100644 --- a/src/transfer/command.ts +++ b/src/transfer/command.ts @@ -1,5 +1,5 @@ import Entropy from "@entropyxyz/sdk"; -import { BaseCommand } from "../common/base-command"; +import { BaseCommand } from "../common/entropy-base"; import { setupProgress } from "../common/progress"; import * as TransferUtils from './utils' import inquirer from "inquirer";