From 1754c237631a7df53f430fa3da0612c9f467d376 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Thu, 6 Apr 2023 16:59:17 +0200 Subject: [PATCH] chore: improvements to `GetWalletToken` function --- services/wallet/reader.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/services/wallet/reader.go b/services/wallet/reader.go index 48399b29d..3eeea4eff 100644 --- a/services/wallet/reader.go +++ b/services/wallet/reader.go @@ -28,6 +28,16 @@ func getFixedCurrencies() []string { return []string{"USD"} } +func belongsToMandatoryTokens(symbol string) bool { + var mandatoryTokens = []string{"ETH", "DAI", "SNT", "STT"} + for _, t := range mandatoryTokens { + if t == symbol { + return true + } + } + return false +} + func NewReader(rpcClient *rpc.Client, tokenManager *token.Manager, marketManager *market.Manager, accountsDB *accounts.Database, walletFeed *event.Feed) *Reader { return &Reader{rpcClient, tokenManager, marketManager, accountsDB, walletFeed, nil} } @@ -224,6 +234,7 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address) for symbol, tokens := range getTokenBySymbols(allTokens) { balancesPerChain := make(map[uint64]ChainBalance) decimals := tokens[0].Decimals + anyPositiveBalance := false for _, token := range tokens { hexBalance := balances[token.ChainID][address][token.Address] balance := big.NewFloat(0.0) @@ -237,6 +248,9 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address) if client, ok := clients[token.ChainID]; ok { hasError = err != nil || !client.IsConnected } + if !anyPositiveBalance { + anyPositiveBalance = balance.Cmp(big.NewFloat(0.0)) > 0 + } balancesPerChain[token.ChainID] = ChainBalance{ Balance: balance, Address: token.Address, @@ -245,6 +259,10 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address) } } + if !anyPositiveBalance && !belongsToMandatoryTokens(symbol) { + continue + } + marketValuesPerCurrency := make(map[string]TokenMarketValues) for _, currency := range currencies { marketValuesPerCurrency[currency] = TokenMarketValues{