Fix balance cache on switching to testnet (#4924)

This commit is contained in:
Roman Volosovskyi 2024-03-15 13:37:00 +01:00 committed by GitHub
parent 2c634a2b45
commit 38183ab335
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -1 +1 @@
0.176.10 0.176.11

View File

@ -19,9 +19,8 @@ import (
"github.com/status-im/status-go/services/wallet/community" "github.com/status-im/status-go/services/wallet/community"
"github.com/status-im/status-go/services/wallet/market" "github.com/status-im/status-go/services/wallet/market"
"github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/thirdparty"
"github.com/status-im/status-go/services/wallet/transfer"
"github.com/status-im/status-go/services/wallet/token" "github.com/status-im/status-go/services/wallet/token"
"github.com/status-im/status-go/services/wallet/transfer"
"github.com/status-im/status-go/services/wallet/walletevent" "github.com/status-im/status-go/services/wallet/walletevent"
) )
@ -329,11 +328,28 @@ func (r *Reader) getWalletTokenBalances(ctx context.Context, addresses []common.
cachedBalancesPerChain := map[common.Address]map[common.Address]map[uint64]string{} cachedBalancesPerChain := map[common.Address]map[common.Address]map[uint64]string{}
updateAnyway := false updateAnyway := false
if !updateBalances { if !updateBalances {
cacheCheck:
for _, address := range addresses { for _, address := range addresses {
if _, ok := cachedTokens[address]; !ok { if res, ok := cachedTokens[address]; !ok || len(res) == 0 {
updateAnyway = true updateAnyway = true
break break
} }
networkFound := map[uint64]bool{}
for _, token := range cachedTokens[address] {
for _, chain := range chainIDs {
if _, ok := token.BalancesPerChain[chain]; ok {
networkFound[chain] = true
}
}
}
for _, chain := range chainIDs {
if !networkFound[chain] {
updateAnyway = true
break cacheCheck
}
}
} }
} }