Skip to content

Commit

Permalink
Merge pull request #601 from near/fix/message-about-wrong-network
Browse files Browse the repository at this point in the history
Fix: Redundant suggestion about the wrong network is not shown anymore
  • Loading branch information
vgrichina authored Nov 16, 2020
2 parents d3aa943 + cdc17cc commit 890c8bb
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions utils/inspect-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit 890c8bb

Please sign in to comment.