Skip to content

Commit

Permalink
chore: get and return evmos price change in balance call
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrsirdev committed Oct 18, 2023
1 parent 05393cc commit 2967885
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 8 additions & 3 deletions api/handler/v1/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ type ERC20Entry struct {
URL string `json:"url"`
HandlingAction string `json:"handlingAction"`
} `json:"handledByExternalUI"`
ERC20Address string `json:"erc20Address"`
PngSrc string `json:"pngSrc"`
Prefix string `json:"prefix"`
ERC20Address string `json:"erc20Address"`
PngSrc string `json:"pngSrc"`
Prefix string `json:"prefix"`
Price24HChange string `json:"price24HChange"`
}

type ModuleBalanceContainer struct {
Expand Down Expand Up @@ -100,6 +101,7 @@ func ERC20ModuleEmptyBalance(ctx *fasthttp.RequestCtx) {
networkConfig := networkConfigs[configIdx]
mainnetConfig := resources.GetMainnetConfig(networkConfig)
coingeckoPrice := GetCoingeckoPrice(v.CoingeckoID)
coin24hChnage := GetCoingecko24HChange(v.CoingeckoID)
container.values[k] = ERC20Entry{
Name: v.Name,
Symbol: v.Symbol,
Expand All @@ -116,6 +118,7 @@ func ERC20ModuleEmptyBalance(ctx *fasthttp.RequestCtx) {
ERC20Address: v.Erc20,
PngSrc: v.PngSrc,
Prefix: v.Prefix,
Price24HChange: coin24hChnage,
}
index++
}
Expand Down Expand Up @@ -195,6 +198,7 @@ func ERC20ModuleBalance(ctx *fasthttp.RequestCtx) {
networkConfig := networkConfigs[configIdx]
mainnetConfig := resources.GetMainnetConfig(networkConfig)
coingeckoPrice := GetCoingeckoPrice(v.CoingeckoID)
coin24hChnage := GetCoingecko24HChange(v.CoingeckoID)

container.values[k] = ERC20Entry{
Name: v.Name,
Expand All @@ -212,6 +216,7 @@ func ERC20ModuleBalance(ctx *fasthttp.RequestCtx) {
ERC20Address: v.Erc20,
PngSrc: v.PngSrc,
Prefix: v.Prefix,
Price24HChange: coin24hChnage,
}
index++
}
Expand Down
9 changes: 9 additions & 0 deletions api/handler/v1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ func GetCoingeckoPrice(coingeckoID string) string {
return price
}

func GetCoingecko24HChange(coingeckoID string) string {
change := "0"
val, err := db.RedisGet24HChange(coingeckoID)
if err == nil {
change = val
}
return change
}

func paramToString(param string, ctx *fasthttp.RequestCtx) string {
return fmt.Sprint(ctx.UserValue(param))
}
Expand Down
5 changes: 5 additions & 0 deletions internal/v1/db/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func RedisGetPrice(asset string, vsCurrency string) (string, error) {
return formatRedisResponse(val, err)
}

func RedisGet24HChange(asset string) (string, error) {
val, err := rdb.Get(ctxRedis, asset+"|24h|change").Result()
return formatRedisResponse(val, err)
}

func RedisSetPrice(asset string, vsCurrency string, price string) {
key := buildKeyPrice(asset, vsCurrency)
err := rdb.Set(ctxRedis, key, price, 0).Err()
Expand Down

0 comments on commit 2967885

Please sign in to comment.