From 3ca8cb9cea01f81be54cc7e76c85cedf753f8f83 Mon Sep 17 00:00:00 2001 From: Nayyir Jutha Date: Tue, 22 Oct 2024 16:51:38 -0400 Subject: [PATCH] fixed tests due to faulty config, added new dev choice to manually jump start network --- src/balance/interaction.ts | 7 ++++--- src/cli.ts | 3 ++- src/common/utils-cli.ts | 2 -- src/common/utils.ts | 7 +++++++ src/tui.ts | 19 +++++++++++++++++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/balance/interaction.ts b/src/balance/interaction.ts index 1fcef279..334c00c7 100644 --- a/src/balance/interaction.ts +++ b/src/balance/interaction.ts @@ -1,11 +1,12 @@ -import { print } from "src/common/utils" +import { findAccountByAddressOrName, print } from "src/common/utils" import { EntropyBalance } from "./main" export async function entropyBalance (entropy, endpoint, storedConfig) { try { const balanceService = new EntropyBalance(entropy, endpoint) - const balance = await balanceService.getBalance(storedConfig.selectedAccount) - print(`Address ${storedConfig.selectedAccount} has a balance of: ${balance.toLocaleString('en-US')} BITS`) + const address = findAccountByAddressOrName(storedConfig.accounts, storedConfig.selectedAccount)?.address + const balance = await balanceService.getBalance(address) + print(`Entropy Account [${storedConfig.selectedAccount}] (${address}) has a balance of: ${balance.toLocaleString('en-US')} BITS`) } catch (error) { console.error('There was an error retrieving balance', error) } diff --git a/src/cli.ts b/src/cli.ts index fcba4223..0f599002 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -4,7 +4,7 @@ import { Command, Option } from 'commander' import { EntropyTuiOptions } from './types' -import { loadEntropy } from './common/utils-cli' +import { endpointOption, loadEntropy } from './common/utils-cli' import * as config from './config' import launchTui from './tui' @@ -28,6 +28,7 @@ program .env('DEV_MODE') .hideHelp() ) + .addOption(endpointOption()) .addCommand(entropyBalanceCommand()) .addCommand(entropyAccountCommand()) .addCommand(entropyTransferCommand()) diff --git a/src/common/utils-cli.ts b/src/common/utils-cli.ts index e7030a12..27c8605e 100644 --- a/src/common/utils-cli.ts +++ b/src/common/utils-cli.ts @@ -82,8 +82,6 @@ export async function loadEntropy (addressOrName: string, endpoint: string): Pro if (!selectedAccount) throw new Error(`No account with name or address: "${addressOrName}"`) const entropy = await initializeEntropy({ keyMaterial: selectedAccount.data, endpoint }) - await entropy.substrate.tx.registry.jumpStartNetwork() - .signAndSend(entropy.keyring.accounts.registration.pair) if (!entropy?.keyring?.accounts?.registration?.pair) { throw new Error("Signer keypair is undefined or not properly initialized.") diff --git a/src/common/utils.ts b/src/common/utils.ts index b4dbc7ea..8e894966 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -73,3 +73,10 @@ export function findAccountByAddressOrName (accounts: EntropyAccountConfig[], al accounts.find(account => account.name === aliasOrAddress) ) } + +export async function jumpStartNetwork (entropy) { + await entropy.substrate.tx.registry.jumpStartNetwork() + .signAndSend(entropy.keyring.accounts.registration.pair) + + return +} \ No newline at end of file diff --git a/src/tui.ts b/src/tui.ts index 6b7c35ed..a2b34cf9 100644 --- a/src/tui.ts +++ b/src/tui.ts @@ -3,7 +3,7 @@ import Entropy from '@entropyxyz/sdk' import * as config from './config' import { EntropyTuiOptions } from './types' import { logo } from './common/ascii' -import { print } from './common/utils' +import { jumpStartNetwork, print } from './common/utils' import { loadEntropy } from './common/utils-cli' import { EntropyLogger } from './common/logger' @@ -44,6 +44,15 @@ export default function tui (entropy: Entropy, options: EntropyTuiOptions) { 'User Programs', ] + const devChoices = [ + 'Jump Start Network', + // 'Create and Fund Faucet(s)' + ] + + if (options.dev) { + choices = [...choices, ...devChoices] + } + // assign exit so its last choices = [...choices, 'Exit'] @@ -129,8 +138,14 @@ async function main (entropy: Entropy, choices, options, logger: EntropyLogger) .catch(err => console.error('There was an error with program dev', err)) break } + case 'Jump Start Network': { + await jumpStartNetwork(entropy) + .catch(err => console.error('There was an issue jumpstarting the network', err)) + break + } default: { - throw Error(`unsupported choice: ${answers.choice}`) + console.error('Unsupported Action:' + answers.choice) + break } } }