From 80f25d5ff7828478d27cbbf2af474be578b79f08 Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Tue, 3 Oct 2023 15:53:36 -0300 Subject: [PATCH] fix: misc collectibles fixes --- services/wallet/collectibles/manager.go | 5 ++++- services/wallet/thirdparty/alchemy/client.go | 7 +++++++ services/wallet/thirdparty/alchemy/types.go | 20 ++++++++++++++++--- services/wallet/thirdparty/infura/client.go | 8 ++++++++ services/wallet/thirdparty/opensea/client.go | 5 +++++ .../wallet/thirdparty/opensea/client_v2.go | 5 +++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/services/wallet/collectibles/manager.go b/services/wallet/collectibles/manager.go index 6e563a1d2..e634fd2c2 100644 --- a/services/wallet/collectibles/manager.go +++ b/services/wallet/collectibles/manager.go @@ -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 { diff --git a/services/wallet/thirdparty/alchemy/client.go b/services/wallet/thirdparty/alchemy/client.go index 841de3554..d3e7f6b15 100644 --- a/services/wallet/thirdparty/alchemy/client.go +++ b/services/wallet/thirdparty/alchemy/client.go @@ -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, diff --git a/services/wallet/thirdparty/alchemy/types.go b/services/wallet/thirdparty/alchemy/types.go index 9d9d16d75..cec2ef891 100644 --- a/services/wallet/thirdparty/alchemy/types.go +++ b/services/wallet/thirdparty/alchemy/types.go @@ -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), } } diff --git a/services/wallet/thirdparty/infura/client.go b/services/wallet/thirdparty/infura/client.go index b96a95388..e6a2377ad 100644 --- a/services/wallet/thirdparty/infura/client.go +++ b/services/wallet/thirdparty/infura/client.go @@ -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, diff --git a/services/wallet/thirdparty/opensea/client.go b/services/wallet/thirdparty/opensea/client.go index 670f6bf35..f2973e6a0 100644 --- a/services/wallet/thirdparty/opensea/client.go +++ b/services/wallet/thirdparty/opensea/client.go @@ -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, diff --git a/services/wallet/thirdparty/opensea/client_v2.go b/services/wallet/thirdparty/opensea/client_v2.go index 48bb65efb..deef07741 100644 --- a/services/wallet/thirdparty/opensea/client_v2.go +++ b/services/wallet/thirdparty/opensea/client_v2.go @@ -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,