Skip to content

Commit

Permalink
fixed fresh install and using tui, might have fixed cli not sure
Browse files Browse the repository at this point in the history
  • Loading branch information
rh0delta committed Aug 29, 2024
1 parent 50ab1e1 commit b013ce3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
12 changes: 10 additions & 2 deletions src/account/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export async function entropyManageAccounts (endpoint: string, storedConfig: Ent
}

case 'select-account': {
if (!accounts.length) {
console.error('There are currently no accounts available, please create or import a new account using the Manage Accounts feature')
return
}
const { selectedAccount } = await inquirer.prompt(selectAccountQuestions(accounts))
print('Current selected account is ' + selectedAccount)

Expand All @@ -48,8 +52,12 @@ export async function entropyManageAccounts (endpoint: string, storedConfig: Ent
}

case 'list-account': {
EntropyAccount.list({ accounts })
.forEach((account) => print(account))
try {
EntropyAccount.list({ accounts })
.forEach((account) => print(account))
} catch (error) {
console.error(error.message.split('AccountsError: ')[1])
}
return
}

Expand Down
6 changes: 5 additions & 1 deletion src/account/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export class EntropyAccount extends EntropyBase {
}

async register (params?: AccountRegisterParams): Promise<string> {
const { programModAddress, programData } = params
let programModAddress: string
let programData: any
if (params) {
({ programModAddress, programData } = params)
}
const registerParams = programModAddress && programData
? {
programDeployer: programModAddress,
Expand Down
5 changes: 3 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ async function setEntropyGlobal (address: string, endpoint: string, password?: s
entropy = await loadEntropy(address, endpoint, password)
}
}
else {
else if (address && endpoint) {
entropy = await loadEntropy(address, endpoint, password)
} else {
return
}
}

Expand All @@ -53,7 +55,6 @@ program
})
.hook('preAction', async (_thisCommand, actionCommand) => {
await config.init()
console.log({ commandName })
if (commandName === 'account') return
// entropy not required for any account commands

Expand Down
3 changes: 1 addition & 2 deletions src/config/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export function deserialize (config) {
return JSON.parse(config, reviver)
}

function replacer (key, value) {
console.log(key, typeof value, value instanceof Uint8Array)
function replacer (_key: string, value: any) {
if (value instanceof Uint8Array) {
return PREFIX + Buffer.from(value).toString('base64')
}
Expand Down
10 changes: 8 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile, writeFile, rm } from 'node:fs/promises'
import { readFileSync } from 'node:fs'
import { readFileSync, writeFileSync } from 'node:fs'
import { mkdirp } from 'mkdirp'
import { join, dirname } from 'path'
import envPaths from 'env-paths'
Expand Down Expand Up @@ -63,7 +63,13 @@ export async function get (configPath = CONFIG_PATH) {
}

export function getSync (configPath = CONFIG_PATH) {
const configBuffer = readFileSync(configPath, 'utf8')
let configBuffer
try {
configBuffer = readFileSync(configPath, 'utf8')
} catch (error) {
writeFileSync(configPath, '{}')
configBuffer = readFileSync(configPath, 'utf8')
}
return deserialize(configBuffer)
}

Expand Down
6 changes: 3 additions & 3 deletions src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export default function tui (entropy: Entropy, options: EntropyTuiOptions) {

async function main (entropy: Entropy, choices, options, logger: EntropyLogger) {
let storedConfig = await setupConfig()

// If the selected account changes within the TUI we need to reset the entropy instance being used
const currentAccount = entropy.keyring.accounts.registration.address
if (currentAccount !== storedConfig.selectedAccount) {
const currentAccount = entropy?.keyring?.accounts?.registration?.address
if (currentAccount && currentAccount !== storedConfig.selectedAccount) {
await entropy.close()
entropy = await loadEntropy(storedConfig.selectedAccount, options.endpoint);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ test('Account - create', async t => {
await run('wasm', wasmGlobalsReady())
await run('config.init', config.init(configPath))
const testAccountSeed = randomAsHex(32)
const newAccount = await EntropyAccount.import({ name: testAccountName, seed: testAccountSeed })
const testAccountName = 'Test Account'
const newAccount = await EntropyAccount.import({ name: testAccountName, seed: testAccountSeed })

const testKeyring = new Keyring({ seed: testAccountSeed, path: 'none', debug: true })
const { admin } = testKeyring.getAccount()
Expand Down

0 comments on commit b013ce3

Please sign in to comment.