From 1d173734a608de2d71480d6ad39f4559f11a75e2 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Mon, 19 Aug 2024 16:27:53 -0300 Subject: [PATCH] fix(wallet)_: set a separate id (and circuit) for the cryptcompare proxy --- services/wallet/service.go | 1 + .../wallet/thirdparty/cryptocompare/client.go | 14 +++++++++----- .../thirdparty/cryptocompare/client_test.go | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 services/wallet/thirdparty/cryptocompare/client_test.go diff --git a/services/wallet/service.go b/services/wallet/service.go index 7bd3dbaa9..9ddeb597b 100644 --- a/services/wallet/service.go +++ b/services/wallet/service.go @@ -120,6 +120,7 @@ func NewService( cryptoCompare := cryptocompare.NewClient() coingecko := coingecko.NewClient() cryptoCompareProxy := cryptocompare.NewClientWithParams(cryptocompare.Params{ + ID: fmt.Sprintf("%s-proxy", cryptoCompare.ID()), URL: fmt.Sprintf("https://%s.api.status.im/cryptocompare/", statusProxyStageName), User: config.WalletConfig.StatusProxyMarketUser, Password: config.WalletConfig.StatusProxyMarketPassword, diff --git a/services/wallet/thirdparty/cryptocompare/client.go b/services/wallet/thirdparty/cryptocompare/client.go index 09df4cee0..892a9bc1e 100644 --- a/services/wallet/thirdparty/cryptocompare/client.go +++ b/services/wallet/thirdparty/cryptocompare/client.go @@ -11,6 +11,7 @@ import ( "github.com/status-im/status-go/services/wallet/thirdparty/utils" ) +const baseID = "cryptocompare" const extraParamStatus = "Status.im" const baseURL = "https://min-api.cryptocompare.com" @@ -34,22 +35,24 @@ type MarketValuesContainer struct { } type Params struct { + ID string URL string User string Password string } type Client struct { + id string httpClient *thirdparty.HTTPClient baseURL string creds *thirdparty.BasicCreds } func NewClient() *Client { - return &Client{ - httpClient: thirdparty.NewHTTPClient(), - baseURL: baseURL, - } + return NewClientWithParams(Params{ + ID: baseID, + URL: baseURL, + }) } func NewClientWithParams(params Params) *Client { @@ -62,6 +65,7 @@ func NewClientWithParams(params Params) *Client { } return &Client{ + id: params.ID, httpClient: thirdparty.NewHTTPClient(), baseURL: params.URL, creds: creds, @@ -215,5 +219,5 @@ func (c *Client) FetchHistoricalDailyPrices(symbol string, currency string, limi } func (c *Client) ID() string { - return "cryptocompare" + return c.id } diff --git a/services/wallet/thirdparty/cryptocompare/client_test.go b/services/wallet/thirdparty/cryptocompare/client_test.go new file mode 100644 index 000000000..7477380ef --- /dev/null +++ b/services/wallet/thirdparty/cryptocompare/client_test.go @@ -0,0 +1,17 @@ +package cryptocompare + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIDs(t *testing.T) { + stdClient := NewClient() + require.Equal(t, baseID, stdClient.ID()) + + clientWithParams := NewClientWithParams(Params{ + ID: "testID", + }) + require.Equal(t, "testID", clientWithParams.ID()) +}