feat: token list updated at global
This commit is contained in:
parent
812910f087
commit
9c131edfaa
|
@ -179,10 +179,10 @@ func (api *API) GetBalanceHistoryRange(ctx context.Context, chainIDs []uint64, a
|
|||
return api.s.history.GetBalanceHistory(ctx, chainIDs, addresses, tokenSymbol, currencySymbol, fromTimestamp)
|
||||
}
|
||||
|
||||
func (api *API) GetTokenList(ctx context.Context) ([]*token.List, error) {
|
||||
func (api *API) GetTokenList(ctx context.Context) (*token.ListWrapper, error) {
|
||||
log.Debug("call to get token list")
|
||||
rst := api.s.tokenManager.GetList()
|
||||
log.Debug("result from token list", "len", len(rst))
|
||||
log.Debug("result from token list", "len", len(rst.Data))
|
||||
return rst, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -77,11 +77,15 @@ func (t *Token) IsNative() bool {
|
|||
}
|
||||
|
||||
type List struct {
|
||||
Name string `json:"name"`
|
||||
Tokens []*Token `json:"tokens"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
Source string `json:"source"`
|
||||
Version string `json:"version"`
|
||||
Name string `json:"name"`
|
||||
Tokens []*Token `json:"tokens"`
|
||||
Source string `json:"source"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type ListWrapper struct {
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
Data []*List `json:"data"`
|
||||
}
|
||||
|
||||
type addressTokenMap = map[common.Address]*Token
|
||||
|
@ -465,40 +469,42 @@ func (tm *Manager) GetTokensByChainIDs(chainIDs []uint64) ([]*Token, error) {
|
|||
return res, nil
|
||||
}
|
||||
|
||||
func (tm *Manager) GetList() []*List {
|
||||
res := make([]*List, 0)
|
||||
func (tm *Manager) GetList() *ListWrapper {
|
||||
data := make([]*List, 0)
|
||||
nativeTokens, err := tm.getNativeTokens()
|
||||
if err == nil {
|
||||
res = append(res, &List{
|
||||
Name: "native",
|
||||
Tokens: nativeTokens,
|
||||
UpdatedAt: time.Now().Unix(),
|
||||
Source: "native",
|
||||
Version: "1.0.0",
|
||||
data = append(data, &List{
|
||||
Name: "native",
|
||||
Tokens: nativeTokens,
|
||||
Source: "native",
|
||||
Version: "1.0.0",
|
||||
})
|
||||
}
|
||||
|
||||
customTokens, err := tm.GetCustoms(true)
|
||||
if err == nil && len(customTokens) > 0 {
|
||||
res = append(res, &List{
|
||||
Name: "custom",
|
||||
Tokens: customTokens,
|
||||
UpdatedAt: time.Now().Unix(),
|
||||
Source: "custom",
|
||||
Version: "1.0.0",
|
||||
data = append(data, &List{
|
||||
Name: "custom",
|
||||
Tokens: customTokens,
|
||||
Source: "custom",
|
||||
Version: "1.0.0",
|
||||
})
|
||||
}
|
||||
|
||||
updatedAt := time.Now().Unix()
|
||||
for _, store := range tm.stores {
|
||||
res = append(res, &List{
|
||||
Name: store.GetName(),
|
||||
Tokens: store.GetTokens(),
|
||||
UpdatedAt: store.GetUpdatedAt(),
|
||||
Source: store.GetSource(),
|
||||
Version: store.GetVersion(),
|
||||
updatedAt = store.GetUpdatedAt()
|
||||
data = append(data, &List{
|
||||
Name: store.GetName(),
|
||||
Tokens: store.GetTokens(),
|
||||
Source: store.GetSource(),
|
||||
Version: store.GetVersion(),
|
||||
})
|
||||
}
|
||||
return res
|
||||
return &ListWrapper{
|
||||
Data: data,
|
||||
UpdatedAt: updatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func (tm *Manager) DiscoverToken(ctx context.Context, chainID uint64, address common.Address) (*Token, error) {
|
||||
|
|
Loading…
Reference in New Issue