From f43791c3de3f7ec2cd56fcde97670c7f78aa1c42 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 16 Apr 2024 13:56:30 +0200 Subject: [PATCH 1/2] Refactor getDefaultUrls function --- packages/grid_client/src/client.ts | 51 ++++-------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/packages/grid_client/src/client.ts b/packages/grid_client/src/client.ts index a3266a7e24..8a9df5c3f7 100644 --- a/packages/grid_client/src/client.ts +++ b/packages/grid_client/src/client.ts @@ -171,52 +171,13 @@ class GridClient { getDefaultUrls(network: NetworkEnv): Record { const urls = { rmbProxy: "", substrate: "", graphql: "", activation: "", relay: "" }; + const NETWORK = network !== NetworkEnv.main ? `${network}.` : ""; + urls.rmbProxy = this.clientOptions.proxyURL ?? `https://gridproxy.${NETWORK}grid.tf`; + urls.relay = this.clientOptions.relayURL ?? `wss://relay.${NETWORK}grid.tf`; + urls.substrate = this.clientOptions.substrateURL ?? `wss://tfchain.${NETWORK}grid.tf/ws`; + urls.graphql = this.clientOptions.graphqlURL ?? `https://graphql.${NETWORK}grid.tf/graphql`; + urls.activation = this.clientOptions.activationURL ?? `https://activation.${NETWORK}grid.tf/activation/activate`; - if (network === NetworkEnv.dev) { - urls.rmbProxy = this.clientOptions.proxyURL ? this.clientOptions.proxyURL : "https://gridproxy.dev.grid.tf"; - urls.relay = this.clientOptions.relayURL ? this.clientOptions.relayURL : "wss://relay.dev.grid.tf"; - urls.substrate = this.clientOptions.substrateURL - ? this.clientOptions.substrateURL - : "wss://tfchain.dev.grid.tf/ws"; - urls.graphql = this.clientOptions.graphqlURL - ? this.clientOptions.graphqlURL - : "https://graphql.dev.grid.tf/graphql"; - urls.activation = this.clientOptions.activationURL - ? this.clientOptions.activationURL - : "https://activation.dev.grid.tf/activation/activate"; - } else if (network === NetworkEnv.test) { - urls.rmbProxy = this.clientOptions.proxyURL ? this.clientOptions.proxyURL : "https://gridproxy.test.grid.tf"; - urls.relay = this.clientOptions.relayURL ? this.clientOptions.relayURL : "wss://relay.test.grid.tf"; - urls.substrate = this.clientOptions.substrateURL - ? this.clientOptions.substrateURL - : "wss://tfchain.test.grid.tf/ws"; - urls.graphql = this.clientOptions.graphqlURL - ? this.clientOptions.graphqlURL - : "https://graphql.test.grid.tf/graphql"; - urls.activation = this.clientOptions.activationURL - ? this.clientOptions.activationURL - : "https://activation.test.grid.tf/activation/activate"; - } else if (network === NetworkEnv.qa) { - urls.rmbProxy = this.clientOptions.proxyURL ? this.clientOptions.proxyURL : "https://gridproxy.qa.grid.tf"; - urls.relay = this.clientOptions.relayURL ? this.clientOptions.relayURL : "wss://relay.qa.grid.tf"; - urls.substrate = this.clientOptions.substrateURL - ? this.clientOptions.substrateURL - : "wss://tfchain.qa.grid.tf/ws"; - urls.graphql = this.clientOptions.graphqlURL - ? this.clientOptions.graphqlURL - : "https://graphql.qa.grid.tf/graphql"; - urls.activation = this.clientOptions.activationURL - ? this.clientOptions.activationURL - : "https://activation.qa.grid.tf/activation/activate"; - } else if (network === NetworkEnv.main) { - urls.rmbProxy = this.clientOptions.proxyURL ? this.clientOptions.proxyURL : "https://gridproxy.grid.tf"; - urls.relay = this.clientOptions.relayURL ? this.clientOptions.relayURL : "wss://relay.grid.tf"; - urls.substrate = this.clientOptions.substrateURL ? this.clientOptions.substrateURL : "wss://tfchain.grid.tf/ws"; - urls.graphql = this.clientOptions.graphqlURL ? this.clientOptions.graphqlURL : "https://graphql.grid.tf/graphql"; - urls.activation = this.clientOptions.activationURL - ? this.clientOptions.activationURL - : "https://activation.grid.tf/activation/activate"; - } return urls; } From 16a8dcc21948ddbc7d0d8a71c13d3de13e287129 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 17 Apr 2024 12:02:43 +0200 Subject: [PATCH 2/2] Enhance getDefaultUrls --- packages/grid_client/src/client.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/grid_client/src/client.ts b/packages/grid_client/src/client.ts index 8a9df5c3f7..1b06614da2 100644 --- a/packages/grid_client/src/client.ts +++ b/packages/grid_client/src/client.ts @@ -170,13 +170,15 @@ class GridClient { } getDefaultUrls(network: NetworkEnv): Record { - const urls = { rmbProxy: "", substrate: "", graphql: "", activation: "", relay: "" }; - const NETWORK = network !== NetworkEnv.main ? `${network}.` : ""; - urls.rmbProxy = this.clientOptions.proxyURL ?? `https://gridproxy.${NETWORK}grid.tf`; - urls.relay = this.clientOptions.relayURL ?? `wss://relay.${NETWORK}grid.tf`; - urls.substrate = this.clientOptions.substrateURL ?? `wss://tfchain.${NETWORK}grid.tf/ws`; - urls.graphql = this.clientOptions.graphqlURL ?? `https://graphql.${NETWORK}grid.tf/graphql`; - urls.activation = this.clientOptions.activationURL ?? `https://activation.${NETWORK}grid.tf/activation/activate`; + const base = network === NetworkEnv.main ? "grid.tf" : `${network}.grid.tf`; + const { proxyURL, relayURL, substrateURL, graphqlURL, activationURL } = this.clientOptions; + const urls = { + rmbProxy: proxyURL || `https://gridproxy.${base}`, + relay: relayURL || `wss://relay.${base}`, + substrate: substrateURL || `wss://tfchain.${base}/ws`, + graphql: graphqlURL || `https://graphql.${base}/graphql`, + activation: activationURL || `https://activation.${base}/activation/activate`, + }; return urls; }