chore: skip picking if VEGA_URL set

This commit is contained in:
asiaznik 2024-03-08 13:53:34 +01:00
parent 635445f23b
commit b0bbae4c2e
No known key found for this signature in database
GPG Key ID: 4D5C8972A02C52C2

View File

@ -619,6 +619,12 @@ export const useEnvironment = create<EnvStore>()((set, get) => ({
const state = get(); const state = get();
// skip picking up the best node if VEGA_URL env variable is set
if (state.VEGA_URL && isValidUrl(state.VEGA_URL)) {
state.setUrl(state.VEGA_URL);
return;
}
let storedUrl = LocalStorage.getItem(STORAGE_KEY); let storedUrl = LocalStorage.getItem(STORAGE_KEY);
if (!isValidUrl(storedUrl)) { if (!isValidUrl(storedUrl)) {
// remove invalid data from local storage // remove invalid data from local storage
@ -667,24 +673,21 @@ export const useEnvironment = create<EnvStore>()((set, get) => ({
// remove unhealthy node url from local storage // remove unhealthy node url from local storage
LocalStorage.removeItem(STORAGE_KEY); LocalStorage.removeItem(STORAGE_KEY);
} }
// A node's url (VEGA_URL) is either the requsted node (previously // A node's url (VEGA_URL) is either the requested node (previously
// connected or taken form env variable) or the currently best available // connected or taken form env variable) or the currently best available
// node. // node.
const url = requestedNode?.url || bestNode?.url; const url = requestedNode?.url || bestNode?.url;
if (url != null) { if (url != null) {
set({ state.setUrl(url);
status: 'success', return;
VEGA_URL: url,
});
LocalStorage.setItem(STORAGE_KEY, url);
} else {
set({
status: 'failed',
error: 'No suitable node found',
});
console.warn('No suitable node was found');
} }
set({
status: 'failed',
error: 'No suitable node found',
});
console.warn('No suitable node was found');
}, },
})); }));