From aea9d5266c7f4bf5c3b261f484035f9807ccdfd8 Mon Sep 17 00:00:00 2001 From: Bill He Date: Wed, 1 May 2024 18:36:28 -0700 Subject: [PATCH] use env endpoint for geo --- .../state/manager/Enviroment.kt | 4 ++- .../state/manager/V4StateManagerAdaptor.kt | 4 +-- .../state/v2/manager/StateManagerAdaptorV2.kt | 34 ++++++++++--------- .../tests/payloads/AbacusMockData.kt | 1 + .../tests/payloads/EnvironmentsMock.kt | 6 ++-- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Enviroment.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Enviroment.kt index abc603589..dc3546664 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Enviroment.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/Enviroment.kt @@ -32,6 +32,7 @@ data class EnvironmentEndpoints( val faucet: String?, val squid: String?, val nobleValidator: String?, + val geo: String?, ) { companion object { fun parse( @@ -47,7 +48,8 @@ data class EnvironmentEndpoints( val faucet = parser.asString(data["faucet"]) val squid = parser.asString(data["0xsquid"]) val nobleValidator = parser.asString(data["nobleValidator"]) - return EnvironmentEndpoints(indexers, validators, faucet, squid, nobleValidator) + val geo = parser.asString(data["geo"]) + return EnvironmentEndpoints(indexers, validators, faucet, squid, nobleValidator, geo) } } } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt index 443a0d5f2..226f96cce 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/manager/V4StateManagerAdaptor.kt @@ -244,8 +244,8 @@ class V4StateManagerAdaptor( return configs.publicApiUrl("screen") } - override fun geoUrl(): String { - return "https://api.dydx.exchange/v4/geo" + override fun geoUrl(): String? { + return environment.endpoints.geo } override fun complianceScreenUrl(address: String): String? { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt index baeb17854..bfeccf111 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/StateManagerAdaptorV2.kt @@ -446,25 +446,27 @@ internal class StateManagerAdaptorV2( } private fun fetchGeo() { - val url = "https://api.dydx.exchange/v4/geo" - networkHelper.get( - url, - null, - null, - callback = { _, response, httpCode, _ -> - geo = if (networkHelper.success(httpCode) && response != null) { - val payload = networkHelper.parser.decodeJsonObject(response)?.toIMap() - if (payload != null) { - val country = networkHelper.parser.asString(networkHelper.parser.value(payload, "geo.country")) - country + val url = environment.endpoints.geo + if (url != null) { + networkHelper.get( + url, + null, + null, + callback = { _, response, httpCode, _ -> + geo = if (networkHelper.success(httpCode) && response != null) { + val payload = networkHelper.parser.decodeJsonObject(response)?.toIMap() + if (payload != null) { + val country = networkHelper.parser.asString(networkHelper.parser.value(payload, "geo.country")) + country + } else { + null + } } else { null } - } else { - null - } - }, - ) + }, + ) + } } internal fun trade(data: String?, type: TradeInputField?) { diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt index f04ed68c4..5197627c8 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/AbacusMockData.kt @@ -63,6 +63,7 @@ class AbacusMockData { null, null, null, + null ), null, WalletConnection( diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/EnvironmentsMock.kt b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/EnvironmentsMock.kt index de8363901..46fb195a6 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/EnvironmentsMock.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/tests/payloads/EnvironmentsMock.kt @@ -83,7 +83,8 @@ class EnvironmentsMock { "validators":[ "https://validator.v4staging.dydx.exchange" ], - "0xsquid":"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app" + "0xsquid":"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app", + "geo": "https://api.dydx.exchange/v4/geo" }, "featureFlags":{ "reduceOnlySupported":true, @@ -117,7 +118,8 @@ class EnvironmentsMock { "https://test-dydx.kingnodes.com/" ], "0xsquid":"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app", - "faucet":"https://faucet.v4testnet.dydx.exchange" + "faucet":"https://faucet.v4testnet.dydx.exchange", + "geo": "https://api.dydx.exchange/v4/geo" }, "featureFlags":{ "reduceOnlySupported":false,