fix: misc collectibles fixes

This commit is contained in:
Dario Gabriel Lipicar 2023-10-03 15:53:36 -03:00 committed by dlipicar
parent 2bcf08f273
commit 80f25d5ff7
6 changed files with 46 additions and 4 deletions

View File

@ -543,7 +543,10 @@ func (o *Manager) processFullCollectibleData(assets []thirdparty.FullCollectible
if canProvide {
metadata, err := o.metadataProvider.FetchCollectibleMetadata(id, tokenURI)
if err != nil {
return err
// Metadata is available but fetching failed.
// Ideally we would retry, but for now we just skip it.
log.Error("Failed to fetch collectible metadata", "err", err)
continue
}
if metadata != nil {

View File

@ -10,6 +10,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/connection"
"github.com/status-im/status-go/services/wallet/thirdparty"
@ -77,6 +78,12 @@ type Client struct {
}
func NewClient(apiKeys map[uint64]string) *Client {
for _, chainID := range walletCommon.AllChainIDs() {
if apiKeys[uint64(chainID)] == "" {
log.Warn("Alchemy API key not available for", "chainID", chainID)
}
}
return &Client{
client: &http.Client{Timeout: time.Minute},
apiKeys: apiKeys,

View File

@ -82,7 +82,19 @@ type RawMetadata struct {
}
type Raw struct {
RawMetadata RawMetadata `json:"metadata"`
RawMetadata interface{} `json:"metadata"`
}
func (r *Raw) UnmarshalJSON(b []byte) error {
metadata := RawMetadata{
Attributes: make([]Attribute, 0),
}
// Field structure is not known in advance
_ = json.Unmarshal(b, &metadata)
r.RawMetadata = metadata
return nil
}
type OpenSeaMetadata struct {
@ -166,14 +178,16 @@ func (c *Contract) toCollectionData(id thirdparty.ContractID) thirdparty.Collect
}
func (c *Asset) toCollectiblesData(id thirdparty.CollectibleUniqueID) thirdparty.CollectibleData {
rawMetadata := c.Raw.RawMetadata.(RawMetadata)
return thirdparty.CollectibleData{
ID: id,
Provider: AlchemyID,
Name: c.Name,
Description: c.Description,
ImageURL: c.Image.ImageURL,
AnimationURL: c.Image.OriginalAnimationURL,
Traits: alchemyToCollectibleTraits(c.Raw.RawMetadata.Attributes),
AnimationURL: c.Image.CachedAnimationURL,
Traits: alchemyToCollectibleTraits(rawMetadata.Attributes),
}
}

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/connection"
"github.com/status-im/status-go/services/wallet/thirdparty"
@ -25,6 +26,13 @@ type Client struct {
}
func NewClient(apiKey string, apiKeySecret string) *Client {
if apiKey == "" {
log.Warn("Infura API key not available")
}
if apiKeySecret == "" {
log.Warn("Infura API key secret not available")
}
return &Client{
client: &http.Client{Timeout: time.Minute},
apiKey: apiKey,

View File

@ -8,6 +8,7 @@ import (
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/connection"
@ -62,6 +63,10 @@ type Client struct {
// new opensea v1 client.
func NewClient(apiKey string, httpClient *HTTPClient) *Client {
if apiKey == "" {
log.Warn("OpenseaV1 API key not available")
}
return &Client{
client: httpClient,
apiKey: apiKey,

View File

@ -8,6 +8,7 @@ import (
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/connection"
@ -58,6 +59,10 @@ type ClientV2 struct {
// new opensea v2 client.
func NewClientV2(apiKey string, httpClient *HTTPClient) *ClientV2 {
if apiKey == "" {
log.Warn("OpenseaV2 API key not available")
}
return &ClientV2{
client: httpClient,
apiKey: apiKey,