@@ -28,6 +28,21 @@ const GLOBAL_COMPONENTS: { [key: string]: Component } = {
2828 TfSelectCountry : defineAsyncComponent ( ( ) => import ( "./components/node_selector/select_location_internals/TfSelectCountry.vue" ) ) , // prettier-ignore
2929} ;
3030
31+ const SERVICE_URLS_CACHE_KEY = "service_urls_cache" ;
32+ const SERVICE_URLS_CACHE_TTL = 60 * 60 * 1000 ; // 1 hour
33+
34+ /**
35+ * Invalidates the service URLs cache.
36+ * Should be called when service connection fails to ensure fresh URLs are fetched on next attempt.
37+ */
38+ export function invalidateServiceUrlsCache ( ) {
39+ try {
40+ sessionStorage . removeItem ( SERVICE_URLS_CACHE_KEY ) ;
41+ } catch ( error ) {
42+ console . warn ( "[invalidateServiceUrlsCache] Failed to invalidate service URLs cache" , error ) ;
43+ }
44+ }
45+
3146export function defineGlobals ( app : App < Element > ) : void {
3247 defineGlobalComponents ( app ) ;
3348 defineGlobalProps ( app ) ;
@@ -81,6 +96,20 @@ function defineGlobalProps(app: App<Element>) {
8196 * @returns A promise that resolves to `true` if all service URLs are successfully set, or `false` if any service URL is missing.
8297 */
8398export async function setGlobalEnv ( ) {
99+ try {
100+ const cachedRaw = sessionStorage . getItem ( SERVICE_URLS_CACHE_KEY ) ;
101+ if ( cachedRaw ) {
102+ const cached = JSON . parse ( cachedRaw ) as { urls : Record < string , string > ; timestamp : number } ;
103+ if ( Date . now ( ) - cached . timestamp < SERVICE_URLS_CACHE_TTL ) {
104+ Object . assign ( window . env , cached . urls ) ;
105+ return true ;
106+ }
107+ }
108+ } catch ( error ) {
109+ // Ignore cache errors and fall back to live checks
110+ console . warn ( "[setGlobalEnv] Failed to read service URLs cache" , error ) ;
111+ }
112+
84113 const {
85114 GRIDPROXY_STACKS ,
86115 GRAPHQL_STACKS ,
@@ -106,6 +135,7 @@ export async function setGlobalEnv() {
106135 const result = await urlManger . getAvailableServicesStack ( ) ;
107136
108137 if ( Object . values ( result ) . includes ( null ) ) {
138+ invalidateServiceUrlsCache ( ) ;
109139 window . $$showMonitorError ( result ) ;
110140 return false ;
111141 }
@@ -118,5 +148,26 @@ export async function setGlobalEnv() {
118148 window . env . ACTIVATION_SERVICE_URL = Activation ! ;
119149 window . env . RELAY_DOMAIN = RMB ! ;
120150 window . env . KYC_URL = KYC ! ;
151+
152+ try {
153+ sessionStorage . setItem (
154+ SERVICE_URLS_CACHE_KEY ,
155+ JSON . stringify ( {
156+ urls : {
157+ GRIDPROXY_URL : window . env . GRIDPROXY_URL ,
158+ STATS_URL : window . env . STATS_URL ,
159+ GRAPHQL_URL : window . env . GRAPHQL_URL ,
160+ SUBSTRATE_URL : window . env . SUBSTRATE_URL ,
161+ ACTIVATION_SERVICE_URL : window . env . ACTIVATION_SERVICE_URL ,
162+ RELAY_DOMAIN : window . env . RELAY_DOMAIN ,
163+ KYC_URL : window . env . KYC_URL ,
164+ } ,
165+ timestamp : Date . now ( ) ,
166+ } ) ,
167+ ) ;
168+ } catch ( error ) {
169+ console . warn ( "[setGlobalEnv] Failed to write service URLs cache" , error ) ;
170+ }
171+
121172 return true ;
122173}
0 commit comments