Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix opt.tuiEndpoint references, and entropy reloading #281

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import yoctoSpinner from 'yocto-spinner'
import * as config from './config'
import { EntropyTuiOptions } from './types'
import { logo } from './common/ascii'
import { jumpStartNetwork, print } from './common/utils'
import { jumpStartNetwork, print, findAccountByAddressOrName } from './common/utils'
import { loadEntropy, accountOption, endpointOption } from './common/utils-cli'
import { EntropyLogger } from './common/logger'

Expand Down Expand Up @@ -93,15 +93,18 @@ async function main (entropy: Entropy, choices: string[], options: EntropyTuiOpt
// Entropy is undefined on initial install, after user creates their first account,
// entropy should be loaded
if (storedConfig.selectedAccount && !entropy) {
entropy = await loadEntropy(storedConfig.selectedAccount, options.tuiEndpoint)
entropy = await loadEntropy(storedConfig.selectedAccount, options.endpoint)
}

// 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 && currentAccount !== storedConfig.selectedAccount) {
const currentAccount = findAccountByAddressOrName(
storedConfig.accounts,
entropy?.keyring?.accounts?.registration?.address
)
if (currentAccount && currentAccount.name !== storedConfig.selectedAccount) {
await entropy.close()
entropy = await loadEntropy(storedConfig.selectedAccount, options.tuiEndpoint);
entropy = await loadEntropy(storedConfig.selectedAccount, options.endpoint);
}

Comment on lines -99 to -104
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the major tui slowdown. selectedAccount is stored as account.name now, not account.address, so this was if (true) meaning loadEntropy was always being called another time

This doubled tui startup from 2s => 4s, which felt stink!


const answers = await inquirer.prompt([{
type: 'list',
Expand All @@ -125,26 +128,26 @@ async function main (entropy: Entropy, choices: string[], options: EntropyTuiOpt

switch (answers.choice) {
case 'Manage Accounts': {
const response = await entropyAccount(options.tuiEndpoint, storedConfig)
const response = await entropyAccount(options.endpoint, storedConfig)
if (response === 'exit') { returnToMain = true }
break
}
case 'Register': {
await entropyRegister(entropy, options.tuiEndpoint, storedConfig)
await entropyRegister(entropy, options.endpoint, storedConfig)
break
}
case 'Balance': {
await entropyBalance(entropy, options.tuiEndpoint, storedConfig)
await entropyBalance(entropy, options.endpoint, storedConfig)
.catch(err => console.error('There was an error retrieving balance', err))
break
}
case 'Transfer': {
await entropyTransfer(entropy, options.tuiEndpoint)
await entropyTransfer(entropy, options.endpoint)
.catch(err => console.error('There was an error sending the transfer', err))
break
}
case 'Sign': {
await entropySign(entropy, options.tuiEndpoint)
await entropySign(entropy, options.endpoint)
.catch(err => console.error('There was an issue with signing', err))
break
}
Expand All @@ -157,12 +160,12 @@ async function main (entropy: Entropy, choices: string[], options: EntropyTuiOpt
break
}
case 'User Programs': {
await entropyProgram(entropy, options.tuiEndpoint)
await entropyProgram(entropy, options.endpoint)
.catch(err => console.error('There was an error with programs', err))
break
}
case 'Deploy Program': {
await entropyProgramDev(entropy, options.tuiEndpoint)
await entropyProgramDev(entropy, options.endpoint)
.catch(err => console.error('There was an error with program dev', err))
break
}
Expand All @@ -173,8 +176,8 @@ async function main (entropy: Entropy, choices: string[], options: EntropyTuiOpt
loader.text = 'Jumpstarting Network...'
try {
loader.start()
const jumpStartStatus = await jumpStartNetwork(entropy, options.tuiEndpoint)
const jumpStartStatus = await jumpStartNetwork(entropy, options.endpoint)

if (jumpStartStatus.isFinalized) {
loader.clear()
loader.success('Network jumpstarted!')
Expand Down
1 change: 0 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export interface EntropyTuiOptions {
account: string
endpoint: string
tuiEndpoint: string
dev: boolean
version: string
coreVersion: string
Expand Down
Loading