feat: filter token by valid chain ID

This commit is contained in:
Anthony Laibe 2023-03-28 15:15:34 +02:00 committed by Anthony Laibe
parent c9a8ab13c2
commit 2baa8e8ead
1 changed files with 15 additions and 1 deletions

View File

@ -132,14 +132,28 @@ func (tm *Manager) fetchTokens() {
tm.tokenList = nil tm.tokenList = nil
tm.tokenMap = nil tm.tokenMap = nil
networks, err := tm.networkManager.Get(false)
if err != nil {
return
}
for _, store := range tm.stores { for _, store := range tm.stores {
tokens, err := store.GetTokens() tokens, err := store.GetTokens()
if err != nil { if err != nil {
log.Error("can't fetch tokens from store: %s", err) log.Error("can't fetch tokens from store: %s", err)
continue continue
} }
validTokens := make([]*Token, 0)
for _, token := range tokens {
for _, network := range networks {
if network.ChainID == token.ChainID {
validTokens = append(validTokens, token)
break
}
}
}
tm.tokenList = mergeTokenLists([][]*Token{tm.tokenList, tokens}) tm.tokenList = mergeTokenLists([][]*Token{tm.tokenList, validTokens})
} }
tm.tokenMap = toTokenMap(tm.tokenList) tm.tokenMap = toTokenMap(tm.tokenList)