feat(Wallet): add function to get erc20 token by contract address

Part of #10251
This commit is contained in:
Dario Gabriel Lipicar 2023-06-02 17:07:42 -03:00 committed by dlipicar
parent d2462b01ce
commit 7557f0c799
1 changed files with 25 additions and 9 deletions

View File

@ -158,20 +158,26 @@ func (tm *Manager) fetchTokens() {
tm.tokenMap = toTokenMap(tm.tokenList)
}
func (tm *Manager) getFullTokenList(chainID uint64) []*Token {
tokens, err := tm.GetTokens(chainID)
if err != nil {
return nil
}
customTokens, err := tm.GetCustomsByChainID(chainID)
if err != nil {
return nil
}
return append(tokens, customTokens...)
}
func (tm *Manager) FindToken(network *params.Network, tokenSymbol string) *Token {
if tokenSymbol == network.NativeCurrencySymbol {
return tm.ToToken(network)
}
tokens, err := tm.GetTokens(network.ChainID)
if err != nil {
return nil
}
customTokens, err := tm.GetCustomsByChainID(network.ChainID)
if err != nil {
return nil
}
allTokens := append(tokens, customTokens...)
allTokens := tm.getFullTokenList(network.ChainID)
for _, token := range allTokens {
if token.Symbol == tokenSymbol {
return token
@ -180,6 +186,16 @@ func (tm *Manager) FindToken(network *params.Network, tokenSymbol string) *Token
return nil
}
func (tm *Manager) FindTokenByAddress(chainID uint64, address common.Address) *Token {
allTokens := tm.getFullTokenList(chainID)
for _, token := range allTokens {
if token.Address == address {
return token
}
}
return nil
}
func (tm *Manager) FindSNT(chainID uint64) *Token {
tokens, err := tm.GetTokens(chainID)
if err != nil {