From 7b6fc87f89c03b534644057d5608bc1085447484 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Thu, 9 Mar 2023 17:03:57 -0300 Subject: [PATCH] fix(wallet): use OpenSea api key only for mainnet endpoint --- services/wallet/thirdparty/opensea/client.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/services/wallet/thirdparty/opensea/client.go b/services/wallet/thirdparty/opensea/client.go index c47f51c33..1198241fa 100644 --- a/services/wallet/thirdparty/opensea/client.go +++ b/services/wallet/thirdparty/opensea/client.go @@ -32,6 +32,8 @@ var BaseURLs = map[uint64]string{ 5: "https://testnets-api.opensea.io/api/v1", } +const ChainIDRequiringAPIKey = 1 + type TraitValue string type NFTUniqueID struct { @@ -138,8 +140,12 @@ type Client struct { // new opensea client. func NewOpenseaClient(chainID uint64, apiKey string) (*Client, error) { + var tmpAPIKey string = "" + if chainID == ChainIDRequiringAPIKey { + tmpAPIKey = apiKey + } if client, ok := OpenseaClientInstances[chainID]; ok { - if client.apiKey == apiKey { + if client.apiKey == tmpAPIKey { return client, nil } } @@ -151,7 +157,7 @@ func NewOpenseaClient(chainID uint64, apiKey string) (*Client, error) { openseaClient := &Client{ client: client, url: url, - apiKey: apiKey, + apiKey: tmpAPIKey, IsConnected: true, LastCheckedAt: time.Now().Unix(), } @@ -282,7 +288,9 @@ func (o *Client) doOpenseaRequest(url string) ([]byte, error) { req.Header.Set("Content-Type", "application/json") req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0") - req.Header.Set("X-API-KEY", o.apiKey) + if len(o.apiKey) > 0 { + req.Header.Set("X-API-KEY", o.apiKey) + } resp, err := o.client.Do(req) if err != nil {