diff --git a/src/common/utils.ts b/src/common/utils.ts index 8e89496..9f8cab3 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -1,5 +1,6 @@ import { Buffer } from 'buffer' import { EntropyAccountConfig } from "../config/types" +import { EntropyLogger } from './logger' export function stripHexPrefix (str: string): string { if (str.startsWith('0x')) return str.slice(2) @@ -74,9 +75,31 @@ export function findAccountByAddressOrName (accounts: EntropyAccountConfig[], al ) } -export async function jumpStartNetwork (entropy) { - await entropy.substrate.tx.registry.jumpStartNetwork() - .signAndSend(entropy.keyring.accounts.registration.pair) - - return +export async function jumpStartNetwork (entropy, endpoint): Promise { + const logger = new EntropyLogger('JUMPSTART_NETWORK', endpoint) + return new Promise((resolve, reject) => { + entropy.substrate.tx.registry.jumpStartNetwork() + .signAndSend(entropy.keyring.accounts.registration.pair, ({ status, dispatchError }) => { + if (dispatchError) { + let msg: string + if (dispatchError.isModule) { + // for module errors, we have the section indexed, lookup + const decoded = entropy.substrate.registry.findMetaError( + dispatchError.asModule + ) + const { docs, name, section } = decoded + + msg = `${section}.${name}: ${docs.join(' ')}` + } else { + // Other, CannotLookup, BadOrigin, no extra info + msg = dispatchError.toString() + } + const error = Error(msg) + logger.error('There was an issue jump starting the network', error) + return reject(error) + } + + if (status.isFinalized) resolve(status) + }) + }) } \ No newline at end of file diff --git a/src/tui.ts b/src/tui.ts index a2b34cf..84e22ab 100644 --- a/src/tui.ts +++ b/src/tui.ts @@ -13,6 +13,7 @@ import { entropyBalance } from './balance/interaction' import { entropyTransfer } from './transfer/interaction' import { entropyFaucet } from './faucet/interaction' import { entropyProgram, entropyProgramDev } from './program/interaction' +import yoctoSpinner from 'yocto-spinner' async function setupConfig () { let storedConfig = await config.get() @@ -45,7 +46,7 @@ export default function tui (entropy: Entropy, options: EntropyTuiOptions) { ] const devChoices = [ - 'Jump Start Network', + 'Jumpstart Network', // 'Create and Fund Faucet(s)' ] @@ -58,8 +59,10 @@ export default function tui (entropy: Entropy, options: EntropyTuiOptions) { main(entropy, choices, options, logger) } +const loader = yoctoSpinner() async function main (entropy: Entropy, choices, options, logger: EntropyLogger) { + if (loader.isSpinning) loader.stop() const storedConfig = await setupConfig() // Entropy is undefined on initial install, after user creates their first account, @@ -138,9 +141,29 @@ 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)) + case 'Jumpstart Network': { + // TO-DO: possibly move this to it's own directory similar to the other actions + // could create a new system directory for system/network level functionality + // i.e jumpstarting, deploy faucet, etc. + loader.text = 'Jumpstarting Network...' + try { + loader.start() + const jumpStartStatus = await jumpStartNetwork(entropy, options.endpoint) + + if (jumpStartStatus.isFinalized) { + loader.clear() + loader.success('Network jumpstarted!') + // running into an issue where the loader displays the success message but the return to main menu + // prompt does not display, so for now exiting process + process.exit(0) + } + } catch (error) { + loader.text = 'Jumpstart Failed' + loader.stop() + loader.clear() + console.error('There was an issue jumpstarting the network', error); + process.exit(1) + } break } default: {