Skip to content

Commit

Permalink
write only key for nfts, no need for balance
Browse files Browse the repository at this point in the history
  • Loading branch information
matijamarjanovic committed Jan 17, 2025
1 parent b107e7d commit 936f181
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,16 @@ func getBalances(addr std.Address) string {
nftGetter := value.(grc721.NFTGetter)
nft := nftGetter()
key_parts := strings.Split(key, ".")
if addr == nft.OwnerOf(grc721.TokenID(key_parts[len(key_parts)-1])) { // show only the nfts owner owns
balances.Set("nft:"+key)
owner, err := nft.OwnerOf(grc721.TokenID(key_parts[len(key_parts)-1]))
if err == nil && addr == owner { // show only the nfts owner owns
balances.Set("nft:"+key, 1)
}
return false
})

grc20reg.Iterate(func(key string, tokenGetter grc20.TokenGetter) bool {
token := tokenGetter()
balance := token.BalanceOf(addr)
balance := token.BalanceOf(addr)
if balance > 0 {
balances.Set("token:"+key, balance)
}
Expand All @@ -430,9 +430,8 @@ func getBalances(addr std.Address) string {
balances.Iterate("", "", func(key string, value interface{}) bool {
switch {
case strings.HasPrefix(key, "nft:"):
balance := value.(uint64)
symbol := strings.TrimPrefix(key, "nft:")
sb.WriteString(ufmt.Sprintf("NFT:%s:%d,", symbol, balance))
sb.WriteString(ufmt.Sprintf("NFT:%s,", symbol))
case strings.HasPrefix(key, "token:"):
balance := value.(uint64)
symbol := strings.TrimPrefix(key, "token:")
Expand Down Expand Up @@ -461,8 +460,9 @@ func getNonZeroBalances(addr std.Address) string {
nftGetter := value.(grc721.NFTGetter)
nft := nftGetter()
key_parts := strings.Split(key, ".")
if addr == nft.OwnerOf(grc721.TokenID(key_parts[len(key_parts)-1])) { // show only the nfts owner owns
balances.Set("nft:"+key)
owner, err := nft.OwnerOf(grc721.TokenID(key_parts[len(key_parts)-1]))
if err == nil && addr == owner { // show only the nfts owner owns
balances.Set("nft:"+key, 1)
}
return false
})
Expand Down Expand Up @@ -490,9 +490,8 @@ func getNonZeroBalances(addr std.Address) string {
balances.Iterate("", "", func(key string, value interface{}) bool {
switch {
case strings.HasPrefix(key, "nft:"):
balance := value.(uint64)
symbol := strings.TrimPrefix(key, "nft:")
sb.WriteString(ufmt.Sprintf("NFT:%s:%d,", symbol, balance))
sb.WriteString(ufmt.Sprintf("NFT:%s,", symbol))
case strings.HasPrefix(key, "token:"):
balance := value.(uint64)
symbol := strings.TrimPrefix(key, "token:")
Expand Down

0 comments on commit 936f181

Please sign in to comment.