Skip to content

Commit

Permalink
added loader to jumpstart
Browse files Browse the repository at this point in the history
  • Loading branch information
rh0delta committed Oct 23, 2024
1 parent e32ab04 commit fabbfe8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
33 changes: 28 additions & 5 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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<any> {
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)
})
})
}
31 changes: 27 additions & 4 deletions src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -45,7 +46,7 @@ export default function tui (entropy: Entropy, options: EntropyTuiOptions) {
]

const devChoices = [
'Jump Start Network',
'Jumpstart Network',
// 'Create and Fund Faucet(s)'
]

Expand All @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit fabbfe8

Please sign in to comment.