From e36de33ce837dc94a5f5a781fb5205c93a0f9043 Mon Sep 17 00:00:00 2001 From: Atharva Date: Mon, 9 Dec 2024 02:31:36 +0530 Subject: [PATCH] feat: Update stake status accordingly --- src/node-commands.ts | 58 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/node-commands.ts b/src/node-commands.ts index 60a63f9..dd0d67e 100644 --- a/src/node-commands.ts +++ b/src/node-commands.ts @@ -329,19 +329,24 @@ export function registerNodeCommands(program: Command) { reason: 'Could not fetch data', remainingTime: -1, }; - if (accountInfo.nominator) { - const eoaData = await fetchEOADetails(config, accountInfo.nominator); - if (eoaData) { - const unstakableData = await fetchUnstakeableDetails( + if (descriptions.length === 0) { + if (accountInfo.nominator) { + const eoaData = await fetchEOADetails( config, - publicKey, accountInfo.nominator ); - unstakable = unstakableData ?? unstakable; + + if (eoaData) { + const unstakableData = await fetchUnstakeableDetails( + config, + publicKey, + accountInfo.nominator + ); + unstakable = unstakableData ?? unstakable; + } } - } - if (descriptions.length === 0) { + // Node process not started console.log( yaml.dump({ @@ -379,6 +384,30 @@ export function registerNodeCommands(program: Command) { nodeStatus = lockedStakeStr === '0.0' ? 'need-stake' : 'waiting-for-network'; + if (nodeStatus === 'active') { + unstakable = { + unlocked: false, + reason: 'Node is active', + remainingTime: -1, + }; + } else { + if (accountInfo.nominator) { + const eoaData = await fetchEOADetails( + config, + accountInfo.nominator + ); + + if (eoaData) { + const unstakableData = await fetchUnstakeableDetails( + config, + publicKey, + accountInfo.nominator + ); + unstakable = unstakableData ?? unstakable; + } + } + } + console.log( yaml.dump({ state: nodeStatus, @@ -412,6 +441,19 @@ export function registerNodeCommands(program: Command) { } // Node was started but is currently inactive + if (accountInfo.nominator) { + const eoaData = await fetchEOADetails(config, accountInfo.nominator); + + if (eoaData) { + const unstakableData = await fetchUnstakeableDetails( + config, + publicKey, + accountInfo.nominator + ); + unstakable = unstakableData ?? unstakable; + } + } + console.log( yaml.dump({ state: 'stopped',