Skip to content

Commit

Permalink
get working for fresh install. see WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed Aug 29, 2024
1 parent d971d4d commit 50ab1e1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
/* NOTE: calling this file entropy.ts helps commander parse process.argv */
import { Command, Option } from 'commander'
import Entropy from '@entropyxyz/sdk'

import * as config from './config'
import { EntropyTuiOptions } from './types'
import { currentAccountAddressOption, endpointOption, loadEntropy } from './common/utils-cli'

import launchTui from './tui'
import { entropyAccountCommand } from './account/command'
import { entropyTransferCommand } from './transfer/command'
import { entropySignCommand } from './sign/command'
import { entropyBalanceCommand } from './balance/command'
import { EntropyTuiOptions } from './types'
import launchTui from './tui'

let entropy: Entropy
async function setEntropyGlobal (address: string, endpoint: string, password?: string) {
Expand Down Expand Up @@ -49,6 +52,8 @@ program
commandName = subCommand.name()
})
.hook('preAction', async (_thisCommand, actionCommand) => {
await config.init()
console.log({ commandName })
if (commandName === 'account') return
// entropy not required for any account commands

Expand Down
2 changes: 2 additions & 0 deletions src/common/utils-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export function passwordOption (description?: string) {

export function currentAccountAddressOption () {
const storedConfig = config.getSync()
// WIP: this needs a try-catch which runs config.init if it's missing ... which may need a sync version
// TODO
return new Option(
'-a, --account <address>',
'Sets the current account for the session or defaults to the account stored in the config'
Expand Down
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function hasRunMigration (config: any, version: number) {
export async function init (configPath = CONFIG_PATH, oldConfigPath = OLD_CONFIG_PATH) {
const currentConfig = await get(configPath)
.catch(async (err) => {
console.log("error", err.code)
if (err && err.code !== 'ENOENT') throw err

const oldConfig = await get(oldConfigPath).catch(noop) // drop errors
Expand Down
6 changes: 0 additions & 6 deletions src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ import { entropySign } from './sign/interaction'
import { entropyBalance } from './balance/interaction'
import { entropyTransfer } from './transfer/interaction'

let hasConfigInit = false
async function setupConfig () {
if (!hasConfigInit) {
await config.init()
hasConfigInit = true
}

let storedConfig = await config.get()

// set selectedAccount if we can
Expand Down

0 comments on commit 50ab1e1

Please sign in to comment.