Commit 02765635 authored by vicotor's avatar vicotor

update token info

parent d7eccbcb
......@@ -78,6 +78,7 @@ func (cr *ChainRepo) parseChainDataToMap(data []byte) (map[int]types.ChainInfo,
Name: cd.Name,
Explorer: "",
Rpc: "",
NativeCurrency: cd.NativeCurrency,
}
if len(cd.Rpc) > 0 {
ci.Rpc = cd.Rpc[0].Url
......
......@@ -284,7 +284,7 @@ func (d *Dao) GetBridgeTokenBalance(chainId int64, user string) (balances apiMod
if token.ChainId != chainId {
continue
}
tokenInfo, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainClient, token.Token, user)
tokenInfo, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainClient, chainId, token.Token, user)
if err != nil {
log.WithFields(log.Fields{
"chain_id": token.ChainId,
......@@ -330,7 +330,7 @@ func (d *Dao) GetTokenBalance(chainId int64, user string, tokens []string) (bala
var innerBalance = make([]tokenBalance, 0)
for _, token := range tokens {
tokenInfo, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainClient, token, user)
tokenInfo, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainClient, chainId, token, user)
if err != nil {
log.WithFields(log.Fields{
"chain_id": chainId,
......@@ -384,7 +384,7 @@ func (d *Dao) QuoteBridge(param apiModel.QuoteBridgeParam) (quote apiModel.Quote
}).Error("get out config failed")
return quote, fmt.Errorf("internal error")
}
_, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainInfo.cli, param.FromToken, param.User)
_, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainInfo.cli, chainInfo.conf.ChainId, param.FromToken, param.User)
if err != nil {
log.WithFields(log.Fields{
"chain_id": param.FromChainId,
......@@ -586,7 +586,7 @@ func (d *Dao) GetSwapTokenBalance(chainId int64, user string) (balances apiModel
innerBalance := make([]tokenBalance, 0)
for _, token := range chainSwapConfig.SupportTokens {
tokenInfo, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainInfo.cli, token.TokenContract, user)
tokenInfo, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(chainInfo.cli, chainId, token.TokenContract, user)
if err != nil {
log.WithFields(log.Fields{
"chain_id": chainId,
......@@ -631,7 +631,7 @@ func (d *Dao) QuoteSwap(param apiModel.QuoteSwapParam) (quote apiModel.QuoteResu
return quote, fmt.Errorf("not found chain for chain id")
}
_, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(fromChainInfo.cli, param.Path.SwapFromToken, param.User)
_, balance, err := d.tokenRepo.RetriveTokenInfoAndBalance(fromChainInfo.cli, fromChainInfo.conf.ChainId, param.Path.SwapFromToken, param.User)
if err != nil {
log.WithFields(log.Fields{
"chain_id": param.FromChainId,
......
......@@ -52,10 +52,11 @@ func (tr *TokenRepo) RetriveTokenInfo(chainId int64, address string) (TokenInfo,
return info, nil
}
if strings.Compare(strings.ToLower(address), strings.ToLower(constant.CoinAddress)) == 0 {
cinfo, _ := tr.chainRepo.Get(chainId)
info := TokenInfo{
Name: "MOVA",
Symbol: "MOVA",
Decimals: 18,
Name: cinfo.NativeCurrency.Name,
Symbol: cinfo.NativeCurrency.Symbol,
Decimals: int64(cinfo.NativeCurrency.Decimals),
Address: address,
}
tr.SetTokenInfo(address, info)
......@@ -101,15 +102,16 @@ func (tr *TokenRepo) RetriveTokenInfo(chainId int64, address string) (TokenInfo,
return info, nil
}
func (tr *TokenRepo) RetriveTokenInfoAndBalance(client *ethclient.Client, address string, user string) (TokenInfo, *big.Int, error) {
func (tr *TokenRepo) RetriveTokenInfoAndBalance(client *ethclient.Client, chainId int64, address string, user string) (TokenInfo, *big.Int, error) {
info := TokenInfo{}
balance := big.NewInt(0)
cinfo, _ := tr.chainRepo.Get(chainId)
if strings.Compare(strings.ToLower(address), strings.ToLower(constant.CoinAddress)) == 0 {
info = TokenInfo{
Name: "MOVA",
Symbol: "MOVA",
Decimals: 18,
Name: cinfo.NativeCurrency.Name,
Symbol: cinfo.NativeCurrency.Symbol,
Decimals: int64(cinfo.NativeCurrency.Decimals),
Address: address,
}
tr.SetTokenInfo(address, info)
......
......@@ -6,4 +6,9 @@ type ChainInfo struct {
Name string `json:"name,omitempty"`
Rpc string `json:"rpc,omitempty"`
Explorer string `json:"explorer,omitempty"`
NativeCurrency struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals int `json:"decimals"`
} `json:"nativeCurrency"`
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment