@@ -32,7 +32,8 @@ import {
3232 setUseIcp4dMasterNodeHost ,
3333 resetAuth ,
3434 packageActivated ,
35- refreshToolkits
35+ refreshToolkits ,
36+ checkIcp4dHostExists
3637} from './actions' ;
3738import getStore from './redux-store/configure-store' ;
3839import StateSelector from './util/state-selectors' ;
@@ -405,9 +406,7 @@ export default {
405406 if ( selectedComp ) {
406407 this . mainCompositeSelectorPanel . hide ( ) ;
407408 if ( this . apiVersion === CONF_API_VERSION_V5 ) {
408- // todo
409409 const fqn = this . namespace ? `${ this . namespace } ::${ selectedComp } ` : `${ selectedComp } ` ;
410- // const appRoot = SourceArchiveUtils.getApplicationRoot(atom.project.getPaths(), selectedFilePath);
411410 const toolkitRootPath = atom . config . get ( CONF_TOOLKITS_PATH ) ;
412411 let messageHandler = MessageHandlerRegistry . get ( fqn ) ;
413412 if ( ! messageHandler ) {
@@ -473,11 +472,7 @@ export default {
473472
474473 buildMake ( action ) {
475474 if ( this . apiVersion === CONF_API_VERSION_V5 ) {
476- if ( StateSelector . getIcp4dUrl ( getStore ( ) . getState ( ) ) ) {
477- this . buildMakeV5 ( action ) ;
478- } else {
479- this . handleIcp4durlNotSet ( ) ;
480- }
475+ this . handleV5Action ( ( ) => this . buildMakeV5 ( action ) ) ;
481476 } else {
482477 this . buildMakeV4 ( action ) ;
483478 }
@@ -555,11 +550,7 @@ export default {
555550
556551 buildApp ( action ) {
557552 if ( this . apiVersion === CONF_API_VERSION_V5 ) {
558- if ( StateSelector . getIcp4dUrl ( getStore ( ) . getState ( ) ) ) {
559- this . buildAppV5 ( action ) ;
560- } else {
561- this . handleIcp4dUrlNotSet ( ) ;
562- }
553+ this . handleV5Action ( ( ) => this . buildAppV5 ( action ) ) ;
563554 } else {
564555 this . buildAppV4 ( action ) ;
565556 }
@@ -705,11 +696,7 @@ export default {
705696 */
706697 submit ( ) {
707698 if ( this . apiVersion === CONF_API_VERSION_V5 ) {
708- if ( StateSelector . getIcp4dUrl ( getStore ( ) . getState ( ) ) ) {
709- this . submitV5 ( ) ;
710- } else {
711- this . handleIcp4dUrlNotSet ( ) ;
712- }
699+ this . handleV5Action ( ( ) => this . submitV5 ( ) ) ;
713700 } else {
714701 this . submitV4 ( ) ;
715702 }
@@ -732,17 +719,16 @@ export default {
732719
733720 openConsole ( ) {
734721 if ( this . apiVersion === CONF_API_VERSION_V5 ) {
735- if ( StateSelector . getIcp4dUrl ( getStore ( ) . getState ( ) ) ) {
722+ const openConsoleFn = ( ) => {
736723 const consoleUrlString = StateSelector . getStreamsConsoleUrl ( getStore ( ) . getState ( ) ) ;
737724 if ( consoleUrlString ) {
738725 try {
739726 const consoleUrl = new URL ( consoleUrlString ) ; /* eslint-disable-line compat/compat */
740727 MessageHandlerRegistry . openUrl ( `${ consoleUrl } ` ) ;
741728 } catch ( err ) { /* */ }
742729 }
743- } else {
744- this . handleIcp4dUrlNotSet ( ) ;
745- }
730+ } ;
731+ this . handleV5Action ( openConsoleFn ) ;
746732 } else {
747733 this . streamingAnalyticsCredentials = atom . config . get ( CONF_STREAMING_ANALYTICS_CREDENTIALS ) ;
748734 this . consoleService = this . consumeConsoleService ( { id : name , name } ) ;
@@ -765,15 +751,24 @@ export default {
765751
766752 openIcp4dDashboard ( ) {
767753 if ( this . apiVersion === CONF_API_VERSION_V5 ) {
768- const icp4dUrlString = StateSelector . getIcp4dUrl ( getStore ( ) . getState ( ) ) ;
769- if ( icp4dUrlString ) {
754+ const openDashboard = ( ) => {
770755 try {
771- const icp4dUrl = new URL ( icp4dUrlString ) ; /* eslint-disable-line compat/compat */
756+ const icp4dUrl = new URL ( StateSelector . getIcp4dUrl ( getStore ( ) . getState ( ) ) ) ; /* eslint-disable-line compat/compat */
772757 MessageHandlerRegistry . openUrl ( `${ icp4dUrl } /zen/#/homepage` ) ;
773758 } catch ( err ) { /* */ }
774- } else {
775- this . handleIcp4dUrlNotSet ( ) ;
776- }
759+ } ;
760+ this . handleV5Action ( openDashboard ) ;
761+ }
762+ } ,
763+
764+ handleV5Action ( callbackFn ) {
765+ const icp4dUrl = StateSelector . getIcp4dUrl ( getStore ( ) . getState ( ) ) ;
766+ if ( icp4dUrl ) {
767+ const successFn = callbackFn ;
768+ const errorFn = ( ) => this . handleIcp4dUrlNotSet ( this . handleV5Action . bind ( this , callbackFn ) ) ;
769+ getStore ( ) . dispatch ( checkIcp4dHostExists ( successFn , errorFn ) ) ;
770+ } else {
771+ this . handleIcp4dUrlNotSet ( this . handleV5Action . bind ( this , callbackFn ) ) ;
777772 }
778773 } ,
779774
0 commit comments