@@ -36,8 +36,7 @@ import (
3636 "github.com/status-im/status-go/services/wallet/router"
3737 "github.com/status-im/status-go/services/wallet/router/fees"
3838 "github.com/status-im/status-go/services/wallet/thirdparty"
39- "github.com/status-im/status-go/services/wallet/token"
40- tokenTypes "github.com/status-im/status-go/services/wallet/token/types"
39+ tokentypes "github.com/status-im/status-go/services/wallet/token/types"
4140 "github.com/status-im/status-go/services/wallet/transfer"
4241 "github.com/status-im/status-go/services/wallet/walletconnect"
4342 "github.com/status-im/status-go/services/wallet/wallettypes"
@@ -78,7 +77,18 @@ func (api *API) GetLastWalletTokenUpdate() map[common.Address]int64 {
7877
7978// GetBalancesByChain return a map with key as chain id and value as map of account address and map of token address and balance
8079// [chainID][account][token]balance
81- func (api * API ) GetBalancesByChain (ctx context.Context , chainIDs []uint64 , addresses , tokens []common.Address ) (map [uint64 ]map [common.Address ]map [common.Address ]* hexutil.Big , error ) {
80+ func (api * API ) GetBalancesByChain (ctx context.Context , addresses []common.Address , tokenKeys []string ) (map [uint64 ]map [common.Address ]map [common.Address ]* hexutil.Big , error ) {
81+ tokens := make ([]* tokentypes.Token , 0 )
82+ chainIDs := make ([]uint64 , 0 )
83+ for _ , tokenKey := range tokenKeys {
84+ token , err := api .s .tokenManager .GetTokenByKey (tokenKey )
85+ if err != nil {
86+ return nil , err
87+ }
88+ tokens = append (tokens , token )
89+ chainIDs = append (chainIDs , token .ChainID )
90+ }
91+
8292 clients , err := api .s .rpcClient .EthClients (chainIDs )
8393 if err != nil {
8494 return nil , err
@@ -87,7 +97,7 @@ func (api *API) GetBalancesByChain(ctx context.Context, chainIDs []uint64, addre
8797 return api .s .tokenManager .GetBalancesByChain (ctx , clients , addresses , tokens )
8898}
8999
90- func (api * API ) FetchOrGetCachedWalletBalances (ctx context.Context , addresses []common.Address , forceRefresh bool ) (map [common.Address ][]tokenTypes .StorageToken , error ) {
100+ func (api * API ) FetchOrGetCachedWalletBalances (ctx context.Context , addresses []common.Address , forceRefresh bool ) (map [common.Address ][]tokentypes .StorageToken , error ) {
91101 activeNetworks , err := api .s .rpcClient .GetNetworkManager ().GetActiveNetworks ()
92102 if err != nil {
93103 return nil , err
@@ -117,11 +127,10 @@ func (api *API) FetchDecodedTxData(ctx context.Context, data string) (*thirdpart
117127}
118128
119129// GetBalanceHistory retrieves token balance history for token identity on multiple chains
120- func (api * API ) GetBalanceHistory (ctx context.Context , chainIDs [] uint64 , addresses []common.Address , tokenSymbol string , currencySymbol string , timeInterval history.TimeInterval ) ([]* history.ValuePoint , error ) {
130+ func (api * API ) GetBalanceHistory (ctx context.Context , addresses []common.Address , tokenKeys [] string , currencySymbol string , timeInterval history.TimeInterval ) ([]* history.ValuePoint , error ) {
121131 logutils .ZapLogger ().Debug ("wallet.api.GetBalanceHistory" ,
122- zap .Uint64s ("chainIDs" , chainIDs ),
123132 zap .Stringers ("address" , addresses ),
124- zap .String ( "tokenSymbol " , tokenSymbol ),
133+ zap .Strings ( "tokenKeys " , tokenKeys ),
125134 zap .String ("currencySymbol" , currencySymbol ),
126135 zap .Int ("timeInterval" , int (timeInterval )),
127136 )
@@ -143,57 +152,43 @@ func (api *API) GetBalanceHistory(ctx context.Context, chainIDs []uint64, addres
143152 return nil , fmt .Errorf ("unknown time interval: %v" , timeInterval )
144153 }
145154
146- return api .GetBalanceHistoryRange (ctx , chainIDs , addresses , tokenSymbol , currencySymbol , fromTimestamp , now )
155+ return api .GetBalanceHistoryRange (ctx , addresses , tokenKeys , currencySymbol , fromTimestamp , now )
147156}
148157
149158// GetBalanceHistoryRange retrieves token balance history for token identity on multiple chains for a time range
150159// 'toTimestamp' is ignored for now, but will be used in the future to limit the range of the history
151- func (api * API ) GetBalanceHistoryRange (ctx context.Context , chainIDs [] uint64 , addresses []common.Address , tokenSymbol string , currencySymbol string , fromTimestamp uint64 , _ uint64 ) ([]* history.ValuePoint , error ) {
160+ func (api * API ) GetBalanceHistoryRange (ctx context.Context , addresses []common.Address , tokenKeys [] string , currencySymbol string , fromTimestamp uint64 , _ uint64 ) ([]* history.ValuePoint , error ) {
152161 logutils .ZapLogger ().Debug ("wallet.api.GetBalanceHistoryRange" ,
153- zap .Uint64s ("chainIDs" , chainIDs ),
154162 zap .Stringers ("address" , addresses ),
155- zap .String ( "tokenSymbol " , tokenSymbol ),
163+ zap .Strings ( "tokenKeys " , tokenKeys ),
156164 zap .String ("currencySymbol" , currencySymbol ),
157165 zap .Uint64 ("fromTimestamp" , fromTimestamp ),
158166 )
159- return api .s .history .GetBalanceHistory (ctx , chainIDs , addresses , tokenSymbol , currencySymbol , fromTimestamp )
167+ return api .s .history .GetBalanceHistory (ctx , addresses , tokenKeys , currencySymbol , fromTimestamp )
160168}
161169
162- func (api * API ) GetTokenList (ctx context.Context ) (* token. ListWrapper , error ) {
170+ func (api * API ) GetAllTokenLists (ctx context.Context ) ([] * tokentypes. TokenList , error ) {
163171 logutils .ZapLogger ().Debug ("call to get token list" )
164- rst := api .s .tokenManager .GetList ()
165- logutils .ZapLogger ().Debug ("result from token list" , zap .Int ("len" , len (rst .Data )))
166- return rst , nil
172+ return api .s .tokenManager .GetAllTokenLists ()
167173}
168174
169- func (api * API ) GetTokensAvailableForBridgeOnChain (ctx context.Context , chainID uint64 ) []* tokenTypes .Token {
170- logutils .ZapLogger ().Debug ("call to get tokens available for bridge on chain " )
171- return api .s .router . GetTokensAvailableForBridgeOnChain ( chainID )
175+ func (api * API ) GetAllTokens (ctx context.Context ) ( []* tokentypes .Token , error ) {
176+ logutils .ZapLogger ().Debug ("call to get all tokens " )
177+ return api .s .tokenManager . GetAllTokens ( )
172178}
173179
174- // @deprecated
175- func (api * API ) GetTokens (ctx context.Context , chainID uint64 ) ([]* tokenTypes.Token , error ) {
176- logutils .ZapLogger ().Debug ("call to get tokens" )
177- rst , err := api .s .tokenManager .GetTokens (chainID )
178- logutils .ZapLogger ().Debug ("result from token store" , zap .Int ("len" , len (rst )))
179- return rst , err
180- }
181-
182- // @deprecated
183- func (api * API ) GetCustomTokens (ctx context.Context ) ([]* tokenTypes.Token , error ) {
184- logutils .ZapLogger ().Debug ("call to get custom tokens" )
185- rst , err := api .s .tokenManager .GetCustoms (true )
186- logutils .ZapLogger ().Debug ("result from database for custom tokens" , zap .Int ("len" , len (rst )))
187- return rst , err
180+ func (api * API ) GetTokensAvailableForBridgeOnChain (ctx context.Context , chainID uint64 ) []* tokentypes.Token {
181+ logutils .ZapLogger ().Debug ("call to get tokens available for bridge on chain" )
182+ return api .s .router .GetTokensAvailableForBridgeOnChain (chainID )
188183}
189184
190- func (api * API ) DiscoverToken (ctx context.Context , chainID uint64 , address common.Address ) (* tokenTypes .Token , error ) {
185+ func (api * API ) DiscoverToken (ctx context.Context , chainID uint64 , address common.Address ) (* tokentypes .Token , error ) {
191186 logutils .ZapLogger ().Debug ("call to get discover token" )
192187 token , err := api .s .tokenManager .DiscoverToken (ctx , chainID , address )
193188 return token , err
194189}
195190
196- func (api * API ) AddCustomToken (ctx context.Context , token tokenTypes .Token ) error {
191+ func (api * API ) AddCustomToken (ctx context.Context , token tokentypes .Token ) error {
197192 logutils .ZapLogger ().Debug ("call to create or edit custom token" )
198193 if token .ChainID == 0 {
199194 token .ChainID = api .s .rpcClient .UpstreamChainID
@@ -377,31 +372,31 @@ func (api *API) GetFlatEthereumChains(ctx context.Context) ([]*params.Network, e
377372}
378373
379374// @deprecated
380- func (api * API ) FetchPrices (ctx context.Context , symbols []string , currencies []string ) (map [string ]map [string ]float64 , error ) {
375+ func (api * API ) FetchPrices (ctx context.Context , tokens []* tokentypes. Token , currencies []string ) (map [string ]map [string ]float64 , error ) {
381376 logutils .ZapLogger ().Debug ("call to FetchPrices" )
382- return api .s .marketManager .FetchPrices (symbols , currencies )
377+ return api .s .marketManager .FetchPrices (tokens , currencies )
383378}
384379
385380// @deprecated
386- func (api * API ) FetchMarketValues (ctx context.Context , symbols []string , currency string ) (map [string ]thirdparty.TokenMarketValues , error ) {
381+ func (api * API ) FetchMarketValues (ctx context.Context , tokens []* tokentypes. Token , currency string ) (map [string ]thirdparty.TokenMarketValues , error ) {
387382 logutils .ZapLogger ().Debug ("call to FetchMarketValues" )
388- return api .s .marketManager .FetchTokenMarketValues (symbols , currency )
383+ return api .s .marketManager .FetchTokenMarketValues (tokens , currency )
389384}
390385
391- func (api * API ) GetHourlyMarketValues (ctx context.Context , symbol string , currency string , limit int , aggregate int ) ([]thirdparty.HistoricalPrice , error ) {
386+ func (api * API ) GetHourlyMarketValues (ctx context.Context , token * tokentypes. Token , currency string , limit int , aggregate int ) ([]thirdparty.HistoricalPrice , error ) {
392387 logutils .ZapLogger ().Debug ("call to GetHourlyMarketValues" )
393- return api .s .marketManager .FetchHistoricalHourlyPrices (symbol , currency , limit , aggregate )
388+ return api .s .marketManager .FetchHistoricalHourlyPrices (token , currency , limit , aggregate )
394389}
395390
396- func (api * API ) GetDailyMarketValues (ctx context.Context , symbol string , currency string , limit int , allData bool , aggregate int ) ([]thirdparty.HistoricalPrice , error ) {
391+ func (api * API ) GetDailyMarketValues (ctx context.Context , token * tokentypes. Token , currency string , limit int , allData bool , aggregate int ) ([]thirdparty.HistoricalPrice , error ) {
397392 logutils .ZapLogger ().Debug ("call to GetDailyMarketValues" )
398- return api .s .marketManager .FetchHistoricalDailyPrices (symbol , currency , limit , allData , aggregate )
393+ return api .s .marketManager .FetchHistoricalDailyPrices (token , currency , limit , allData , aggregate )
399394}
400395
401396// @deprecated
402- func (api * API ) FetchTokenDetails (ctx context.Context , symbols []string ) (map [string ]thirdparty.TokenDetails , error ) {
397+ func (api * API ) FetchTokenDetails (ctx context.Context , tokens []* tokentypes. Token ) (map [string ]thirdparty.TokenDetails , error ) {
403398 logutils .ZapLogger ().Debug ("call to FetchTokenDetails" )
404- return api .s .marketManager .FetchTokenDetails (symbols )
399+ return api .s .marketManager .FetchTokenDetails (tokens )
405400}
406401
407402// @deprecated we should remove it once clients fully switched to wallet router, `GetSuggestedRoutesAsync` should be used instead
@@ -697,20 +692,6 @@ func (api *API) BuildTransactionsFromRoute(ctx context.Context, uuid string) {
697692 api .s .routeExecutionManager .BuildTransactionsFromRoute (ctx , uuid )
698693}
699694
700- // Deprecated: `ProceedWithTransactionsSignatures` is the endpoint used in the old way of sending transactions and should not be used anymore.
701- //
702- // The flow that should be used instead:
703- // - call `BuildTransactionsFromRoute`
704- // - wait for the `wallet.router.sign-transactions` signal
705- // - sign received hashes using `SignMessage` call or sign on keycard
706- // - call `SendRouterTransactionsWithSignatures` with the signatures of signed hashes from the previous step
707- //
708- // TODO: remove this struct once mobile switches to the new approach
709- func (api * API ) ProceedWithTransactionsSignatures (ctx context.Context , signatures map [string ]requests.SignatureDetails ) (* transfer.MultiTransactionCommandResult , error ) {
710- logutils .ZapLogger ().Debug ("[WalletAPI:: ProceedWithTransactionsSignatures] sign with signatures and send multi transaction" )
711- return api .s .transactionManager .ProceedWithTransactionsSignatures (ctx , signatures )
712- }
713-
714695func (api * API ) SendRouterTransactionsWithSignatures (ctx context.Context , sendInputParams * requests.RouterSendTransactionsParams ) {
715696 logutils .ZapLogger ().Debug ("[WalletAPI:: SendRouterTransactionsWithSignatures] sign with signatures and send" )
716697 api .s .routeExecutionManager .SendRouterTransactionsWithSignatures (ctx , sendInputParams )
0 commit comments