diff --git a/services/wallet/api.go b/services/wallet/api.go index 03338a7d3..3afda097f 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -215,14 +215,24 @@ func (api *API) GetCryptoOnRamps(ctx context.Context) ([]CryptoOnRamp, error) { return api.s.cryptoOnRampManager.Get() } -func (api *API) GetOpenseaCollectionsByOwner(ctx context.Context, owner common.Address) ([]OpenseaCollection, error) { +func (api *API) GetOpenseaCollectionsByOwner(ctx context.Context, chainID uint64, owner common.Address) ([]OpenseaCollection, error) { log.Debug("call to get opensea collections") - return api.s.opensea.fetchAllCollectionsByOwner(owner) + client, err := newOpenseaClient(chainID) + if err != nil { + return nil, err + } + + return client.fetchAllCollectionsByOwner(owner) } -func (api *API) GetOpenseaAssetsByOwnerAndCollection(ctx context.Context, owner common.Address, collectionSlug string, limit int) ([]OpenseaAsset, error) { +func (api *API) GetOpenseaAssetsByOwnerAndCollection(ctx context.Context, chainID uint64, owner common.Address, collectionSlug string, limit int) ([]OpenseaAsset, error) { log.Debug("call to get opensea assets") - return api.s.opensea.fetchAllAssetsByOwnerAndCollection(owner, collectionSlug, limit) + client, err := newOpenseaClient(chainID) + if err != nil { + return nil, err + } + + return client.fetchAllAssetsByOwnerAndCollection(owner, collectionSlug, limit) } func (api *API) AddEthereumChain(ctx context.Context, network network.Network) error { diff --git a/services/wallet/opensea.go b/services/wallet/opensea.go index 2b68783d5..7048c8191 100644 --- a/services/wallet/opensea.go +++ b/services/wallet/opensea.go @@ -2,6 +2,7 @@ package wallet import ( "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -15,6 +16,11 @@ import ( const AssetLimit = 50 const CollectionLimit = 300 +var BaseURLs = map[uint64]string{ + 1: "https://api.opensea.io/api/v1", + 4: "https://rinkeby-api.opensea.io/api/v1", +} + type TraitValue string func (st *TraitValue) UnmarshalJSON(b []byte) error { @@ -106,12 +112,15 @@ type OpenseaClient struct { } // new opensea client. -func newOpenseaClient() *OpenseaClient { +func newOpenseaClient(chainID uint64) (*OpenseaClient, error) { client := &http.Client{ Timeout: time.Second * 5, } + if url, ok := BaseURLs[chainID]; ok { + return &OpenseaClient{client: client, url: url}, nil + } - return &OpenseaClient{client: client, url: "https://api.opensea.io/api/v1"} + return nil, errors.New("ChainID not supported") } func (o *OpenseaClient) fetchAllCollectionsByOwner(owner common.Address) ([]OpenseaCollection, error) { diff --git a/services/wallet/service.go b/services/wallet/service.go index 2a80cda78..b05ccacc4 100644 --- a/services/wallet/service.go +++ b/services/wallet/service.go @@ -36,7 +36,6 @@ func NewService(db *sql.DB, legacyChainID uint64, legacyClient *ethclient.Client savedAddressesManager: savedAddressesManager, transactionManager: transactionManager, transferController: transferController, - opensea: newOpenseaClient(), cryptoOnRampManager: cryptoOnRampManager, legacyChainID: legacyChainID, } @@ -51,7 +50,6 @@ type Service struct { favouriteManager *FavouriteManager cryptoOnRampManager *CryptoOnRampManager transferController *transfer.Controller - opensea *OpenseaClient legacyChainID uint64 started bool }