Skip to content

Commit

Permalink
chore: buildValuesResponse function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrsirdev committed Oct 23, 2023
1 parent 67b5a94 commit a96a583
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion api/handler/v1/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func getTotalBalance(balance ERC20Entry) decimal.Dec {
return res
}

func buildValuesResponse(values string) string {
return "{\"values\":" + values + "}"
}

func ERC20ModuleEmptyBalance(ctx *fasthttp.RequestCtx) {
container := ModuleBalanceContainer{
values: map[string]ERC20Entry{},
Expand Down Expand Up @@ -290,7 +294,7 @@ func ERC20TokensByNameInternal(name string) (string, error) {

for _, v := range val {
if strings.Contains(v.URL, name) {
res := "{\"values\":" + v.Content + "}"
res := buildValuesResponse(v.Content)
db.RedisSetERC20TokensByName(name, res)
return res, nil
}
Expand Down
2 changes: 1 addition & 1 deletion api/handler/v1/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NetworkConfigByNameInternal(name string) (string, error) {

for _, v := range val {
if strings.Contains(v.URL, name) {
res := "{\"values\":" + v.Content + "}"
res := buildValuesResponse(v.Content)
db.RedisSetNetworkConfigByName(name, res)
return res, nil
}
Expand Down
6 changes: 4 additions & 2 deletions api/handler/v1/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ type ValidatorAPIResponse struct {

func AllValidators(ctx *fasthttp.RequestCtx) {
if validators, err := db.RedisGetAllValidators("EVMOS"); err == nil {
sendResponse("{\"values\":"+validators+"}", err, ctx)
res := buildValuesResponse(validators)
sendResponse(res, err, ctx)
return
}

Expand Down Expand Up @@ -109,5 +110,6 @@ func AllValidators(ctx *fasthttp.RequestCtx) {
validatorsJSON := string(validatorsByte)

db.RedisSetAllValidators("EVMOS", validatorsJSON)
sendResponse("{\"values\":"+validatorsJSON+"}", err, ctx)
validatorsRes := buildValuesResponse(validatorsJSON)
sendResponse(validatorsRes, err, ctx)
}

0 comments on commit a96a583

Please sign in to comment.