Skip to content
This repository was archived by the owner on Oct 8, 2019. It is now read-only.

Commit ef6c860

Browse files
authored
Refactor isConnected logic
Refactored isConnected logic into seperate function.
1 parent 8708649 commit ef6c860

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ var networks = {
9898
}
9999
};
100100

101+
function isConnected() {
102+
return server && connected;
103+
}
104+
101105
function getNetworkFromNethash(nethash){
102106
for(var n in networks){
103107
if(networks[n].nethash == nethash){
@@ -461,7 +465,7 @@ vorpal
461465
.command('network stats', 'Get stats from network')
462466
.action(function(args, callback) {
463467
var self = this;
464-
if(!server || !connected){
468+
if(!isConnected()){
465469
self.log("Please connect to node or network before");
466470
return callback();
467471
}
@@ -546,7 +550,7 @@ vorpal
546550
.command('account status <address>', 'Get account status')
547551
.action(function(args, callback) {
548552
var self = this;
549-
if(!server || !connected){
553+
if(!isConnected()){
550554
self.log("please connect to node or network before");
551555
return callback();
552556
}
@@ -595,7 +599,7 @@ vorpal
595599
.command('account vote <name>', 'Vote for delegate <name>. Remove previous vote if needed')
596600
.action(function(args, callback) {
597601
var self = this;
598-
if(!server || !connected){
602+
if(!isConnected()){
599603
self.log("please connect to node or network before");
600604
return callback();
601605
}
@@ -726,7 +730,7 @@ vorpal
726730
.command('account unvote', 'Remove previous vote')
727731
.action(function(args, callback) {
728732
var self = this;
729-
if(!server || !connected){
733+
if(!isConnected()){
730734
self.log("please connect to node or network before");
731735
return callback();
732736
}
@@ -807,7 +811,7 @@ vorpal
807811
.command('account send <amount> <address>', 'Send <amount> ark to <address>. <amount> format examples: 10, USD10.4, EUR100')
808812
.action(function(args, callback) {
809813
var self = this;
810-
if(!server || !connected){
814+
if(!isConnected()){
811815
self.log("please connect to node or network before");
812816
return callback();
813817
}
@@ -917,7 +921,7 @@ vorpal
917921
.command('account delegate <username>', 'Register new delegate with <username> ')
918922
.action(function(args, callback) {
919923
var self = this;
920-
if(!server || !connected){
924+
if(!isConnected()){
921925
self.log("please connect to node or network before");
922926
return callback();
923927
}
@@ -977,7 +981,7 @@ vorpal
977981
.command('account create', 'Generate a new random cold account')
978982
.action(function(args, callback) {
979983
var self = this;
980-
if(!server || !connected){
984+
if(!isConnected()){
981985
self.log("please connect to node or network before, in order to retrieve necessery information about address prefixing");
982986
return callback();
983987
}
@@ -992,7 +996,7 @@ vorpal
992996
.command('account vanity <string>', 'Generate an address containing lowercased <string> (WARNING you could wait for long)')
993997
.action(function(args, callback) {
994998
var self=this;
995-
if(!server || !connected){
999+
if(!isConnected()){
9961000
self.log("please connect to node or network before, in order to retrieve necessery information about address prefixing");
9971001
return callback();
9981002
}

0 commit comments

Comments
 (0)