Skip to content

Commit

Permalink
fix: convert denom even if price fetcher failed (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Mar 30, 2023
1 parent fae7876 commit 8836989
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/data_fetcher/data_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ func (f *DataFetcher) PopulateAmount(amount *amount.Amount) {
return
}

amount.ConvertDenom(denomInfo.DisplayDenom, denomInfo.DenomCoefficient)
price, fetched := f.GetPrice(denomInfo)
if fetched == false {
return
}

amount.AddUSDPrice(denomInfo.DisplayDenom, denomInfo.DenomCoefficient, price)
amount.AddUSDPrice(price)
}

func (f *DataFetcher) GetValidator(address string) (*responses.Validator, bool) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/types/amount/amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ func AmountFromString(amount string, denom string) *Amount {
}
}

func (a *Amount) AddUSDPrice(displayDenom string, denomCoefficient int64, usdPrice float64) {
func (a *Amount) ConvertDenom(displayDenom string, denomCoefficient int64) {
denomCoefficientBigFloat := new(big.Float).SetInt64(denomCoefficient)
a.Value = new(big.Float).Quo(a.Value, denomCoefficientBigFloat)
a.Denom = displayDenom
}

func (a *Amount) AddUSDPrice(usdPrice float64) {
tokenPriceBigFloat := new(big.Float).Set(a.Value)
amountValueBigFloat := new(big.Float).SetFloat64(usdPrice)
a.PriceUSD = new(big.Float).Mul(tokenPriceBigFloat, amountValueBigFloat)
Expand Down

0 comments on commit 8836989

Please sign in to comment.