Skip to content

Commit ed50ce2

Browse files
committed
fix issue that prevents collection names to be shown
1 parent c2127c8 commit ed50ce2

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

internal/collections/collection.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/benleb/gloomberg/internal/cache"
1212
"github.com/benleb/gloomberg/internal/gbl"
1313
"github.com/benleb/gloomberg/internal/gbnode"
14+
"github.com/benleb/gloomberg/internal/style"
1415
"github.com/charmbracelet/lipgloss"
1516
"github.com/ethereum/go-ethereum/common"
1617
"github.com/spf13/viper"
@@ -82,28 +83,29 @@ func NewCollection(contractAddress common.Address, name string, nodes *gbnode.No
8283
var collectionName string
8384

8485
cache := cache.New(ctx)
85-
nameInCache := false
8686

8787
if name != "" {
8888
collectionName = name
89-
} else if viper.GetBool("redis.enabled") {
90-
// check if the collection is already in the cache
91-
if name, err := cache.GetCollectionName(contractAddress); err == nil && name != "" {
89+
} else {
90+
if name, err := cache.GetCollectionName(contractAddress); err == nil {
9291
gbl.Log.Infof("cache | cached collection name: %s", name)
9392

94-
collectionName = name
95-
nameInCache = true
96-
}
97-
} else {
98-
collectionName = nodes.GetRandomNode().GetCollectionName(contractAddress)
99-
}
93+
if name != "" {
94+
collectionName = name
95+
}
96+
} else if name, err := nodes.GetRandomNode().GetCollectionName(contractAddress); err == nil {
97+
gbl.Log.Infof("chain | collection name via contract call: %s", name)
10098

101-
if collectionName != "" && !nameInCache {
102-
// cache collection name
103-
if viper.GetBool("redis.enabled") {
104-
gbl.Log.Infof("cache | caching collection name: %s", collectionName)
99+
if name != "" {
100+
collectionName = name
101+
}
105102

103+
// cache collection name
106104
cache.CacheCollectionName(contractAddress, collectionName)
105+
} else {
106+
gbl.Log.Errorf("error getting collection name, using: %s | %s", style.ShortenAddress(&contractAddress), err)
107+
108+
collectionName = style.ShortenAddress(&contractAddress)
107109
}
108110
}
109111

0 commit comments

Comments
 (0)