Skip to content

Commit

Permalink
cleaning up the cleanup for accounts restructure;
Browse files Browse the repository at this point in the history
  • Loading branch information
rh0delta committed Aug 28, 2024
1 parent ec0609f commit 3aa419b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
53 changes: 29 additions & 24 deletions src/account/interaction.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
import inquirer from "inquirer";
import { EntropyAccount } from './main'
import { print } from "src/common/utils"
import * as config from '../config'

import {
manageAccountsQuestions,
newAccountQuestions,
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')) {

Check failure on line 21 in src/account/interaction.ts

View workflow job for this annotation

GitHub Actions / Build, test, and lint

Cannot find name 'secret'.
// isDebugMode = true
seed = secret.split('#debug')[0]

Check failure on line 23 in src/account/interaction.ts

View workflow job for this annotation

GitHub Actions / Build, test, and lint

Cannot find name 'secret'.
} else {
seed = importKey ? secret : randomAsHex(32)

Check failure on line 25 in src/account/interaction.ts

View workflow job for this annotation

GitHub Actions / Build, test, and lint

Cannot find name 'secret'.

Check failure on line 25 in src/account/interaction.ts

View workflow job for this annotation

GitHub Actions / Build, test, and lint

Cannot find name 'randomAsHex'.
}

}
case 'list-account': {

}
case 'select-account': {

}
case 'exit': {

}
}
return { accounts: responses.accounts ? responses.accounts : storedConfig.accounts, selectedAccount: responses.selectedAccount || storedConfig.selectedAccount }

Check failure on line 39 in src/account/interaction.ts

View workflow job for this annotation

GitHub Actions / Build, test, and lint

Cannot find name 'responses'. Did you mean 'Response'?

Check failure on line 39 in src/account/interaction.ts

View workflow job for this annotation

GitHub Actions / Build, test, and lint

Cannot find name 'responses'. Did you mean 'Response'?

Check failure on line 39 in src/account/interaction.ts

View workflow job for this annotation

GitHub Actions / Build, test, and lint

Cannot find name 'responses'. Did you mean 'Response'?
}
9 changes: 4 additions & 5 deletions src/account/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntropyAccountConfig> {
const seed = randomAsHex(32)
async create ({ seed = randomAsHex(32), name, path }: AccountCreateParams): Promise<EntropyAccountConfig> {
const keyring = new Keyring({ seed, path, debug: true })
const fullAccount = keyring.getAccount()
// TODO: sdk should create account on constructor
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions src/account/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface AccountCreateParams {
name: string
seed: string
path?: string
}

Expand Down
2 changes: 1 addition & 1 deletion src/balance/command.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/common/base-command.ts → src/common/entropy-base.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/transfer/command.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 3aa419b

Please sign in to comment.