mirror of
https://github.com/status-im/status-go.git
synced 2025-02-18 01:37:22 +00:00
chore: improvements to GetWalletToken
function
This commit is contained in:
parent
ff755a1176
commit
1754c23763
@ -28,6 +28,16 @@ func getFixedCurrencies() []string {
|
|||||||
return []string{"USD"}
|
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 {
|
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}
|
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) {
|
for symbol, tokens := range getTokenBySymbols(allTokens) {
|
||||||
balancesPerChain := make(map[uint64]ChainBalance)
|
balancesPerChain := make(map[uint64]ChainBalance)
|
||||||
decimals := tokens[0].Decimals
|
decimals := tokens[0].Decimals
|
||||||
|
anyPositiveBalance := false
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
hexBalance := balances[token.ChainID][address][token.Address]
|
hexBalance := balances[token.ChainID][address][token.Address]
|
||||||
balance := big.NewFloat(0.0)
|
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 {
|
if client, ok := clients[token.ChainID]; ok {
|
||||||
hasError = err != nil || !client.IsConnected
|
hasError = err != nil || !client.IsConnected
|
||||||
}
|
}
|
||||||
|
if !anyPositiveBalance {
|
||||||
|
anyPositiveBalance = balance.Cmp(big.NewFloat(0.0)) > 0
|
||||||
|
}
|
||||||
balancesPerChain[token.ChainID] = ChainBalance{
|
balancesPerChain[token.ChainID] = ChainBalance{
|
||||||
Balance: balance,
|
Balance: balance,
|
||||||
Address: token.Address,
|
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)
|
marketValuesPerCurrency := make(map[string]TokenMarketValues)
|
||||||
for _, currency := range currencies {
|
for _, currency := range currencies {
|
||||||
marketValuesPerCurrency[currency] = TokenMarketValues{
|
marketValuesPerCurrency[currency] = TokenMarketValues{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user