From cdc17cca34e8d4063dcb3a75d2b152bcc44ef6ba Mon Sep 17 00:00:00 2001 From: Serhii Volovyk Date: Tue, 17 Nov 2020 00:18:38 +0200 Subject: [PATCH] The suggestion about the wrong network not shown when the network is correct --- utils/inspect-response.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/utils/inspect-response.js b/utils/inspect-response.js index 20317a55..e8beeec1 100644 --- a/utils/inspect-response.js +++ b/utils/inspect-response.js @@ -4,24 +4,15 @@ const chalk = require('chalk'); // colorize output const util = require('util'); -const checkExistAccount = (error, options) => { +const checkForAccDoesNotExist = (error, options) => { if(!String(error).includes('does not exist while viewing')) return false; - console.log(chalk`\n{bold.red Account {bold.white ${options.accountId}} is not found in {bold.white ${config.helperAccount}} network.\n}`); + const currentNetwork = config.helperAccount; + console.log(chalk`\n{bold.red Account {bold.white ${options.accountId}} is not found in {bold.white ${currentNetwork}} network.\n}`); - const re = new RegExp('[^.]*$', 'gi'); - const suffix = String(options.accountId).match(re)[0]; - - switch(suffix) { - case 'near': - console.log(chalk`{bold.white Use export NEAR_ENV=mainnet to use MainNet accounts. \n}`); - break; - case 'testnet': - console.log(chalk`{bold.white Use export NEAR_ENV=testnet to use TestNet accounts. \n}`); - break; - case 'betanet': - console.log(chalk`{bold.white Use export NEAR_ENV=betanet to use BetaNet accounts. \n}`); - break; + const accSuffix = String(options.accountId).match('[^.]*$')[0]; + if (currentNetwork != accSuffix && (accSuffix == 'betanet' || accSuffix == 'testnet')) { + console.log(chalk`{bold.white Use export NEAR_ENV=${accSuffix} to use ${accSuffix} accounts. \n}`); } return true; @@ -39,8 +30,7 @@ const prettyPrintResponse = (response, options) => { }; const prettyPrintError = (error, options) => { - const isCheckExistAccountError = checkExistAccount(error, options); - if(isCheckExistAccountError) return; + if (checkForAccDoesNotExist(error, options)) return; console.log('An error occured'); console.log(formatResponse(error));