@@ -3,6 +3,7 @@ use candid::{CandidType, Principal};
33use clap:: Args ;
44use futures:: { StreamExt , future:: try_join_all, stream:: FuturesOrdered } ;
55use ic_agent:: Agent ;
6+ use icp:: network:: { Managed , ManagedMode } ;
67use icp:: parsers:: CyclesAmount ;
78use icp:: {
89 context:: { CanisterSelection , Context , EnvironmentSelection } ,
@@ -176,6 +177,8 @@ pub(crate) async fn exec(ctx: &Context, args: &DeployArgs) -> Result<(), anyhow:
176177 }
177178 }
178179
180+ ctx. update_custom_domains ( & environment_selection) . await ;
181+
179182 let _ = ctx. term . write_line ( "\n \n Setting environment variables:" ) ;
180183 let env = ctx
181184 . get_environment ( & environment_selection)
@@ -377,21 +380,29 @@ async fn print_canister_urls(
377380 agent : Agent ,
378381 canister_names : & [ String ] ,
379382) -> Result < ( ) , anyhow:: Error > {
383+ use icp:: network:: custom_domains:: { canister_gateway_url, gateway_domain} ;
384+
380385 let env = ctx. get_environment ( environment_selection) . await ?;
381386
382387 // Get the network URL
383388 let http_gateway_url = match & env. network . configuration {
384389 NetworkConfiguration :: Managed { managed : _ } => {
385- // For managed networks, construct localhost URL
386390 let access = ctx. network . access ( & env. network ) . await ?;
387391 access. http_gateway_url . clone ( )
388392 }
389- NetworkConfiguration :: Connected { connected } => {
390- // For connected networks, use the configured URL
391- connected. http_gateway_url . clone ( )
392- }
393+ NetworkConfiguration :: Connected { connected } => connected. http_gateway_url . clone ( ) ,
393394 } ;
394395
396+ // Friendly domains are available for managed networks where we write custom-domains.txt
397+ let has_friendly = matches ! (
398+ & env. network. configuration,
399+ NetworkConfiguration :: Managed {
400+ managed: Managed {
401+ mode: ManagedMode :: Launcher ( config)
402+ }
403+ } if config. version. is_none( )
404+ ) ;
405+
395406 let _ = ctx. term . write_line ( "\n \n Deployed canisters:" ) ;
396407
397408 for name in canister_names {
@@ -407,58 +418,40 @@ async fn print_canister_urls(
407418 } ;
408419
409420 if let Some ( http_gateway_url) = & http_gateway_url {
410- // Check if canister has http_request
411421 let has_http = has_http_request ( & agent, canister_id) . await ;
412- let domain = if let Some ( domain) = http_gateway_url. domain ( ) {
413- Some ( domain)
414- } else if let Some ( host) = http_gateway_url. host_str ( )
415- && ( host == "127.0.0.1" || host == "[::1]" )
416- {
417- Some ( "localhost" )
422+ let friendly = if has_friendly {
423+ Some ( ( name. as_str ( ) , environment_selection. name ( ) ) )
418424 } else {
419425 None
420426 } ;
421427
422428 if has_http {
423- let mut canister_url = http_gateway_url. clone ( ) ;
424- if let Some ( domain) = domain {
425- canister_url
426- . set_host ( Some ( & format ! ( "{canister_id}.{domain}" ) ) )
427- . unwrap ( ) ;
428- } else {
429- canister_url. set_query ( Some ( & format ! ( "canisterId={canister_id}" ) ) ) ;
430- }
429+ let canister_url = canister_gateway_url ( http_gateway_url, canister_id, friendly) ;
431430 let _ = ctx
432431 . term
433432 . write_line ( & format ! ( " {}: {}" , name, canister_url) ) ;
434433 } else {
435434 // For canisters without http_request, show the Candid UI URL
436- if let Some ( ref ui_id) = get_candid_ui_id ( ctx, environment_selection) . await {
437- let mut candid_url = http_gateway_url. clone ( ) ;
438- if let Some ( domain) = domain {
439- candid_url
440- . set_host ( Some ( & format ! ( "{ui_id}.{domain}" , ) ) )
441- . unwrap ( ) ;
435+ if let Some ( ui_id) = get_candid_ui_id ( ctx, environment_selection) . await {
436+ let domain = gateway_domain ( http_gateway_url) ;
437+ let mut candid_url = canister_gateway_url ( http_gateway_url, ui_id, None ) ;
438+ if domain. is_some ( ) {
442439 candid_url. set_query ( Some ( & format ! ( "id={canister_id}" ) ) ) ;
443440 } else {
444441 candid_url. set_query ( Some ( & format ! ( "canisterId={ui_id}&id={canister_id}" ) ) ) ;
445442 }
446443 let _ = ctx
447444 . term
448- . write_line ( & format ! ( " {} (Candid UI): {}" , name , candid_url ) ) ;
445+ . write_line ( & format ! ( " {name } (Candid UI): {candid_url}" ) ) ;
449446 } else {
450- // No Candid UI available - just show the canister ID
451447 let _ = ctx. term . write_line ( & format ! (
452- " {}: {} (Candid UI not available)" ,
453- name, canister_id
448+ " {name}: {canister_id} (Candid UI not available)" ,
454449 ) ) ;
455450 }
456451 }
457452 } else {
458- // No gateway subdomains available - just show the canister ID
459453 let _ = ctx. term . write_line ( & format ! (
460- " {}: {} (No gateway URL available)" ,
461- name, canister_id
454+ " {name}: {canister_id} (No gateway URL available)" ,
462455 ) ) ;
463456 }
464457 }
@@ -471,7 +464,7 @@ async fn print_canister_urls(
471464async fn get_candid_ui_id (
472465 ctx : & Context ,
473466 environment_selection : & EnvironmentSelection ,
474- ) -> Option < String > {
467+ ) -> Option < Principal > {
475468 let env = ctx. get_environment ( environment_selection) . await . ok ( ) ?;
476469
477470 match & env. network . configuration {
@@ -481,14 +474,14 @@ async fn get_candid_ui_id(
481474 if let Ok ( Some ( desc) ) = nd. load_network_descriptor ( ) . await
482475 && let Some ( candid_ui) = desc. candid_ui_canister_id
483476 {
484- return Some ( candid_ui. to_string ( ) ) ;
477+ return Some ( candid_ui) ;
485478 }
486479 // No Candid UI available for this managed network
487480 None
488481 }
489482 NetworkConfiguration :: Connected { .. } => {
490483 // For connected networks, use the mainnet Candid UI
491- Some ( MAINNET_CANDID_UI_CID . to_string ( ) )
484+ Some ( MAINNET_CANDID_UI_CID )
492485 }
493486 }
494487}
0 commit comments