From 8c1161e06ffa2e5c92084f6ccb1736c944b94bb9 Mon Sep 17 00:00:00 2001 From: Ryan Vandersmith Date: Thu, 18 Jan 2024 11:30:10 -0700 Subject: [PATCH 1/2] fix: change root key fetching logic and specify HttpAgent hostname for remote environments (#511) * Change root key fetching logic for remote environments * Specify HttpAgent host --- tools/ui/src/candid.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/ui/src/candid.ts b/tools/ui/src/candid.ts index bbba1cda..0474ab77 100644 --- a/tools/ui/src/candid.ts +++ b/tools/ui/src/candid.ts @@ -12,16 +12,16 @@ declare var d3: any; const names: Record = {}; -function is_local(agent: HttpAgent) { +function isKnownMainnet(agent: HttpAgent) { // @ts-ignore const hostname = agent._host.hostname; - return hostname === '127.0.0.1' || hostname.endsWith('localhost'); + return hostname.endsWith('.icp0.io') || hostname.endsWith('.ic0.app'); } export let authClient: AuthClient | undefined; -const agent = new HttpAgent(); -if (is_local(agent)) { +const agent = new HttpAgent({ host: window.location.host }); +if (!isKnownMainnet(agent)) { agent.fetchRootKey(); } From c24644f77e6c02bf475c40301b12a71fe5208736 Mon Sep 17 00:00:00 2001 From: Ryan Vandersmith Date: Mon, 22 Jan 2024 12:01:05 -0700 Subject: [PATCH 2/2] Replace 'localhost' with '127.0.0.1' for temporary HttpAgent host (#512) --- tools/ui/Cargo.lock | 6 ++---- tools/ui/src/candid.ts | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/ui/Cargo.lock b/tools/ui/Cargo.lock index 43aceb40..1b28c78d 100644 --- a/tools/ui/Cargo.lock +++ b/tools/ui/Cargo.lock @@ -117,7 +117,7 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "candid" -version = "0.10.0" +version = "0.10.2" dependencies = [ "anyhow", "binread", @@ -415,14 +415,12 @@ checksum = "a54b5297861c651551676e8c43df805dad175cc33bc97dbd992edbbb85dcbcdf" [[package]] name = "ic_principal" -version = "0.1.0" +version = "0.1.1" dependencies = [ "arbitrary", "crc32fast", "data-encoding", - "hex", "serde", - "serde_bytes", "sha2", "thiserror", ] diff --git a/tools/ui/src/candid.ts b/tools/ui/src/candid.ts index 0474ab77..24f5f7f9 100644 --- a/tools/ui/src/candid.ts +++ b/tools/ui/src/candid.ts @@ -20,7 +20,9 @@ function isKnownMainnet(agent: HttpAgent) { export let authClient: AuthClient | undefined; -const agent = new HttpAgent({ host: window.location.host }); +const agent = new HttpAgent({ + host: window.location.host.replace(/^(localhost)(:\d+)?$/, '127.0.0.1$2') +}); if (!isKnownMainnet(agent)) { agent.fetchRootKey(); }