From b107e7d79e4cdbba958cdced2bace05072f2a118 Mon Sep 17 00:00:00 2001 From: matijamarjanovic Date: Fri, 17 Jan 2025 20:16:57 +0100 Subject: [PATCH] fix: show only nfts and grc1155 owner has, because there could be who knows how many of those he does not --- .../r/matijamarjanovic/tokenhub/tokenhub.gno | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno b/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno index 6164b3466a3..47e885ad260 100644 --- a/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno +++ b/examples/gno.land/r/matijamarjanovic/tokenhub/tokenhub.gno @@ -399,15 +399,20 @@ func getBalances(addr std.Address) string { registeredNFTs.Iterate("", "", func(key string, value interface{}) bool { nftGetter := value.(grc721.NFTGetter) nft := nftGetter() - balance, _ := nft.BalanceOf(addr) - balances.Set("nft:"+key, balance) + 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) + } return false }) grc20reg.Iterate(func(key string, tokenGetter grc20.TokenGetter) bool { token := tokenGetter() balance := token.BalanceOf(addr) - balances.Set("token:"+key, balance) + balance := token.BalanceOf(addr) + if balance > 0 { + balances.Set("token:"+key, balance) + } return false }) @@ -455,9 +460,9 @@ func getNonZeroBalances(addr std.Address) string { registeredNFTs.Iterate("", "", func(key string, value interface{}) bool { nftGetter := value.(grc721.NFTGetter) nft := nftGetter() - balance, _ := nft.BalanceOf(addr) - if balance > 0 { - balances.Set("nft:"+key, balance) + 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) } return false })