feat: enable rinkeby for opensea (#2357)
This commit is contained in:
parent
59eeed9436
commit
95dcbef5e5
|
@ -215,14 +215,24 @@ func (api *API) GetCryptoOnRamps(ctx context.Context) ([]CryptoOnRamp, error) {
|
||||||
return api.s.cryptoOnRampManager.Get()
|
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")
|
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")
|
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 {
|
func (api *API) AddEthereumChain(ctx context.Context, network network.Network) error {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package wallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -15,6 +16,11 @@ import (
|
||||||
const AssetLimit = 50
|
const AssetLimit = 50
|
||||||
const CollectionLimit = 300
|
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
|
type TraitValue string
|
||||||
|
|
||||||
func (st *TraitValue) UnmarshalJSON(b []byte) error {
|
func (st *TraitValue) UnmarshalJSON(b []byte) error {
|
||||||
|
@ -106,12 +112,15 @@ type OpenseaClient struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// new opensea client.
|
// new opensea client.
|
||||||
func newOpenseaClient() *OpenseaClient {
|
func newOpenseaClient(chainID uint64) (*OpenseaClient, error) {
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Timeout: time.Second * 5,
|
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) {
|
func (o *OpenseaClient) fetchAllCollectionsByOwner(owner common.Address) ([]OpenseaCollection, error) {
|
||||||
|
|
|
@ -36,7 +36,6 @@ func NewService(db *sql.DB, legacyChainID uint64, legacyClient *ethclient.Client
|
||||||
savedAddressesManager: savedAddressesManager,
|
savedAddressesManager: savedAddressesManager,
|
||||||
transactionManager: transactionManager,
|
transactionManager: transactionManager,
|
||||||
transferController: transferController,
|
transferController: transferController,
|
||||||
opensea: newOpenseaClient(),
|
|
||||||
cryptoOnRampManager: cryptoOnRampManager,
|
cryptoOnRampManager: cryptoOnRampManager,
|
||||||
legacyChainID: legacyChainID,
|
legacyChainID: legacyChainID,
|
||||||
}
|
}
|
||||||
|
@ -51,7 +50,6 @@ type Service struct {
|
||||||
favouriteManager *FavouriteManager
|
favouriteManager *FavouriteManager
|
||||||
cryptoOnRampManager *CryptoOnRampManager
|
cryptoOnRampManager *CryptoOnRampManager
|
||||||
transferController *transfer.Controller
|
transferController *transfer.Controller
|
||||||
opensea *OpenseaClient
|
|
||||||
legacyChainID uint64
|
legacyChainID uint64
|
||||||
started bool
|
started bool
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue