chore_: removed GetWalletToken because mobile not use it anymore (#6131)
This commit is contained in:
parent
8a7f24b095
commit
7a967e1775
|
@ -69,27 +69,6 @@ func (api *API) SetPairingsJSONFileContent(content []byte) error {
|
||||||
return api.s.keycardPairings.SetPairingsJSONFileContent(content)
|
return api.s.keycardPairings.SetPairingsJSONFileContent(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used by mobile
|
|
||||||
func (api *API) GetWalletToken(ctx context.Context, addresses []common.Address) (map[common.Address][]token.StorageToken, error) {
|
|
||||||
currency, err := api.s.accountsDB.GetCurrency()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
activeNetworks, err := api.s.rpcClient.NetworkManager.GetActiveNetworks()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
chainIDs := wcommon.NetworksToChainIDs(activeNetworks)
|
|
||||||
clients, err := api.s.rpcClient.EthClients(chainIDs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return api.reader.GetWalletToken(ctx, clients, addresses, currency)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *API) GetLastWalletTokenUpdate() map[common.Address]int64 {
|
func (api *API) GetLastWalletTokenUpdate() map[common.Address]int64 {
|
||||||
return api.reader.GetLastTokenUpdateTimestamps()
|
return api.reader.GetLastTokenUpdateTimestamps()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@ import (
|
||||||
gocommon "github.com/status-im/status-go/common"
|
gocommon "github.com/status-im/status-go/common"
|
||||||
"github.com/status-im/status-go/logutils"
|
"github.com/status-im/status-go/logutils"
|
||||||
"github.com/status-im/status-go/rpc/chain"
|
"github.com/status-im/status-go/rpc/chain"
|
||||||
"github.com/status-im/status-go/services/wallet/async"
|
|
||||||
"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/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/transfer"
|
||||||
"github.com/status-im/status-go/services/wallet/walletevent"
|
"github.com/status-im/status-go/services/wallet/walletevent"
|
||||||
|
@ -34,10 +32,6 @@ const (
|
||||||
activityReloadMarginSeconds = 30 // Trigger a wallet reload if activity is detected this many seconds before the last reload
|
activityReloadMarginSeconds = 30 // Trigger a wallet reload if activity is detected this many seconds before the last reload
|
||||||
)
|
)
|
||||||
|
|
||||||
func getFixedCurrencies() []string {
|
|
||||||
return []string{"USD"}
|
|
||||||
}
|
|
||||||
|
|
||||||
func belongsToMandatoryTokens(symbol string) bool {
|
func belongsToMandatoryTokens(symbol string) bool {
|
||||||
var mandatoryTokens = []string{"ETH", "DAI", "SNT", "STT"}
|
var mandatoryTokens = []string{"ETH", "DAI", "SNT", "STT"}
|
||||||
for _, t := range mandatoryTokens {
|
for _, t := range mandatoryTokens {
|
||||||
|
@ -463,100 +457,6 @@ func (r *Reader) createBalancePerChainPerSymbol(
|
||||||
return balancesPerChain
|
return balancesPerChain
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) GetWalletToken(ctx context.Context, clients map[uint64]chain.ClientInterface, addresses []common.Address, currency string) (map[common.Address][]token.StorageToken, error) {
|
|
||||||
currencies := make([]string, 0)
|
|
||||||
currencies = append(currencies, currency)
|
|
||||||
currencies = append(currencies, getFixedCurrencies()...)
|
|
||||||
|
|
||||||
result, err := r.FetchOrGetCachedWalletBalances(ctx, clients, addresses, true)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenSymbols := make([]string, 0)
|
|
||||||
for _, storageTokens := range result {
|
|
||||||
for _, t := range storageTokens {
|
|
||||||
tokenSymbols = append(tokenSymbols, t.Token.Symbol)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
group = async.NewAtomicGroup(ctx)
|
|
||||||
prices = map[string]map[string]market.DataPoint{}
|
|
||||||
tokenDetails = map[string]thirdparty.TokenDetails{}
|
|
||||||
tokenMarketValues = map[string]thirdparty.TokenMarketValues{}
|
|
||||||
)
|
|
||||||
|
|
||||||
group.Add(func(parent context.Context) error {
|
|
||||||
prices, err = r.marketManager.GetOrFetchPrices(tokenSymbols, currencies, market.MaxAgeInSecondsForBalances)
|
|
||||||
if err != nil {
|
|
||||||
logutils.ZapLogger().Info("marketManager.GetOrFetchPrices", zap.Error(err))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
group.Add(func(parent context.Context) error {
|
|
||||||
tokenDetails, err = r.marketManager.FetchTokenDetails(tokenSymbols)
|
|
||||||
if err != nil {
|
|
||||||
logutils.ZapLogger().Info("marketManager.FetchTokenDetails", zap.Error(err))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
group.Add(func(parent context.Context) error {
|
|
||||||
tokenMarketValues, err = r.marketManager.GetOrFetchTokenMarketValues(tokenSymbols, currency, market.MaxAgeInSecondsForBalances)
|
|
||||||
if err != nil {
|
|
||||||
logutils.ZapLogger().Info("marketManager.GetOrFetchTokenMarketValues", zap.Error(err))
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-group.WaitAsync():
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil, ctx.Err()
|
|
||||||
}
|
|
||||||
err = group.Error()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for address, tokens := range result {
|
|
||||||
for index, tok := range tokens {
|
|
||||||
marketValuesPerCurrency := make(map[string]token.TokenMarketValues)
|
|
||||||
for _, currency := range currencies {
|
|
||||||
if _, ok := tokenMarketValues[tok.Symbol]; !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
marketValuesPerCurrency[currency] = token.TokenMarketValues{
|
|
||||||
MarketCap: tokenMarketValues[tok.Symbol].MKTCAP,
|
|
||||||
HighDay: tokenMarketValues[tok.Symbol].HIGHDAY,
|
|
||||||
LowDay: tokenMarketValues[tok.Symbol].LOWDAY,
|
|
||||||
ChangePctHour: tokenMarketValues[tok.Symbol].CHANGEPCTHOUR,
|
|
||||||
ChangePctDay: tokenMarketValues[tok.Symbol].CHANGEPCTDAY,
|
|
||||||
ChangePct24hour: tokenMarketValues[tok.Symbol].CHANGEPCT24HOUR,
|
|
||||||
Change24hour: tokenMarketValues[tok.Symbol].CHANGE24HOUR,
|
|
||||||
Price: prices[tok.Symbol][currency].Price,
|
|
||||||
HasError: !r.marketManager.IsConnected,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := tokenDetails[tok.Symbol]; !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
result[address][index].Description = tokenDetails[tok.Symbol].Description
|
|
||||||
result[address][index].AssetWebsiteURL = tokenDetails[tok.Symbol].AssetWebsiteURL
|
|
||||||
result[address][index].BuiltOn = tokenDetails[tok.Symbol].BuiltOn
|
|
||||||
result[address][index].MarketValuesPerCurrency = marketValuesPerCurrency
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r.updateTokenUpdateTimestamp(addresses)
|
|
||||||
|
|
||||||
return result, r.persistence.SaveTokens(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLastTokenUpdateTimestamps returns last timestamps of successful token updates
|
// GetLastTokenUpdateTimestamps returns last timestamps of successful token updates
|
||||||
func (r *Reader) GetLastTokenUpdateTimestamps() map[common.Address]int64 {
|
func (r *Reader) GetLastTokenUpdateTimestamps() map[common.Address]int64 {
|
||||||
result := make(map[common.Address]int64)
|
result := make(map[common.Address]int64)
|
||||||
|
|
|
@ -1,216 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
||||||
"$id": "http://example.com/example.json",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"jsonrpc",
|
|
||||||
"result"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"jsonrpc": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"result": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"address",
|
|
||||||
"assetWebsiteUrl",
|
|
||||||
"balancesPerChain",
|
|
||||||
"builtOn",
|
|
||||||
"chainId",
|
|
||||||
"decimals",
|
|
||||||
"description",
|
|
||||||
"marketValuesPerCurrency",
|
|
||||||
"name",
|
|
||||||
"pegSymbol",
|
|
||||||
"symbol",
|
|
||||||
"tokenListId",
|
|
||||||
"verified"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"address": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"assetWebsiteUrl": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"balancesPerChain": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"31337"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"31337": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"address",
|
|
||||||
"balance",
|
|
||||||
"balance1DayAgo",
|
|
||||||
"chainId",
|
|
||||||
"hasError",
|
|
||||||
"rawBalance"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"address": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"balance": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"balance1DayAgo": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"chainId": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"hasError": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"rawBalance": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"builtOn": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"chainId": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"decimals": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"description": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"marketValuesPerCurrency": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"USD",
|
|
||||||
"usd"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"USD": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"change24hour",
|
|
||||||
"changePct24hour",
|
|
||||||
"changePctDay",
|
|
||||||
"changePctHour",
|
|
||||||
"hasError",
|
|
||||||
"highDay",
|
|
||||||
"lowDay",
|
|
||||||
"marketCap",
|
|
||||||
"price"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"change24hour": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"changePct24hour": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"changePctDay": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"changePctHour": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"hasError": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"highDay": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"lowDay": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"marketCap": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"price": {
|
|
||||||
"type": "number"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"usd": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"change24hour",
|
|
||||||
"changePct24hour",
|
|
||||||
"changePctDay",
|
|
||||||
"changePctHour",
|
|
||||||
"hasError",
|
|
||||||
"highDay",
|
|
||||||
"lowDay",
|
|
||||||
"marketCap",
|
|
||||||
"price"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"change24hour": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"changePct24hour": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"changePctDay": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"changePctHour": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"hasError": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"highDay": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"lowDay": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"marketCap": {
|
|
||||||
"type": "number"
|
|
||||||
},
|
|
||||||
"price": {
|
|
||||||
"type": "number"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"pegSymbol": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"symbol": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"tokenListId": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"verified": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -106,20 +106,3 @@ class TestRpc(StatusBackendTestCase):
|
||||||
|
|
||||||
response = self.rpc_client.rpc_valid_request(method, params, _id)
|
response = self.rpc_client.rpc_valid_request(method, params, _id)
|
||||||
self.rpc_client.verify_json_schema(response.json(), method)
|
self.rpc_client.verify_json_schema(response.json(), method)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.wallet
|
|
||||||
@pytest.mark.rpc
|
|
||||||
class TestRpcStatusD(StatusDTestCase): # temp for methods not implemented in Status Backend
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"method, params",
|
|
||||||
[
|
|
||||||
("wallet_getWalletToken", [[user_1.address, ]]),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_(self, method, params):
|
|
||||||
_id = str(random.randint(1, 8888))
|
|
||||||
|
|
||||||
response = self.rpc_client.rpc_valid_request(method, params, _id)
|
|
||||||
self.rpc_client.verify_json_schema(response.json(), method)
|
|
||||||
|
|
Loading…
Reference in New Issue